Repository navigation
Description
What happens
Turning a signed-in organizer into the context an MCP tool runs with is written out three times, with two identical types:
- Production:
resolveBearerActorinsrc/auth/bearer.tsloads the session, callstoActor, checks the actor is an organizer, then returnsactor: { ...actor, via: { clientId } },scopes,clientId,defaultWorkspaceId,workspaces: bearerWorkspaces(session)andlocale. - Tests and evals:
contextForOrganizerinsrc/mcp/testing/context.tsrepeats the same steps by hand, field by field. It's whatsrc/mcp/tools.db.test.tsandsrc/mcp/evals/followups.tsrun the tools with. - The route:
src/app/api/mcp/route.tscopies the six fields from the resolution intoToolContextone at a time. - Types:
BearerWorkspace(src/auth/bearer.ts) andToolWorkspace(src/mcp/context.ts) are the same{ id, slug, name, role }.ToolContextrestates the fields ofBearerResolution's ok branch, doc comments included, plusdb.
Today the copies give the same values. But a field added to the bearer path (as locale once was) has to be added in three places, and if the test copy is missed, the MCP DB tests and evals keep passing on a context production no longer builds.
Nobody using OpenSignup notices.
Fix, in outline
- One builder in
src/auth/bearer.ts: export aBearerOrganizertype (actor, scopes, clientId, defaultWorkspaceId, workspaces, locale, with the existing doc comments moved onto it) and a purebearerOrganizer(session, clientId, scopes): BearerOrganizer | nullthat callstoActor, narrows the kind and builds the fields. It absorbsbearerWorkspaces, which nothing else then uses. resolveBearerActorcalls it withparseScopeString(...)and returns{ ok: true, ...organizer, authInfo }.BearerResolution's ok branch becomesBearerOrganizer & { ok: true; authInfo }.src/mcp/context.ts:ToolContextbecomesBearerOrganizer & { db };ToolWorkspacegoes.contextForOrganizer: load the session, callbearerOrganizer, throw if null, return{ db, ...organizer }.- The route: spread the resolution into the context instead of copying fields.
A verify agent made this change in a scratch tree: 4 files, about 23 lines fewer.
Watch for
- The seam rule. CLAUDE.md says
resolveBearerActoris the only auth import under MCP routes and tool handlers. The new builder lives inbearer.ts, the seam module, and the only new import outside it is a type-onlyBearerOrganizerinsrc/mcp/context.ts. Tool handlers still import nothing from@/auth. Keep it that way. - Keep the spread.
toActoris React-cached, so the actor is copied withvia, never mutated; the comment saying so stays with the code. - Scopes. Production filters through
parseScopeString; the test helper passes typed scopes as given. Keep that: the builder takes scopes already parsed. - This touches
src/auth/, so the PR waits for the owner before merging. An open PR changes the key-error logging inbearer.ts; the lines don't overlap, but whichever lands second has a small merge. route.test.tsmocksresolveBearerActor. Its mock still fits the new type; check it does.
Done when
grep -rn "ToolWorkspace\|bearerWorkspaces" srcfinds nothing, andcontextForOrganizerbuilds its context by calling the same functionresolveBearerActordoes.pnpm lint && pnpm format:check && pnpm typecheck && pnpm knip && pnpm testpass, andpnpm test:dbpasses (tools.db.test.tsand the OAuth flow tests use this path).
Found by the pipeline's refactor scout in the MCP server and its auth seam (src/mcp, src/auth/bearer.ts, src/app/api/mcp), at 2c037aa. Checked by an independent verify agent. It quoted every copy, confirmed they give equal values today, found no comment calling the copy deliberate and no open PR fixing it, then made the change in a scratch worktree: typecheck, lint, knip, prettier and pnpm test src/mcp src/auth src/app/api/mcp (250 tests) passed. pnpm test:db couldn't run there (no Postgres). Then it removed the worktree. https://claude.ai/code/session_016YZ9SU4eo5cjeZjMfXY5sy
Activity