Skip to content

feat(mcp): per-requester OAuth for MCP servers - #122166

Merged
obviyus merged 5 commits into
mainfrom
t3code/multiplayer-mcp-oauth
Aug 11, 2026
Merged

obviyus merged 5 commits into
mainfrom
t3code/multiplayer-mcp-oauth

Conversation

@obviyus

@obviyus obviyus commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

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" (default shared — byte-identical to current behavior, operator store keys unchanged, zero migration).

  • Requester rows reuse mcp_oauth_stores row 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.
  • Per-requester servers are partitioned out of the static/scheduled runtime (fail-closed without trusted sender identity) and materialize per-sender transports; resolveMcpTransport picks the principal at its single identity-construction site.
  • Unauthenticated sender calling a tool receives a connect result with the authorize URL in the text plus a portable Connect <server> URL button (mirrors the MCP Apps details → channel-action seam). Before any catalog exists, a synthetic per-server connect tool prevents a first-sender dead-end; it is never remembered as the session catalog.
  • The Gateway serves GET /oauth/mcp/callback on 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. New gateway.publicOrigin (origin-only, validated like mcp.apps.sandboxOrigin) builds the redirect URL; openclaw doctor warns 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/logout for 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

  • Boundary tests: two-requester token isolation, restart survival, wrong-code (no token write), supersede (second start wins, first state rejected), callback route (state correlation, replay, method/path, error param), harness connect results, partition fail-closed, schema/doctor matrix, prefix cleanup, status union. Grouped run: 8 shards, 407 tests green.
  • 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.
  • Two-user Executor Docker E2E (per-user OAuth through the gateway callback, isolation assertion): running now; result will be posted before merge.
  • Production/test LOC: ~+690 production (new capability: identity grammar, gateway route, connect surface, config contract), ~+820 tests.

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:

  • Per-requester scope only activates for trusted senders; OpenClaw's shared-channel model assumes an operator-curated, mutually trusted roster.
  • Identical possession semantics already ship today via the Composio resolver plugin, whose upstream-app OAuth links are likewise delivered in chat (verified in the deployed plugin source: its resolver documents "OAuth links delivered in chat by the router's manage-connections tool").
  • The link is single-use (completion clears the PKCE slots), superseded by any newer start, and mis-use binds the clicker's own account to the requester row — it cannot leak an existing token.
  • docs/cli/mcp.md now states this trust model explicitly next to the feature docs.
  • A requester-private sign-in handoff (DM delivery) is tracked as a follow-up on [Feature]: Per-requester OAuth for MCP servers (multiplayer tool identity) #122034.

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.publicOrigin loopback); 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
}

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 11, 2026 17:31
@obviyus
obviyus requested a review from a team as a code owner August 11, 2026 17:31
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 11, 2026, 3:59 PM ET / 19:59 UTC.

ClawSweeper review

What this changes

Adds configurable per-requester OAuth for HTTP MCP servers, with requester-isolated credential storage, a Gateway callback, and sender-facing sign-in actions.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep 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
Reviewed head: bbe769f150c24ea117c7351d889839af2c40fc43
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The design and earlier E2E evidence are useful, but current-head source, dependency, and security review evidence is incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a repository member, so contributor proof is not a merge gate; however, the available real E2E transcript predates the current head and remains an exact-head review gap.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a repository member, so contributor proof is not a merge gate; however, the available real E2E transcript predates the current head and remains an exact-head review gap.
Evidence reviewed 8 items Current main is operator-only: The OAuth identity type only permits an operator principal and keys credentials by server name and URL.
Transport owner boundary: Current transport creation always constructs the operator identity before passing it to the OAuth bearer wrapper; requester isolation must be selected here, not downstream.
Requester sibling path: Current requester-scoped runtimes require a plugin resolver to produce an override; the proposed OAuth path must explicitly bridge this materialization boundary.
Findings None None.
Security Needs attention Complete the current callback security review: The new public Gateway callback maps OAuth state to requester credentials, but its exact current implementation was unavailable for inspection after the branch force-pushes.

How this fits together

Configured 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]
Loading

Decision needed

Question Recommendation
Should this PR advance only after a rebase plus a redacted two-user OAuth callback run on current head, or may the earlier-head evidence be accepted for this security-sensitive feature? Require exact-head evidence: Rebase or otherwise make the current head inspectable, then rerun the two-user Gateway callback and isolation scenario on that head.

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

  • Resolve security concern: Complete the current callback security review - The new public Gateway callback maps OAuth state to requester credentials, but its exact current implementation was unavailable for inspection after the branch force-pushes.
  • Resolve merge risk (P1) - GitHub reports the current head as dirty; it must be rebased or otherwise made mergeable before final review.
  • Resolve merge risk (P1) - The available two-user E2E transcript identifies cbe8c4c8c2e33373c91909e2546b3ac30e83e517, not current head bbe769f150c24ea117c7351d889839af2c40fc43.
  • Resolve merge risk (P1) - New requester identity and public callback configuration affect persisted OAuth state, existing deployments, and the Gateway security boundary; the exact implementation and MCP SDK contract could not be inspected.

Findings

  • [medium] Complete the current callback security review — src/gateway/mcp-oauth-callback.ts:1
Agent review details

Security

Needs attention: The exact public callback and requester-credential mapping could not receive a current-head security pass.

Review metrics

Metric Value Why it matters
Configuration surfaces 2 added, 0 removed The PR introduces requester OAuth identity selection and a public Gateway origin, both compatibility-sensitive operator settings.
Production versus tests production approximately +690, tests approximately +820 The PR body reports substantial feature growth across durable state, Gateway handling, and runtime transport paths; exact diff accounting was unavailable.

Stored data model

Persistent data-model change detected: database schema: src/state/openclaw-state-db-schema-additive.ts, database schema: src/state/openclaw-state-schema.sql, migration/backfill/repair: src/cli/mcp-cli.oauth-integration.test.ts, migration/backfill/repair: src/commands/doctor-config-analysis.test.ts, migration/backfill/repair: src/commands/doctor-config-analysis.ts, migration/backfill/repair: src/commands/doctor-config-flow.test.ts, and 8 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Refresh current-head proof (recommended)
    Resolve the dirty merge state and publish redacted current-head two-user callback, isolation, replay, and upgrade evidence before merge.
  2. Pause pending security review
    Keep the PR open until the complete exact diff and MCP SDK contract can receive a dedicated security review.

Technical review

Best 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.

Labels

Label justifications:

  • P2: This is a bounded but substantial multi-user OAuth capability with operator-facing configuration.
  • merge-risk: 🚨 compatibility: The new identity mode, callback origin, and stored requester rows alter MCP OAuth setup and upgrade behavior.
  • merge-risk: 🚨 security-boundary: The feature maps shared-channel requester identity and public OAuth callbacks to credential-bearing state.
  • merge-risk: 🚨 availability: An invalid or unreachable public callback origin prevents requester sign-in from completing.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The author is a repository member, so contributor proof is not a merge gate; however, the available real E2E transcript predates the current head and remains an exact-head review gap.

Evidence

Security concerns:

  • [medium] Complete the current callback security review — src/gateway/mcp-oauth-callback.ts:1
    The new public Gateway callback maps OAuth state to requester credentials, but its exact current implementation was unavailable for inspection after the branch force-pushes.
    Confidence: 0.94

What I checked:

Likely related people:

  • obviyus: Merged history shows repeated MCP requester-scope and OAuth/Gateway work, including the requester-scoped MCP implementation. (role: feature owner and recent area contributor; confidence: high; commits: 834561ad6723, 8b66fe773f40, 2a3a840aaf80; files: src/agents/mcp-connection-resolver.ts, src/agents/mcp-transport.ts, src/agents/mcp-oauth.ts)
  • steipete: Current MCP OAuth callback and state history includes recent work by this contributor; deeper line provenance was unavailable from the blobless checkout. (role: recent current-main contributor; confidence: medium; commits: de9314301f, f3e1b02dc1; files: src/agents/mcp-oauth.ts, src/agents/mcp-oauth-store.ts, src/gateway)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Make current head inspectable and mergeable.
  • Attach a redacted two-user Gateway OAuth callback run for current head.
  • Complete the MCP SDK and callback security review.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-11T18:06:35.093Z sha b8cb3f4eef032c370ac8d5c9286574b5810eb119 :: found issues before merge. :: [P1] Avoid full credential-store scans on public callbacks
  • reviewed 2026-08-11T18:55:07.002Z sha b252ca090d2817f6c743eec215cc8123ef767d8a :: found issues before merge. :: [P2] Keep unknown OAuth callbacks read-only

@obviyus
obviyus force-pushed the t3code/multiplayer-mcp-oauth branch 2 times, most recently from 516fcd4 to b2e8f00 Compare August 11, 2026 18:46
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 11, 2026
@obviyus
obviyus force-pushed the t3code/multiplayer-mcp-oauth branch from b252ca0 to b8bfb39 Compare August 11, 2026 19:22
@obviyus
obviyus force-pushed the t3code/multiplayer-mcp-oauth branch 7 times, most recently from c88a6e7 to 0faecca Compare August 11, 2026 20:35
@obviyus
obviyus force-pushed the t3code/multiplayer-mcp-oauth branch from 0faecca to e43b637 Compare August 11, 2026 20:37
@obviyus
obviyus enabled auto-merge (squash) August 11, 2026 20:37
@obviyus
obviyus disabled auto-merge August 11, 2026 20:44
@obviyus
obviyus enabled auto-merge (squash) August 11, 2026 20:45
@obviyus
obviyus merged commit 6a4a546 into main Aug 11, 2026
120 checks passed
@obviyus
obviyus deleted the t3code/multiplayer-mcp-oauth branch August 11, 2026 20:58
vincentkoc added a commit to tangtaizong666/openclaw that referenced this pull request Aug 11, 2026
…-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)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation extensions: codex gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant