Skip to content

Port mentra-console MCP incident tools to the Cloud V2 admin reports API - #3388

Open
PhilippeFerreiraDeSousa wants to merge 5 commits into
devfrom
claude/bold-agnesi-ea30ec
Open

Port mentra-console MCP incident tools to the Cloud V2 admin reports API#3388
PhilippeFerreiraDeSousa wants to merge 5 commits into
devfrom
claude/bold-agnesi-ea30ec

Conversation

@PhilippeFerreiraDeSousa

@PhilippeFerreiraDeSousa PhilippeFerreiraDeSousa commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Scope

The mentra-console MCP server (cloud/packages/console-mcp) still targeted the legacy V1 incidents API (GET /api/agent/incidents[/:id[/logs]], X-Agent-Key). The cloud/ tree is frozen and V1 incidents are superseded by Cloud V2 reports, so this recreates the server at cloud-v2/packages/console-mcp on the admin reports API introduced by #3378:

V1 tool V2 tool Backing endpoint
incident_list report_list GET /api/admin/reports?kind=&status=&limit=&before=
incident_get report_get GET /api/admin/reports/:reportId
incident_get_logs report_get_logs detail + GET /api/admin/reports/:reportId/artifacts/:artifactId per logs artifact
report_get_artifact artifact bytes: screenshots inline as MCP images, JSON/text as text, binaries by pointer to scripts/fetch-incident-logs.sh

Carried over from V1: bounded log output (default 200 lines) with level/grep/limit filters, short-id prefix resolution (rep_... ULIDs, scanned against the ~600 most recent reports via the before cursor), mentra://reports resources, a debug-report prompt, the run-mcp.sh Cursor launcher, and the smoke test. New behavior for V2: report_get_logs merges every logs artifact ({entries: [{timestamp, level, message, source?}]} bundles from phone/glasses) oldest-first tagged with the uploading device, and an unreadable bundle degrades to a warning instead of failing the call.

Auth and host selection mirror the ported fetch-incident-logs.sh: Authorization: Bearer $MENTRA_ADMIN_TOKEN (org msk_ key whose synthetic email api-key@{keyId}.local is allowlisted via CLOUD_CORE_ADMIN_EMAILS, or a WorkOS admin access token), host from MENTRA_CORE_URL or MENTRA_ENV=prod|staging|dev (default prod). 401/403/404 map to actionable hints (env-pinned keys, allowlist, API not deployed).

The legacy package is left untouched — its V1 app/org/admin tools keep working until the cloud/ tree is removed. Root AGENTS.md now points V2 report triage (rep_... ids) at the new package.

Notes for reviewers

  • Deployment dependency: the report tools need a core that serves /api/admin/reports, i.e. Admin console: report triage (list, detail, screenshots, logs) #3378 merged and deployed. Until then they return the mapped 404 hint. No compile-time dependency on core.
  • There is an in-flight port of scripts/fetch-incident-logs.sh to this same API (same env conventions). If it lands first, its AGENTS.md note about the MCP server being unported should be dropped when this merges; the AGENTS.md touch here is kept minimal to make that conflict trivial.
  • Four bun.lock files change: the repo root, mobile, and sdk workspaces all glob cloud-v2/packages/* in addition to cloud-v2's own workspace, so each lockfile registers the new package and its @modelcontextprotocol/sdk dep tree.
  • The package depends on zod ^4.4.3: since the admin console website landed, cloud-v2 links @modelcontextprotocol/sdk against zod 4, and mixing a zod-3 identity with it through the SDK's zod-compat types fails typecheck (TS2589). Every schema helper used is identical in the v4 classic API.
  • Possible follow-up: V2 admin submission review tools (/api/admin/submissions/...) if wanted; kept out of scope here.

Test evidence

  • bun test (package): 28 pass across config / log parsing-merging-filtering / id resolution
  • bunx tsc --noEmit and root tsc -b packages/console-mcp (new project reference) pass
  • bun install at repo root and cloud-v2/ regenerate both lockfiles cleanly (CI lockfile check runs frozen install)
  • End-to-end: drove the built server over real stdio JSON-RPC against a mock core implementing the three endpoints + /api/admin/me — 13/13 checks pass: tool registration, console_auth_status verify, compact list rows, short-prefix resolve, includeContext:false, phone+glasses bundle merge ordering with source tags, level/grep/source/json filters, inline PNG image content, JSON artifact as text, 404 mapping, prefix-miss messaging
  • run-mcp.sh manual stdio check from the README returns the expected console_auth_status result

Note

Low Risk
Developer-tooling only (MCP client + docs/lockfiles); no runtime changes to core, mobile, or auth beyond calling existing admin APIs with configured tokens.

Overview
Adds @mentra/console-mcp under cloud-v2/packages/console-mcp — a stdio MCP server that replaces the frozen V1 incident tools with Cloud V2 admin reports (/api/admin/reports), authenticated via MENTRA_ADMIN_TOKEN and MENTRA_CORE_URL / MENTRA_ENV.

Agents get report_list, report_get, report_get_logs (merged phone/glasses log bundles with filters), report_get_artifact (inline images/text or curl hints), plus console_auth_status, mentra://reports resources, and a debug-report prompt. Short rep_... prefix resolution, run-mcp.sh for Cursor, unit tests, and a live smoke script are included.

AGENTS.md now documents V1 incident fetch via fetch-incident-logs.sh + MENTRA_AGENT_API_KEY, and V2 rep_... triage via this MCP package. Root and cloud-v2 bun.lock files and cloud-v2/tsconfig.json register the new workspace package and its @modelcontextprotocol/sdk dependency tree. The legacy cloud/packages/console-mcp package is unchanged.

Reviewed by Cursor Bugbot for commit a982f3b. Bugbot is set up for automated code reviews on this repo. Configure here.

The legacy server at cloud/packages/console-mcp reads V1 incidents via
GET /api/agent/incidents with X-Agent-Key, but the cloud/ tree is frozen
and V1 incidents are superseded by Cloud V2 reports. Recreate the MCP
server at cloud-v2/packages/console-mcp on the admin reports API:

- incident_list / incident_get / incident_get_logs become report_list /
  report_get / report_get_logs against GET /api/admin/reports[/:id],
  plus report_get_artifact for raw payloads (screenshots inline as MCP
  image content, JSON/text inline as text, binaries by pointer to
  scripts/fetch-incident-logs.sh)
- report_get_logs downloads every logs artifact ({entries: [...]}
  bundles uploaded by phone/glasses), merges them oldest-first tagged
  with the artifact source, and keeps the V1 level/grep/limit filters;
  unreadable bundles degrade to a warning instead of failing the call
- auth mirrors the ported fetch-incident-logs.sh: Authorization: Bearer
  MENTRA_ADMIN_TOKEN (org msk_ key allowlisted via
  CLOUD_CORE_ADMIN_EMAILS, or a WorkOS admin access token), host from
  MENTRA_CORE_URL or MENTRA_ENV=prod|staging|dev (default prod)
- short id prefixes resolve against the most recent 600 reports using
  the before cursor; 401/403/404 map to actionable hints
- mentra://reports resources, debug-report prompt, run-mcp.sh launcher,
  smoke test, and bun unit tests ported to the new shapes

The legacy package is left untouched (its V1 app/org/admin tools die
with the cloud/ tree); AGENTS.md now points V2 report triage at the new
package.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

📋 PR Review Helper

📱 Mobile App Build

Ready to test! (commit a982f3b)

📥 Download APK

🕶️ ASG Client Build

Waiting for build...


🔀 Test Locally

gh pr checkout 3388

Comment thread cloud-v2/packages/console-mcp/src/tools/reports.ts Outdated
Comment thread cloud-v2/packages/console-mcp/src/utils/id-resolution.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23b720ed2a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cloud-v2/packages/console-mcp/src/tools/reports.ts Outdated
PhilippeFerreiraDeSousa added 3 commits July 9, 2026 19:26
… the MCP SDK

The mobile and sdk bun workspaces both glob ../cloud-v2/packages/*, so the
new console-mcp package is a member of four workspaces, not two. CI's
mobile frozen-lockfile check failed on the PR merge ref because
mobile/bun.lock (and next in line, sdk/bun.lock) never learned about the
package; regenerate both.

Since the admin console website landed on dev, cloud-v2's isolated
install links @modelcontextprotocol/sdk against zod@4 while this package
pinned zod@3, and typechecking the two zod identities through the SDK's
zod-compat layer explodes (TS2589). Depend on zod ^4.4.3 so the package
and the SDK share one zod everywhere; every schema helper used here is
unchanged in the v4 classic API.

Also read normalized {message} feedback for compact list summaries and
mark the bin entry executable.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 11, 2026

Copy link
Copy Markdown

Deploying mentra-live-ota-site with  Cloudflare Pages  Cloudflare Pages

Latest commit: deaf666
Status: ✅  Deploy successful!
Preview URL: https://4536d6e3.mentra-live-ota-site.pages.dev
Branch Preview URL: https://claude-bold-agnesi-ea30ec.mentra-live-ota-site.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying dev-augmentos-console with  Cloudflare Pages  Cloudflare Pages

Latest commit: deaf666
Status: ✅  Deploy successful!
Preview URL: https://0697b161.dev-augmentos-console.pages.dev
Branch Preview URL: https://claude-bold-agnesi-ea30ec.dev-augmentos-console.pages.dev

View logs

Comment thread cloud-v2/packages/console-mcp/src/utils/id-resolution.ts
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mentra-store-dev with  Cloudflare Pages  Cloudflare Pages

Latest commit: deaf666
Status: ✅  Deploy successful!
Preview URL: https://ebaa532c.augmentos-appstore-2.pages.dev
Branch Preview URL: https://claude-bold-agnesi-ea30ec.augmentos-appstore-2.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying prod-augmentos-account with  Cloudflare Pages  Cloudflare Pages

Latest commit: deaf666
Status: ✅  Deploy successful!
Preview URL: https://92902372.augmentos-e84.pages.dev
Branch Preview URL: https://claude-bold-agnesi-ea30ec.augmentos-e84.pages.dev

View logs

- Canonicalize pasted report ids (lowercase/mixed-case rep_... ULIDs) so
  the exact lookup and prefix scan both match the uppercase stored form
- Replace fetch-incident-logs.sh pointers with a ready-to-run curl
  against the admin artifacts endpoint: the repo script still targets V1
  incidents, so the suggested command would not fetch V2 artifacts
- Document that the before-cursor scan can skip rows sharing the
  boundary millisecond (the list API filters strictly-before; the scan
  is best-effort and the miss path asks for a full id)
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

PR Agent Orchestrator State

{
  "cycle": 2,
  "fixRound": 0,
  "totalReviewerRuns": 2,
  "consecutiveNoNewReviews": 2,
  "openFindings": [],
  "resolvedFindings": [],
  "nitFindings": [],
  "phase": "discovery",
  "status": "in_progress",
  "lastPair": [],
  "stagnationFixRounds": 0,
  "lastOpenCount": 0,
  "fingerprintReopenCounts": {},
  "mutedFingerprints": []
}

@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

🤖 PR Agent Review — cycle 2

✅ No blocking findings · 0 blocking · 0 nits
Reviewers this cycle: none

No model reviews ran this cycle.

Updated automatically by the PR Agent Orchestrator each review cycle. Nits do not block merge.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a982f3b. Configure here.

): Promise<{ report: ReportDetail; assets: ReportAsset[] }> {
const query = canonicalizeReportId(id);
try {
return await client.getReport(query);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty report ID hits list

Medium Severity

Blank or whitespace-only reportId values are canonicalized to an empty string, so getReport requests /api/admin/reports/ and hits the list route instead of a detail lookup. That returns a successful list payload shaped as { reports: [...] }, which resolveReport treats as a detail result and yields report: undefined to callers like report_get / report_get_logs instead of a clear not-found error.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit a982f3b. Configure here.

@@ -0,0 +1,27 @@
{
"name": "@mentra/console-mcp",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling it the @mentra/console-mcp is kinda a misnomer now that we moved the reports from the dev console to their own admin portal, so this mcp mostly handles incident reports, calling it the @mentra/admin-mcp makes more sense, or just @mentra/mcp if we plan to extend it beyond just the admin portal / incident system...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants