Skip to content

feat: MCP server so agents can read and answer messages for a user - #496

Merged
Makisuo merged 6 commits into
mainfrom
t3/agent-message-mcp
Nov 16, 2026
Merged

Makisuo merged 6 commits into
mainfrom
t3/agent-message-mcp

fix(mcp): a concurrent refresh ends the grant; no length is no size

1ac3225
Select commit
Loading
Failed to load commit list.
Maple Review Bot / Maple / review succeeded Nov 16, 2026 in 1m 49s

Confidence 8/10 · No issues found

🟢 Confidence 8/10 · likely safe to merge. The one behaviour change, ending the grant on a lost refresh claim, is pinned by a two-fibre test; only the Content-Length guard is untested.
no findings · tests partial −1 · risk high −1 · 2/2 new units observable

Since the last review the concurrent-refresh branch now ends the grant instead of deleting only its own tokens, and storedSize errors rather than reporting 0 bytes. Both read correctly. The McpQueryErrors traced to page/registry.ts are not addressed: that file gains only the OAuth page.

  • AgentAccess.refresh ends the grant when a concurrent refresh loses the claim
  • ObjectStorage.storedSize fails instead of returning 0 for a missing Content-Length

Before merge

Production impact

Open errors in the changed files (2)
Issue Service Occurrences File
@maple/mcp/errors/McpQueryError (8 issues) maple-ai 105 apps/web-foldkit/src/page/registry.ts
@maple/mcp/errors/McpQueryError (2 issues) maple-chat 12 apps/web-foldkit/src/page/registry.ts

After this merges, Maple checks whether they stop.

Production traffic of the changed files (last 7 days)
File Calls/day Busiest operations
apps/backend/src/routes/mcp.ts 54k POST /mcp 22k/day, 0.0% err
POST /mcp 22k/day, 0.0% err
POST 2.9k/day, 0.1% err
apps/backend/src/routes/agent-oauth.ts 52k POST /mcp 22k/day, 0.0% err
POST /mcp 22k/day, 0.0% err
POST 2.9k/day, 0.1% err
packages/db/src/tables/agents.ts 45k POST /mcp 22k/day, 0.0% err
POST /mcp 22k/day, 0.0% err
POST /oauth/token 301/day, 0.0% err
packages/domain/src/http/agent-access.ts 45k POST /mcp 22k/day, 0.0% err
POST /mcp 22k/day, 0.0% err
POST /oauth/token 301/day, 0.0% err
Telemetry this change adds and removes (17)
  • ➕ attribute agent.client_id · apps/backend/src/routes/agent-access.http.ts:96
  • ➕ span name AgentOAuth.register · apps/backend/src/routes/agent-oauth.ts:197
  • ➕ span name AgentOAuth.token · apps/backend/src/routes/agent-oauth.ts:261
  • ➕ span name Mcp.tool · apps/backend/src/routes/mcp.ts:1011
  • ➕ attribute mcp.tool · apps/backend/src/routes/mcp.ts:1012
  • ➕ attribute agent.grant_id · apps/backend/src/routes/mcp.ts:1012
  • ➕ span name Mcp.request · apps/backend/src/routes/mcp.ts:1174
  • ➕ span name AgentAccess.exchangeCode · apps/backend/src/services/agent-access.ts:266
  • ➕ span name AgentAccess.refresh · apps/backend/src/services/agent-access.ts:339
  • ➕ span name AgentAccess.authenticate · apps/backend/src/services/agent-access.ts:374
  • ➕ span name ObjectStorage.put · apps/backend/src/services/object-storage.ts:44
  • ➕ span name ObjectStorage.storedSize · apps/backend/src/services/object-storage.ts:70
  • ➕ span name AgentMarks.markWrite · apps/backend/src/worker/objects/channel/agent-marks.ts:48
  • ➕ span name ChannelObject.messagesByIds · apps/backend/src/worker/objects/channel/api-messages.ts:126
  • ➕ span name OrgObject.agentChannels · apps/backend/src/worker/objects/org/agent.ts:36
  • ➕ attribute org.agent_channels · apps/backend/src/worker/objects/org/agent.ts:93
  • ➕ span name UserObject.agentNotifications · apps/backend/src/worker/objects/user/agent.ts:26
Ingest cost of new log lines
  • apps/backend/src/routes/agent-oauth.ts:193: If this logs once per call, about 415 MB/month: the file's operations run 52k times a day.
  • apps/backend/src/routes/agent-oauth.ts:257: If this logs once per call, about 415 MB/month: the file's operations run 52k times a day.
  • apps/backend/src/routes/mcp.ts:1166: If this logs once per call, about 433 MB/month: the file's operations run 54k times a day.
What was checked
  • Lost-claim path ends the grant (agent-access.ts:329), pinned by a two-fibre test asserting the grant is gone (mcp.http.test.ts:371)
  • Refresh claims the token only after issuing, and checks kind, expiry and grant first (agent-access.ts:296)
  • put and create_upload_url both sign If-None-Match: *; test asserts createOnly: true (mcp.http.test.ts:530)
Observability coverage: 2 of 2 changes observable
Change Kind Observable Evidence
AgentAccess.exchangeCode / refresh / authenticate service operations over directory D1 yes Effect.withSpan on each (agent-access.ts:266,339,374); no personal data in the span names or the two grant-id log warnings
ObjectStorage.put / storedSize outbound S3 calls yes Effect.fn("ObjectStorage.put") / "ObjectStorage.storedSize" spans (object-storage.ts:44,70)

1ac3225 · Reply "won't fix" to dismiss a finding, or mention @maple-review-bot to ask about one.