Repository navigation
refactor(mcp): single OAuth identity owner + resumable authorization session - #122115
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
…sumable McpOAuthIdentity owns the store-key grammar (operator keys byte-identical, zero migration); provider, coordinator, fetch, transport, CLI, and doctor receive identity instead of re-deriving (serverName, serverUrl) keys. The authorize -> capture -> exchange dance moves from the CLI into the coordinator as a resumable session (start persists the pending verifier/ URL in the store row; complete exchanges the code under the same lease), leaving the CLI loopback as a capture adapter. Production net -7 lines.
5116a0c to
ad417b2
Compare
|
Codex review: found issues before merge. Reviewed August 11, 2026, 11:58 AM ET / 15:58 UTC. ClawSweeper reviewWhat this changesThe PR centralizes MCP OAuth identity and moves authorization start and completion into a resumable SQLite-backed coordinator used by the CLI. Merge readinessKeep open: the refactor breaks completion of an already-started manual OAuth login after upgrade when its legacy pending row has no persisted redirect URL. Priority: P1 Review scores
Verification
How this fits togetherMCP transports request OAuth tokens from shared SQLite state before sending authenticated calls to remote MCP servers. The CLI starts browser authorization, captures the returned code, and submits it to the same OAuth state owner. flowchart LR
Config[MCP server configuration] --> CLI[CLI login]
CLI --> Start[Start authorization]
Start --> State[SQLite OAuth session]
State --> Complete[Complete authorization]
Complete --> Provider[OAuth token provider]
Provider --> Remote[Remote MCP server]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource -5, Tests -11. Total -16 across 22 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Preserve legacy pending sessions by requiring only the stored verifier, then let completion use a stored redirect when present or the existing configured/default redirect resolution; add a seeded pre-refactor-row regression test. Do we have a high-confidence way to reproduce the issue? Yes—source reproduction is high confidence: seed a base-shaped pending row with codeVerifier and lastAuthorizationUrl but no redirectUrl, then run the current completion path with a valid code. Is this the best way to solve the issue? No—the owner boundary is coherent, but the new persisted-session precondition must retain the existing configured/default redirect behavior for upgrade rows. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8f61ec4120b8. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
Follow-up to #122115: startMcpOAuthAuthorization suppressed stored tokens unconditionally, forcing a browser authorization on every mcp login even with a valid session. Suppression is again gated on a recorded authorization-required challenge; start returns a closed authorized|redirect result and the CLI early-returns the already-logged-in outcome. Co-authored-by: Ayaan Zaidi <[email protected]>
…session (openclaw#122115) Prep for per-requester MCP OAuth (openclaw#122034). McpOAuthIdentity owns the store-key grammar (operator keys byte-identical, zero migration); the authorize -> capture -> exchange dance becomes a resumable coordinator session with the CLI loopback as a capture adapter. Production net -7 lines; openclaw#112032 issuer binding preserved. Co-authored-by: Ayaan Zaidi <[email protected]>
Follow-up to openclaw#122115: startMcpOAuthAuthorization suppressed stored tokens unconditionally, forcing a browser authorization on every mcp login even with a valid session. Suppression is again gated on a recorded authorization-required challenge; start returns a closed authorized|redirect result and the CLI early-returns the already-logged-in outcome. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
The MCP OAuth cluster hardwires "whose tokens" to the operator: three modules independently derive the store key from (serverName, serverUrl), the key silently doubles as the refresh-lease key, and the interactive authorize → capture → exchange dance lives as ~125 lines inside a Commander action with its contract proven only against a whole-module mock. Per-requester OAuth (multiplayer tool identity, #122034) cannot be built on that shape without smearing a principal parameter across five signatures and copy-pasting the login dance for a second driver.
Why This Change Was Made
Prep refactor for #122034, behavior-neutral for operators. Part A:
McpOAuthIdentity(src/agents/mcp-oauth-identity.ts) becomes the single owner of the store-key grammar — operator keys are byte-identical to today's, so existing rows keep working with zero migration; provider, coordinator, fetch wrapper, transport, CLI, auth-profile projection, and doctor all receive an identity instead of re-deriving keys (resolveMcpOAuthStoreKeydeleted, zero references remain). Part B: the authorization dance moves into the coordinator as a resumable session —startMcpOAuthAuthorizationpersists the pending verifier/authorize URL in the existing store-row slots and releases the lease;completeMcpOAuthAuthorizationreacquires it and exchanges the code — leaving the CLI loopback as a pure capture adapter and giving the future gateway callback route (multiplayer) a real seam with an executable contract.User Impact
None intended:
openclaw mcp loginflow, manual--codepath, doctor migrations, and #112032's issuer-binding security behavior are preserved (its test scenarios migrated mechanically to the identity interface with assertions semantically unchanged).Evidence
node scripts/run-vitest.mjs src/agents/mcp-oauth src/agents/mcp-transport src/agents/mcp-auth-profile src/cli/mcp-cli src/infra/state-migrations.mcp-oauthgit diff --check, oxfmt, tsgo lanes clean on the patch.