Skip to content

refactor(mcp): single OAuth identity owner + resumable authorization session - #122115

Merged
obviyus merged 2 commits into
mainfrom
feat/mcp-oauth-identity-session
Aug 11, 2026
Merged

obviyus merged 2 commits into
mainfrom
feat/mcp-oauth-identity-session

Conversation

@obviyus

@obviyus obviyus commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

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 (resolveMcpOAuthStoreKey deleted, zero references remain). Part B: the authorization dance moves into the coordinator as a resumable session — startMcpOAuthAuthorization persists the pending verifier/authorize URL in the existing store-row slots and releases the lease; completeMcpOAuthAuthorization reacquires 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 login flow, manual --code path, 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

  • Grouped focused run green (exit 0): 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-oauth
  • New coordinator boundary tests drive start → pending-persisted → simulated restart → complete against the real SQLite store; wrong code fails without clearing pending; a second start supersedes the first.
  • Production LOC net −7 (+224/−231); tests net −8, with mock-heavy CLI dance tests replaced by interface-level coordinator tests.
  • git diff --check, oxfmt, tsgo lanes clean on the patch.

@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 15:40
@obviyus
obviyus requested a review from a team as a code owner August 11, 2026 15:40
@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
…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.
@obviyus
obviyus force-pushed the feat/mcp-oauth-identity-session branch from 5116a0c to ad417b2 Compare August 11, 2026 15:41
@obviyus
obviyus enabled auto-merge (squash) August 11, 2026 15:47
@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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: found issues before merge. Reviewed August 11, 2026, 11:58 AM ET / 15:58 UTC.

ClawSweeper review

What this changes

The PR centralizes MCP OAuth identity and moves authorization start and completion into a resumable SQLite-backed coordinator used by the CLI.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep 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
Reviewed head: 91f6c24cc8e20da1605b48cd0d87a69322753b72

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The refactor has strong new-session coverage but needs one focused upgrade-compatibility repair before it is merge-ready.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-owned PR is not subject to the external-contributor proof gate; its body and integration test provide useful supplemental evidence.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-owned PR is not subject to the external-contributor proof gate; its body and integration test provide useful supplemental evidence.
Evidence reviewed 6 items Introduced upgrade rejection: The PR head rejects completion unless both a verifier and redirect URL are already persisted.
Legacy pending-session shape: Before this PR, redirect initiation stored the authorization URL but not the normal configured/default redirect URL; it only stored a redirect for the localhost fallback.
Existing manual completion contract: The base CLI accepted a later --code submission, while the old coordinator reconstructed its redirect from configuration or the provider default.
Findings 1 actionable finding [P1] Preserve pre-refactor pending OAuth sessions
Security None None.

How this fits together

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

Before merge

  • Preserve pre-refactor pending OAuth sessions (P1) - Before this change, normal manual login persisted the verifier and authorization URL but not the configured/default redirect URL; completion reconstructed that value. This new guard rejects those valid pending rows after an upgrade, so mcp login <name> --code cannot finish. Derive the redirect through the existing configured/default path when the stored field is absent and cover a base-shaped row.
  • Resolve merge risk (P1) - An operator who begins a manual OAuth flow before upgrading can receive a valid code but be forced to restart after the new completion guard rejects the legacy pending row.
  • Resolve merge risk (P1) - The MCP SDK dependency-contract pass could not run because its source is unavailable in this checkout and the promisor remote is unreachable.
  • Complete next step (P2) - A concrete P1 upgrade regression needs correction on this maintainer-protected OAuth path before normal merge review can continue.

Findings

  • [P1] Preserve pre-refactor pending OAuth sessions — src/agents/mcp-oauth.ts:418-420
Agent review details

Security

None.

PR surface

Source -5, Tests -11. Total -16 across 22 files.

View PR surface stats
Area Files Added Removed Net
Source 10 229 234 -5
Tests 12 427 438 -11
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 22 656 672 -16

Review metrics

Metric Value Why it matters
Production vs test LOC production +224/-231 (net -7); tests and test support +432/-441 (net -9) The refactor is net-negative, but its OAuth-state compatibility change needs the missing upgrade regression coverage before merge.

Stored data model

Persistent data-model change detected: serialized state: src/infra/state-migrations.mcp-oauth.test.ts, serialized state: src/infra/state-migrations.mcp-oauth.ts, unknown-data-model-change: src/infra/state-migrations.mcp-oauth.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve pending upgrade sessions (recommended)
    Derive the completion redirect from the stored value when present and otherwise retain the existing configured/default resolution, with a regression test for a legacy pending row.
  2. Accept forced reauthorization
    Deliberately require operators with a pre-upgrade pending login to start authorization again, documenting that compatibility break before merge.

Technical review

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

  • [P1] Preserve pre-refactor pending OAuth sessions — src/agents/mcp-oauth.ts:418-420
    Before this change, normal manual login persisted the verifier and authorization URL but not the configured/default redirect URL; completion reconstructed that value. This new guard rejects those valid pending rows after an upgrade, so mcp login <name> --code cannot finish. Derive the redirect through the existing configured/default path when the stored field is absent and cover a base-shaped row.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.91

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 8f61ec4120b8.

Labels

Label changes:

  • add P1: The PR can break an existing manual MCP OAuth completion path for users upgrading mid-authorization.
  • add merge-risk: 🚨 compatibility: A persisted pre-refactor authorization session no longer satisfies the new completion precondition.
  • add merge-risk: 🚨 auth-provider: The regression is in the OAuth credential lifecycle that exchanges authorization codes for MCP credentials.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This maintainer-owned PR is not subject to the external-contributor proof gate; its body and integration test provide useful supplemental evidence.

Label justifications:

  • P1: The PR can break an existing manual MCP OAuth completion path for users upgrading mid-authorization.
  • merge-risk: 🚨 compatibility: A persisted pre-refactor authorization session no longer satisfies the new completion precondition.
  • merge-risk: 🚨 auth-provider: The regression is in the OAuth credential lifecycle that exchanges authorization codes for MCP credentials.
  • 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: This maintainer-owned PR is not subject to the external-contributor proof gate; its body and integration test provide useful supplemental evidence.

Evidence

What I checked:

  • Introduced upgrade rejection: The PR head rejects completion unless both a verifier and redirect URL are already persisted. (src/agents/mcp-oauth.ts:418, 91f6c24cc8e2)
  • Legacy pending-session shape: Before this PR, redirect initiation stored the authorization URL but not the normal configured/default redirect URL; it only stored a redirect for the localhost fallback. (src/agents/mcp-oauth-provider.ts:162, dfb47122585e)
  • Existing manual completion contract: The base CLI accepted a later --code submission, while the old coordinator reconstructed its redirect from configuration or the provider default. (src/cli/mcp-cli.ts:1348, dfb47122585e)
  • Finding provenance: Blame attributes the rejecting guard to this PR's main refactor commit. (src/agents/mcp-oauth.ts:418, ad417b24dbe6)
  • New-session coverage: The PR tests restart, invalid code, and superseded starts using the real MCP SDK, but seeds only sessions created by the new start path. (src/agents/mcp-oauth.test.ts:891, 91f6c24cc8e2)
  • Dependency inspection limitation: This change directly imports MCP SDK OAuth APIs, but the SDK source was absent from node_modules and the partial-clone fetch could not resolve GitHub, so its contract could not be independently inspected here. (package.json:2026, e31a6e29fff7)

Likely related people:

  • steipete: Introduced the SQLite-backed MCP OAuth state and provider boundary in the foundational refactor. (role: original OAuth state owner; confidence: high; commits: f3d1f02dc134; files: src/agents/mcp-oauth-store.ts, src/agents/mcp-oauth-provider.ts)
  • yetval: Authored the current-main issuer-binding repair whose provider and coordinator boundaries this PR refactors. (role: recent security-path contributor; confidence: high; commits: 01d84e18a4f6; files: src/agents/mcp-oauth.ts, src/agents/mcp-oauth-provider.ts, src/agents/mcp-oauth-refresh-issuer.test.ts)
  • obviyus: Co-authored the merged issuer-binding work and authored this follow-up refactor. (role: recent OAuth refactor contributor; confidence: high; commits: 01d84e18a4f6, ad417b24dbe6; files: src/agents/mcp-oauth.ts, src/cli/mcp-cli.ts)

Rank-up moves

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

  • Add a regression seeded from the pre-refactor pending session shape.
  • Run the focused MCP OAuth and CLI integration suites on the repaired exact head.

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.

@obviyus
obviyus merged commit bf5ce3d into main Aug 11, 2026
128 checks passed
@obviyus
obviyus deleted the feat/mcp-oauth-identity-session branch August 11, 2026 16:05
obviyus added a commit that referenced this pull request Aug 11, 2026
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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
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]>
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 maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. 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