Repository navigation
Description
Summary
Remote MCP servers that use OAuth fail to connect. I hit two distinct bugs in the MCP OAuth client, both reproducible against public servers (PayPal and Calendly). Reproduced on 2026.6.1 (2e08f0f) and 2026.6.5-beta.2 (131c9bf).
Environment
- OpenClaw 2026.6.1 / 2026.6.5-beta.2
- macOS, Node v24
- Servers added with
openclaw mcp add <name> --url <url> --transport streamable-http --auth oauth
Bug 1 — Invalid regular expression: /^https\:\/\//u: Invalid escape (post-auth crash)
Server: https://mcp.paypal.com/mcp (streamable-http, OAuth).
Repro
openclaw mcp add paypal --url https://mcp.paypal.com/mcp --transport streamable-http --auth oauthopenclaw mcp login paypal→ authorize in browser →openclaw mcp login paypal --code <code>→MCP OAuth credentials saved for "paypal"(OAuth succeeds).openclaw mcp probe paypal
Result
[bundle-mcp] failed to start server "paypal" (https://mcp.paypal.com/mcp): SyntaxError: Invalid regular expression: /^https\:\/\//u: Invalid escape
The token is saved; the crash is downstream, while building a regex that matches ^https://. The pattern is written as /^https\:\/\// and compiled with the unicode (u) flag. In unicode mode, an identity escape of a non-syntax character (\:) is an Invalid escape.
Fix: drop the unnecessary backslash before : (and / need not be escaped): use /^https:\/\// rather than /^https\:\/\//u, or remove the u flag from that pattern.
Bug 2 — OAuth error responses surfaced as "[object Response]" (masks the real error)
Server: https://mcp.calendly.com/ (streamable-http, OAuth).
Repro
openclaw mcp add calendly --url https://mcp.calendly.com --transport streamable-http --auth oauthopenclaw mcp login calendly
Result (immediately, before any authorize URL is printed)
Invalid OAuth error response: SyntaxError: Unexpected token 'o', "[object Response]" is not valid JSON. Raw body: [object Response]
This masks the real failure, which is at the RFC 7591 dynamic client registration step. Calendly's discovery is well-formed:
GET https://mcp.calendly.com/.well-known/oauth-protected-resource→ 200,authorization_servers: ["https://calendly.com/"]GET https://calendly.com/.well-known/oauth-authorization-server→ 200, valid JSON, advertisesregistration_endpoint: https://calendly.com/oauth/register
Reproducing the registration POST that OpenClaw makes (redirect_uri http://127.0.0.1:<port>/oauth/callback) returns HTTP 400 with a perfectly readable JSON body:
{"error":"invalid_client_metadata","errors":{"redirect_uri":["must be an HTTPS/SSL URI or redirect to localhost."]}}There are two issues here:
2a) The error body is not read. OpenClaw appears to pass the fetch Response object to JSON.parse (hence the literal string "[object Response]") instead of await response.text() / .json(). This swallows every OAuth error and makes failures undiagnosable. Reading and surfacing the body would have shown the cause immediately.
2b) Loopback redirect uses 127.0.0.1 where the AS requires localhost. OpenClaw registers http://127.0.0.1:<port>/oauth/callback. Calendly's /oauth/register rejects the IP literal but accepts http://localhost:<port>/oauth/callback:
# 127.0.0.1 -> 400 invalid_client_metadata (as above)
# localhost -> 201 Created, client registered successfully
RFC 8252 §7.3 permits both the loopback IP and localhost, but some authorization servers (Calendly) only accept localhost. Consider using localhost for the loopback redirect, or making the loopback host configurable / falling back from 127.0.0.1 to localhost on registration failure.
Impact
Remote OAuth MCP servers are currently unusable: PayPal crashes after a successful auth (Bug 1), and Calendly cannot register, with the real cause hidden (Bug 2). Fixing 2a alone would at least make these failures diagnosable; 1 and 2b are the concrete connectivity fixes.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 8, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 8, 2026, 9:51 AM ET / 13:51 UTC.
Summary
Keep open: current main still routes documented MCP OAuth login/probe through the reported core paths, still defaults dynamic client registration to a 127.0.0.1 redirect, and the reporter's follow-up shows a localhost redirect makes Calendly work while PayPal still hits the regex failure.
Reproducibility: no. full local OAuth login/probe was run, but current source plus the reporter's localhost follow-up make the Calendly path source-reproducible; the PayPal regex failure remains externally reproduced but not source-rooted here.
Ways to help us reproduce this
Next step
Auth-provider behavior is source-supported, but redirect default/fallback policy and the still-untraced PayPal regex failure need maintainer/security judgment before an automated repair lane.
Review details
Best possible solution:
Fix this in core MCP OAuth by surfacing real DCR error bodies, choosing a tested localhost-compatible loopback strategy, and root-causing the PayPal regex crash with focused tests and live redacted proof.
Do we have a high-confidence way to reproduce the issue?
No full local OAuth login/probe was run, but current source plus the reporter's localhost follow-up make the Calendly path source-reproducible; the PayPal regex failure remains externally reproduced but not source-rooted here.
Is this the best way to solve the issue?
The reported direction is right for Calendly error surfacing and loopback host handling, but the best fix should avoid a broad new config surface and should root-cause the PayPal regex before changing code.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model gpt-5.5, reasoning high; reviewed against 9a82b60024b5.
Label changes
Label changes:
P1: A documented MCP OAuth login/probe workflow fails against public remote servers and blocks affected users from using those authenticated MCP tools.impact:auth-provider: The report is about MCP OAuth registration, redirect metadata, stored OAuth credentials, and authenticated remote-server connection behavior.issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.clawsweeper:needs-live-repro: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.clawsweeper:needs-product-decision: Current issue advisory state selects this label.Label justifications:
P1: A documented MCP OAuth login/probe workflow fails against public remote servers and blocks affected users from using those authenticated MCP tools.impact:auth-provider: The report is about MCP OAuth registration, redirect metadata, stored OAuth credentials, and authenticated remote-server connection behavior.Evidence reviewed
Acceptance criteria:
What I checked:
src/agents/mcp-oauth.ts:47, 9a82b60024b5)src/agents/mcp-oauth.ts:209, 9a82b60024b5)src/agents/mcp-transport.ts:115, 9a82b60024b5)src/cli/mcp-cli.ts:1244, 9a82b60024b5)docs/cli/mcp.md. (docs/cli/mcp.md:444, 9a82b60024b5)package.json:1878, 9a82b60024b5)Likely related people:
src/agents/mcp-oauth.ts,src/cli/mcp-cli.ts,docs/cli/mcp.md)src/agents/mcp-http-fetch.ts,src/agents/mcp-transport.ts,src/agents/mcp-http-fetch.test.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.marcusbsorensen commentedon Jun 8, 2026
Update after further testing — this narrows both bugs:
Calendly now connects successfully (34 tools) after changing only the OAuth redirect from the default
http://127.0.0.1:8989/oauth/callbacktohttp://localhost:8989/oauth/callback:So:
Bug 2 is confirmed and fully isolated. The only thing blocking Calendly was the
127.0.0.1literal in the registered redirect URI (rejected by Calendly's/oauth/registerwithinvalid_client_metadata); the[object Response]handling merely hid that. Switching tolocalhostresolves it. Both sub-points still stand: 2a read/surface the error body, and 2b prefer (or fall back to)localhostfor the loopback redirect.Bug 1 appears PayPal-specific. Calendly uses streamable-http + OAuth exactly like PayPal and is now fully authorized, yet it does not trigger the
/^https\:\/\//uregex crash. So Bug 1 is not a generic streamable-http+OAuth problem — it is something in the PayPal connection/metadata path specifically. PayPal still fails atopenclaw mcp probe paypalwith the invalid-escape regex after a successful login.LiuwqGit commentedon Jun 8, 2026
Fix submitted
PR: #91451
Summary
localhostinstead of127.0.0.1for AS compatibility (Calendly DCR).Responseso MCP SDK OAuth error parsing reads JSON bodies instead of[object Response].patternvalues with redundant\:escapes are repaired before TypeBox unicode RegExp compile (PayPal probe crash).Test plan
node scripts/run-vitest.mjs src/agents/mcp-oauth.test.ts src/agents/mcp-http-fetch.test.tsnode scripts/run-vitest.mjs src/agents/agent-bundle-mcp-runtime.test.ts -t "redundant unicode-invalid"pnpm exec oxfmt --checkon changed filesfix(mcp): repair OAuth redirect, errors, and unicode schema patterns
fix(mcp): repair OAuth redirect, errors, and unicode schema patterns (#…
fix(mcp): repair OAuth redirect, errors, and unicode schema patterns (o…