Skip to content

fix(mcp): retry typed OAuth client metadata errors - #160243

Open
Patrick-Erichsen wants to merge 1 commit into
mainfrom
codex/fix-mcp-dcr-registration-retry
Open

Patrick-Erichsen wants to merge 1 commit into
mainfrom
codex/fix-mcp-dcr-registration-retry

Conversation

@Patrick-Erichsen

@Patrick-Erichsen Patrick-Erichsen commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes MCP OAuth login stopping before browser authorization when a provider rejects the default loopback callback with a typed SDK error but omits error_description.

User Impact

Calendly registration now retries the existing localhost callback once. Explicit callbacks and failed authorization-code exchanges keep their existing behavior.

Why This Change Was Made

Calendly returned invalid_client_metadata with a nested errors.redirect_uri field. The SDK preserves its error class but produces an empty message, so OpenClaw’s text-only matcher missed the existing fallback. Recognize the SDK class as well as the established textual errors.

Evidence

  • Actual regression with original matcher: typed SDK case failed, textual case passed. Fixed owner-boundary tests pass, including callback persistence, completion, cleanup and no retry on code-exchange errors.
  • Real Calendly registration through the native built-in manifest and OpenClaw OAuth owner returned a localhost redirect and PKCE S256 authorization URL. Native Notion registration also passed with the normal numeric loopback callback.
  • Registration is real; user consent, token exchange and OAuth tool calls remain untested. Unit OAuth transports are simulated.

Stack-head validation

  • node scripts/check-changed.mjs --base 1fe560c198c2917154e2e1b130b0df3352ac5114 passed: static guards, dependency/lock checks, generated metadata, all typecheck graphs, dead-code scans, lint and runtime import cycles.
  • pnpm test src/agents/mcp-oauth.test.ts src/plugins/bundle-mcp.test.ts src/agents/bundle-mcp-config.test.ts src/cli/mcp-cli.test.ts src/cli/mcp-cli.plugins.test.ts src/cli/mcp-cli.oauth.test.ts src/plugins/contracts/package-manifest.contract.test.ts src/plugins/contracts/extension-runtime-dependencies.contract.test.ts --maxWorkers=1 passed: 729 tests / 8 files / 5 routed shards in 420.34s. The new CLI plugin suite took 54.31s including cold transformation (3 tests); the infra suite took 200.74s (67 tests). Hosted CI timing was not yet available.
  • Six additional Doctor contract/closure tests passed in the full check. Fresh P2 review findings about Typeform/Customer.io regions were addressed through documented existing overrides and live regional registration proof.

Package and upgrade proof

Validated stack head 5859d7c3d184e80cfed01304a93681ff69d64036 on macOS arm64 / Node 24.19.0:

  • Canonical node scripts/package-openclaw-for-docker.mjs --allow-unreleased-changelog --output-dir .artifacts/claw-723/package passed (19m47.6s), including declaration builds, UI build, package inventory and extracted runtime import-graph checks.
  • Built openclaw-2026.9.6.tgz, 99,082,240 bytes, SHA-256 0ee3ab0c8d43e777431ce557797c9609dbeb10bef9fbaf40a0d5dcf4954bcb04. All 35 compiled entries are present; packed manifests match source exactly.
  • Fresh isolated npm install: plugins list --json finds all 35 under the installed package, origin bundled, disabled. Enabling GoDaddy/Excalidraw exposes native MCP servers without manual config; live mcp probe returns 2/5 tools. Authenticated GitHub returns 45 tools; output is redacted. Missing-key fail-closed behavior and regional endpoint overrides pass. npm lifecycle-script approvals are limited to this disposable fixture; no user/global npm policy changed.
  • Real published-driver cell: registry [email protected] ran update --tag <candidate.tgz> --yes --json --no-restart --timeout 900. Result status: ok, installed build 2026.9.6-5859d7c3d184-2026-09-28T06-43-34.310Z; maintained upgrade-survivor helper verified baseline, candidate and installed application-byte identities. Existing disabled MCP config and enabled memory-core survived unchanged; all 35 additions remain disabled.
  • The updater's migration rehearsal, config validation, plugin resolution, isolated Gateway canary, Doctor and post-plugin lint passed. Its nonfatal warnings described deferred model-retirement repair, loopback-only hosting and deliberately skipped service management for isolated state. No personal Gateway restart or production release. Upgrade endpoint is a disabled synthetic fixture; separate provider calls above are live.

An earlier package attempt correctly refused a namespace change caused by concurrent generated-doc work. The final build ran after generation and checks finished, on stable inputs. OAuth consent/account tools and ten additional key-service accounts remain unverified; discovery-only inclusion is the approved milestone.

Stack order

  1. fix(mcp): retry typed OAuth client metadata errors #160243 — typed OAuth registration retry
  2. fix(plugins): resolve native MCP header environment references #160244 — native MCP header environment resolution
  3. fix(mcp): discover enabled plugin servers in the CLI #160245 — enabled plugin MCP discovery in the CLI
  4. feat(plugins): add opt-in company MCP built-ins #160246 — 35 opt-in company built-ins

Review only; no merge or release is authorized.

Hosted CI follow-up

Hosted CI is not green. Local validation above passed on the pinned stack; GitHub's later merge-ref/stack runs reported:

  • Bottom OAuth PR: run 36391006397 failed four unchanged service-operation-lock.retained-custody.test.ts cases (missing, unknown-phase, unknown-version, relative-source); sibling jobs were cancelled. The newer merge base includes upstream b107d4af, whose handoff-store refactor makes release() throw for malformed custody where the unchanged test expects false. The OAuth PR changes neither that owner nor its tests. A local replay of the same test-group order on pure upstream c136ec631464 reproduced all four failures with no CLAW-723 code present: 900 passed, 4 failed, 5 skipped across the same 18-file group in 112.43s (macOS; hosted run was Linux). The first archive attempt stopped before tests because scoped dependency links were missing; the corrected prerequisite setup is the reproducing run.
  • Header and built-in layers: run 36391038048 and run 36391101586 stop in preflight because the existing changed-owner planner generates 169/148 Node rows against its 130-row cap. No tests execute in those runs. Upstream a08479ac already fixes that planner handoff without raising the limit or dropping coverage; it is newer than this validated stack base.
  • The CLI layer's hosted checks were still processing with no failed checks at the follow-up read. No workflow dispatch, rerun, policy bypass or push merely to obtain green was performed.

These hosted outcomes remain review/landing context, not passing evidence. No merge is authorized.

@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: 6f67482b95b9e17022558322ce4190bb18417f76
  • Maintainer: @Patrick-Erichsen
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/mcp-oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@Patrick-Erichsen Patrick-Erichsen changed the title codex/fix mcp dcr registration retry fix(mcp): retry typed OAuth client metadata errors Sep 28, 2026
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 28, 2026, 3:41 AM ET / 07:41 UTC (Revision 2).

ClawSweeper review

What this changes

The branch makes OpenClaw retry MCP OAuth client registration with its existing localhost callback when the SDK returns a typed metadata error, and extends the coordinator test.

Merge readiness

✅ Ready for maintainer review

Current main and the latest release still miss SDK client-metadata errors with an empty description. This focused PR addresses that gap, and the review found no discrete introduced defect.

Priority: P2
Reviewed head: 6f67482b95b9e17022558322ce4190bb18417f76

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused, has a meaningful regression case, and reports real provider registration through the changed path.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.
Evidence reviewed 9 items Introduced change: The pinned PR delta adds typed SDK error recognition to the existing registration retry classifier; the verified test merge changes only the two introduced OAuth files.
Current-main gap: Current main still classifies registration errors only by their string representation, so an empty-description typed error does not select the existing localhost retry.
SDK contract: The target pins SDK 1.30.0. Its OAuth client imports the same error class from the server-auth error module and constructs a typed error with an empty message when a response omits error_description.
Findings None None.
Security None None.

How this fits together

The MCP OAuth coordinator takes a configured server and SDK registration result, then prepares a browser authorization URL and stores the pending login session. The CLI or Gateway later completes the callback and token exchange.

flowchart LR
  A[MCP server config] --> B[OAuth coordinator]
  B --> C[SDK client registration]
  C --> D{Metadata rejected?}
  D -->|Eligible retry| E[Localhost callback retry]
  D -->|Accepted| F[Browser authorization URL]
  E --> F
  F --> G[Stored login session]
  G --> H[Callback and token exchange]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +5, Tests +2. Total +7 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 1 +5
Tests 1 55 53 +2
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 61 54 +7

Review metrics

None.

Technical review

Best possible solution:

Keep one coordinator-owned registration retry, with the explicit-callback and code-exchange exclusions preserved and covered at the OAuth boundary.

Do we have a high-confidence way to reproduce the issue?

Yes. Current main has a text-only matcher while SDK 1.30.0 creates an empty-message typed registration error when error_description is absent; the reviewer did not execute the provider flow.

Is this the best way to solve the issue?

Yes. Extending the existing coordinator retry recognizes the SDK result without creating a second OAuth flow or changing configuration and storage contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: A real provider's MCP login can stop before browser authorization, but the affected registration path has limited blast radius.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.

Label justifications:

  • P2: A real provider's MCP login can stop before browser authorization, but the affected registration path has limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR evidence reports a real Calendly registration through the native manifest and changed OpenClaw OAuth owner on the validated stack, producing the localhost callback and PKCE S256 authorization URL after the retry. Consent and token exchange were not demonstrated, but the changed behavior is registration; no stored-data format changes.

Evidence

What I checked:

  • Introduced change: The pinned PR delta adds typed SDK error recognition to the existing registration retry classifier; the verified test merge changes only the two introduced OAuth files. (src/agents/mcp-oauth.ts:64, 6f67482b95b9)
  • Current-main gap: Current main still classifies registration errors only by their string representation, so an empty-description typed error does not select the existing localhost retry. (src/agents/mcp-oauth.ts:61, ff8c752d852f)
  • SDK contract: The target pins SDK 1.30.0. Its OAuth client imports the same error class from the server-auth error module and constructs a typed error with an empty message when a response omits error_description. (src/client/auth.ts:387, 2d889f2b329e)
  • Retry boundary: The coordinator retries once only when no explicit callback was supplied, then reads the saved redirect and PKCE session before returning the browser URL. (src/agents/mcp-oauth.ts:415, 6f67482b95b9)
  • Regression coverage: The parameterized owner-boundary test covers both the new typed case and the prior textual case, including persisted callback state and completion; authorization-code exchange retains a separate no-retry test. (src/agents/mcp-oauth.test.ts:789, 6f67482b95b9)
  • Product entry point: The documented operator flow starts with openclaw mcp login and continues through a loopback browser callback into shared SQLite OAuth state. Public docs: docs/cli/mcp/transports.md. (docs/cli/mcp/transports.md:153, ff8c752d852f)

Likely related people:

  • weiqinl: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (1 earlier review cycle)
  • reviewed 2026-09-28T07:27:34.464Z sha 6f67482 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: S stale Marked as stale due to inactivity status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant