Repository navigation
Conversation
resolveBearerActor and the MCP tests' contextForOrganizer each turned an organizer's session into the tool context by hand, and the route copied the fields over once more. They now share bearerOrganizer in the bearer seam, ToolContext is its type plus db, and the route spreads it, so a field added to the bearer path can't be missed by the tests and evals. Fixes #1141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SSbFFg2F4VY28wUau4
Tophat: passedSee it: https://claude.ai/artifact/7Wf3Ne1VPv5k821mqtju7T
Worth a look: the route now spreads the whole resolution, minus Not checked on the base: the viewer and deleted-organizer cases. I ran them on the head only, and their wording comes from code this PR doesn't touch. Ran 09a688e against a820439 locally, MCP over HTTP with a token from the real OAuth flow, made-up data. https://claude.ai/code/session_016YZ9STFWdWM98i7mGfTd2w Generated by Claude Code |
richshaw
left a comment
There was a problem hiding this comment.
Review: passed (round 1)
bearerOrganizer is now the only place a session becomes a tool context. resolveBearerActor, contextForOrganizer and the route all go through it, and they build the same fields as before, including the 401 for an organizer who is gone. Nothing in src still uses ToolWorkspace or bearerWorkspaces. Both "Done when" items are met, and so is the issue's outline.
Blocking (0)
Optional (3):
route.ts:109: the context now takes everything exceptokandauthInfo, so any field added later to the resolution reaches every tool. The tophat flagged this too. Returning{ ok, organizer, authInfo }would make adding a field a deliberate choice.bearer.ts:24: the file's seam comment now sits on the exportedBearerOrganizer, so it shows as that type's hover doc. Moving it ontoresolveBearerActorwould fix that.context.ts:1: the type-onlyBearerOrganizerimport is what the issue planned. CLAUDE.md's "only auth import" line could name it.
Earlier threads: none
Checks: CI is green on 09a688e (lint-type-test, e2e, CodeQL). The tophat passed on this SHA. I ran code-review at high effort.
This waits for you because it touches src/auth/bearer.ts and the MCP route, which are high-risk. It changes no behaviour. Card: https://claude.ai/artifact/7Wf3Ne1VPv5k821mqtju7T
https://claude.ai/code/session_016YZ9SVJHryH4EUPxis53cd
Generated by Claude Code
Fixes #1141.
Session: https://claude.ai/code/session_016YZ9SSbFFg2F4VY28wUau4
The problem
Turning a signed-in organizer into the context an MCP tool runs with was written out three times.
resolveBearerActorbuilt it in production,contextForOrganizer(which the MCP DB tests and the follow-up evals use) rebuilt it field by field, and the route copied the six fields intoToolContextone at a time.BearerWorkspaceandToolWorkspacewere the same type. A field added to the bearer path but missed in the test copy would leave the MCP tests running on a context production no longer builds.The fix
src/auth/bearer.ts: a new exportedBearerOrganizertype (actor, scopes, clientId, defaultWorkspaceId, workspaces, locale, with their doc comments) and a purebearerOrganizer(session, clientId, scopes). It callstoActor, narrows the kind, copies the actor withvia(the comment about not mutating the React-cached actor moved with it), and maps the memberships. It replacesbearerWorkspaces.BearerResolution's ok branch is nowBearerOrganizer & { ok: true; authInfo }, andresolveBearerActorpassesparseScopeString(...)as before, so the builder takes scopes already parsed.src/mcp/context.ts:ToolContextisBearerOrganizer & { db }.ToolWorkspaceis gone. The only new import is a type-onlyBearerOrganizerfrom the seam module, and tool handlers still import nothing from@/auth.src/mcp/testing/context.ts: loads the session, callsbearerOrganizer, and throws if it gives null.okandauthInfoout of the resolution and spreads the rest into the context. I leftauthInfoout of the context on purpose: it carries the raw token, and the context is attached to it, not the other way round.No behaviour changes, so there's no CHANGELOG entry. It touches
src/auth/and the MCP route, so it waits for the owner. #1135 (from a fork) changes key-error logging inbearer.ts. The lines don't overlap, but whichever lands second has a small merge.Tests
No new tests. The existing ones cover both paths:
route.test.tsmocks the resolution and checks the context the tools get, andtools.db.test.tsplus the OAuth flow DB tests run throughcontextForOrganizerandresolveBearerActor.grep -rn "ToolWorkspace\|bearerWorkspaces" srcfinds nothing.pnpm lint && pnpm format:check && pnpm typecheck && pnpm knip && pnpm testpass (3894 tests).pnpm test:dbpasses (916 tests).Generated by Claude Code