Repository navigation
feat(mcp): per-requester OAuth for MCP servers - #122166
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 3:59 PM ET / 19:59 UTC. ClawSweeper reviewWhat this changesAdds configurable per-requester OAuth for HTTP MCP servers, with requester-isolated credential storage, a Gateway callback, and sender-facing sign-in actions. Merge readinessKeep open: current main still has operator-only MCP OAuth, so this feature remains necessary. The protected maintainer PR needs a current-head security and behavior review because its exact head was unavailable locally and the posted E2E names an earlier commit. Priority: P2 Review scores
Verification
How this fits togetherConfigured MCP servers become agent tools through session runtime materialization. This change would use trusted channel-sender identity to choose OAuth credentials, then route the provider callback through the Gateway before retrying the MCP transport. flowchart LR
A[Trusted channel sender] --> B[Agent MCP tool request]
B --> C[Requester identity selection]
C --> D[OAuth credential store]
D --> E[Gateway callback]
E --> F[Requester MCP transport]
F --> G[External MCP server]
Decision needed
Why: The current branch and its direct MCP SDK dependency contract could not be inspected locally, while the available real E2E result predates the current head. Before merge
Findings
Agent review detailsSecurityNeeds attention: The exact public callback and requester-credential mapping could not receive a current-head security pass. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land one canonical requester-identity flow at transport materialization, preserve the shared default, and provide fresh-install, existing-state, callback-replay, and two-user exact-head proof before merge. Do we have a high-confidence way to reproduce the issue? Not applicable as a bug reproduction. The PR body contains a credible real E2E transcript, but it is for an earlier head and cannot establish current-head behavior. Is this the best way to solve the issue? Unclear. Current main confirms transport identity construction is the correct owner boundary, but the unavailable branch prevents a best-fix comparison against its requester-runtime materialization changes. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 6c485842b1fb. LabelsLabel justifications:
EvidenceSecurity concerns:
What 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
HistoryReview history (2 earlier review cycles)
|
516fcd4 to
b2e8f00
Compare
b252ca0 to
b8bfb39
Compare
c88a6e7 to
0faecca
Compare
0faecca to
e43b637
Compare
…-prep * commit 'edb7a1692e58d78ff7e196db39ea8eff297b2e19': (1351 commits) fix(telegram): expose live location updates to hooks (openclaw#122185) fix(ui): remove the pre-creation session row (openclaw#122259) fix(openai): surface failed realtime response outcomes (openclaw#121177) fix(logging): publish diagnostics ZIP through staged atomic overwrite (openclaw#122130) test(cli): trim duplicate MCP probe process cases (openclaw#122260) feat(agents): replay persisted native video (openclaw#122257) fix(test): serialize default e2e runner (openclaw#122203) fix(ui): always show full assistant responses (openclaw#122207) feat(mcp): per-requester OAuth for MCP servers (openclaw#122166) fix(ui): preserve focus on composer accessory clicks (openclaw#122243) fix(backup): exclude state temp files (openclaw#122250) fix(browser): let attached workers exit after CDP use (openclaw#122103) test(cli): trim duplicate Claw authoring process cases (openclaw#122248) refactor(outbound): inline delivery diagnostics (openclaw#122219) refactor: eliminate final wrapper-shadowing hazards (openclaw#122157) fix(ui): keep new-session identity anchored (openclaw#122242) test(cli): trim duplicate gateway process cases (openclaw#122240) fix(media): decode local file URLs safely (openclaw#122192) refactor(agents): centralize typed activity event emission (openclaw#122188) fix(ui): effort slider matches selected level after model switches (openclaw#122125) ...
Per-requester OAuth for HTTP MCP servers: in shared channels each trusted sender connects their own account. New config: mcp.servers.<name>.oauth.identity ("shared" default, byte-identical behavior) and gateway.publicOrigin (HTTPS except loopback) for the new GET /oauth/mcp/callback served on the Gateway HTTP server. Requester tokens are isolated per (channel, account, sender) in mcp_oauth_stores rows (no schema bump); callbacks correlate through a durable state-keyed one-time index with a 10-minute TTL; per-requester servers are fail-closed out of static/scheduled runtimes; unauthenticated senders get a sign-in link with a portable URL button; MCP config mutations clear requester credentials at the canonical owner. mcp status --json keeps the legacy authStatus fields additively. Proven by a two-user self-hosted-Executor E2E through the real gateway callback. Part of openclaw#122034.
Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
In shared channels every sender's MCP tool call used the operator's OAuth tokens (or a plugin-resolver connection). There was no way for each trusted sender to authenticate to a standard MCP OAuth server as themselves. Part of #122034.
Why This Change Was Made
Adds per-requester OAuth as a core capability behind one new server option,
mcp.servers.<name>.oauth.identity: "shared" | "per-requester"(defaultshared— byte-identical to current behavior, operator store keys unchanged, zero migration).mcp_oauth_storesrow format v1: key<operatorKey>-r-<hash(channel,account,sender)>; each principal row is fully self-contained (own DCR, own lease via storeKey). No schema change.resolveMcpTransportpicks the principal at its single identity-construction site.Connect <server>URL button (mirrors the MCP Appsdetails→ channel-action seam). Before any catalog exists, a synthetic per-serverconnecttool prevents a first-sender dead-end; it is never remembered as the session catalog.GET /oauth/mcp/callbackon its existing HTTP server (second adapter at the loopback-capture seam): durable state correlation by scanning pending store rows, one-time settle (completion clears the PKCE slots), replay/unknown state → generic expired page, product copy only. Newgateway.publicOrigin(origin-only, validated likemcp.apps.sandboxOrigin) builds the redirect URL;openclaw doctorwarns when per-requester is configured without it.readMcpOAuthCredentialsStatus's six-boolean bag is replaced by a closed per-principal status union; CLI list/status shows connected-principal counts. Server unset/replacement clears requester rows by key prefix.Requester-row lifecycle: created on first start-authorization; cleared by server unset/replacement prefix cleanup; survive restart (callback correlation is row-scan based, no in-memory registry); unreachable by legacy JSON import (filename grammar cannot produce
-r-keys).v1 exclusions (follow-ups on #122034): CLI-runtime bearer projection stays operator-only (config rejects
authProfileId+per-requester), Control UI, auto-resume of the interrupted turn (next message picks up tokens, catalog failure-retry window is 5s), plugin resolver contract extension, URL button on the Codex dynamic-tool path (text-only there),openclaw mcp login/logoutfor requester principals.User Impact
Operators can point a shared bot at a standard MCP OAuth server (proven against a self-hosted Executor instance) and have each trusted sender connect their own account; senders who haven't connected get a sign-in button instead of silent failure or someone else's data.
Evidence
tsgo,check:test-types(all three lanes), oxfmt, oxlint,git diff --check, both knip lanes (deadcode:full),check:import-cycles(0 cycles): green on this head.Maintainer Decision: shared-channel sign-in links (2026-08-11)
Reviewed the local ClawSweeper P1 (state-bearing authorize URL visible in the shared channel). Maintainer decision (@obviyus): accepted tradeoff for v1, not a blocker:
docs/cli/mcp.mdnow states this trust model explicitly next to the feature docs.Two-user Executor E2E (real gateway callback) — PASS on review-clean head c88a6e7647d
Self-hosted Executor (MIT, Docker) as a standard MCP OAuth server; real OpenClaw gateway (isolated state dir,
gateway.publicOriginloopback); real qa-channel inbound turns; headless per-user login/consent. Asserts per-user token isolation both directions, durable state-index consumption, replay 404, and unconnected-sender negative.{ "scenario": "OpenClaw per-requester MCP OAuth through the real Gateway callback against self-hosted Executor at c88a6e7647d6ae9be3f155649ab2ba06bf0d3fb3", "steps": [ { "name": "Executor users and isolation markers", "pass": true, "evidence": "Executor health ok; preserved userA/userB IDs distinct; userA sees only USER_A_ONLY and userB sees only USER_B_ONLY. See executor-preserved-state.log." }, { "name": "Fresh isolated Gateway and real inbound channel harness", "pass": true, "evidence": "Fresh R5 state; Gateway 45086; QA bus 38636; mock provider 38122; loopback HTTP publicOrigin accepted; dist build stamp exactly c88a6e7647d6ae9be3f155649ab2ba06bf0d3fb3. See build-integrity.log and gateway-ready.json." }, { "name": "senderA connect, real callback, consumed pending authorization", "pass": true, "evidence": "Real senderA inbound turn executed executor__connect; pending row for senderA store changed 1 to 0; userA consent callback returned HTTP 200 connected page; senderA store contains a token. See senderA-pending-before-callback.log and senderA-oauth-summary.log." }, { "name": "senderA list-artifacts isolation", "pass": true, "evidence": "After 6 seconds, executor__list-artifacts contained USER_A_ONLY and excluded USER_B_ONLY. See senderA-isolation-summary.log." }, { "name": "senderB independent connect, real callback, consumed pending authorization", "pass": true, "evidence": "senderB used a distinct authorization URL and requester store key; pending row changed 1 to 0; userB callback returned HTTP 200; exactly two authorized requester stores remained. See senderB-pending-before-callback.log and senderB-oauth-summary.log." }, { "name": "senderB list-artifacts isolation", "pass": true, "evidence": "After 6 seconds, executor__list-artifacts contained USER_B_ONLY and excluded USER_A_ONLY. See senderB-isolation-summary.log." }, { "name": "Requester-store isolation and callback replay", "pass": true, "evidence": "Before senderC: exactly two distinct -r- rows, zero pending rows, distinct senderA/senderB access tokens; exact senderA callback replay returned 404 already used; zero store-row parse errors in replay segment or full Gateway log; state stayed two rows and zero pending. See sqlite-row-summary.log and callback-replay-summary.log." }, { "name": "Unconnected senderC negative", "pass": true, "evidence": "senderC executed executor__connect with a third distinct authorization URL; no user markers, token fields, or stored token values leaked. Final live state: three requester stores, two authorized, one pending senderC. See senderC-negative-summary.log and final-live-state-summary.log." } ], "overallPass": true }