Repository navigation
fix: connect OAuth MCP servers from chat without stopping the Gateway - #200538
Conversation
- mcp.authLogin gains a browserless link mode: returns the authorization URL or completes a pasted redirect. Settings sign-in stays browser-bound. - /oauth/mcp/callback completes shared link-mode attempts. - openclaw mcp login/logout and add/set/unset/configure/tools route to the running Gateway; offline paths remain for a stopped Gateway. - Accepted config changes clear replaced or removed OAuth credentials for every writer. - Owner, untainted, direct turns get <server>__connect for unauthorized shared servers; the openclaw tool accepts connectMcpServer and reports unfinished parts. - Docs describe online sign-in consistently.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs changes before merge. What this changesThis PR adds Gateway-owned OAuth sign-in links for chat and routes MCP CLI mutations through the running Gateway. Example: An owner asks a direct-chat agent to connect Linear.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Needs changes before merge - 3 items remain Keep this PR open: it provides useful, maintainer-approved online sign-in, but regresses Docker pre-save probes and leaves an existing logout contract test failing. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherAgent tools and administrative clients initiate sign-in through the existing OAuth owner; the Gateway callback saves credentials that subsequent MCP requests consume. flowchart TD
A[Owner direct chat] --> B[Agent connect tools]
C[Administrative clients] --> D[Gateway OAuth owner]
B --> D
D --> E[OAuth provider]
E --> F[Gateway callback]
F --> G[Existing credential store]
G --> B
Technical reviewBest possible solution: Keep Gateway-owned sign-in, restore ownership around pre-save probes, and update the existing logout routing test. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the offline-only refusal, consistent with the supplied before capture and published-release report; no target code was executed during this review. Is this the best way to solve the issue? Reusing the OAuth owner, callback, and credential store is appropriate; the smallest repair preserves that design while restoring probe custody and migrating the affected logout test. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against c48b8293ae67. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +651, Tests +836, Docs +10. Total +1497 across 42 files. Added test files: 3. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 17, 2026, 5:09 AM ET / 10:09 UTC. |
- Leave mcp add/set/unset/configure/tools on their offline path; online config writes move to a follow-up so add probes keep Docker custody. - A sign-in link refuses to renew a client registered for another callback and names logout or offline sign-in, leaving saved credentials untouched. - Move add/configure flag helpers to mcp-cli-server-controls.ts (line cap). - Fix consistent-return in logout, typed test snapshots, the lock payload mock, and drop the retired live logout refusal case. - Record the test-line allocation for the new regressions.
- Covers the pinned-client regression moved into the infra lane.
|
Landed in bdd7cd5.
Follow-up: routing |
…ay (#200582) Related: #200538 ## What Problem This Solves `openclaw mcp add`, `set`, `unset`, `configure` and `tools` refuse to run while the Gateway is running and tell you to stop it first. That blocks an operator, or an agent with shell access, from adding an MCP server to a live Gateway, even though the same change through `openclaw config set` already works online. ## User Impact User impact: you can add or change saved MCP servers with `openclaw mcp …` while the Gateway runs; changes apply without a restart. Commands that probe a server first (`mcp add` by default for non-OAuth servers, and `mcp configure --probe`) still need the Gateway stopped, and now say so with the next step: save without probing (`--no-probe`). OAuth servers skip the probe, so `openclaw mcp add linear --url … --auth oauth` followed by `openclaw mcp login linear` works end to end on a running Gateway. With the Gateway stopped, every command behaves as before. Replacing or removing an OAuth server now clears its old saved sign-in no matter how the change was made: CLI, agent, Settings editor, or a hand edit of `openclaw.json`. Previously only the offline CLI did this, so an online change could leave a stale account attached to a new URL. A Gateway restart alone clears nothing. ## Why This Change Was Made The running Gateway is the one config writer. The MCP CLI prepares the same normalized change it would write offline and hands it to the Gateway with the existing config-owner binding, the path `openclaw config set` already uses. Probes are different: they launch the server (Docker launches need exclusive state custody) and can refresh credentials, so the probing path keeps loading, probing and saving inside one offline custody scope, as on main. Credential cleanup moves to the owner that sees every committed change: when the Gateway accepts a new source config, it compares the previous and next MCP servers and clears OAuth credentials for servers whose definition changed or disappeared, using the existing per-server lifecycle lease and the same rule the offline CLI already applied. The offline facade skips its own cleanup when a running Gateway owns config writes, so nothing is cleared twice. No schema, protocol, or config-option change. ## Evidence - **Online routing (process test with a real Gateway owner):** `mcp set`, `configure`, `tools`, `unset` and `add --no-probe` each go through the running Gateway and the Gateway stays up; `mcp add` with its default probe refuses with "Probing a server needs the Gateway stopped" and saves nothing. On main every one of these refuses. - **Credential cleanup (same harness):** an online URL replacement, a removal, and an in-process agent write each clear the stored OAuth credentials; an unchanged OAuth identity keeps them. On main the online cases keep stale credentials. - **Probe custody regression:** a probing `mcp add` runs its probe while holding state ownership, which is what Docker launches require. This is the defect the review caught in the earlier attempt (#200538). - Focused suites, typecheck, lint, line-cap and test-line ratchets pass; the full build with declarations and the packed Bun install smoke pass. <details><summary>Known local-only flake</summary> `src/cli/mcp-cli.test.ts` "requires initialize to finish within the configured probe timeout" fails on the development host under heavy load on unmodified main as well, and passes in CI. This PR does not change that path. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…openclaw#200538) ## What Problem This Solves When you ask your agent to connect an OAuth MCP server (for example Linear), it cannot. `openclaw mcp login` refuses while the Gateway runs, Settings sign-in only works from a browser, and the agent never learns the server is waiting for sign-in. In practice the agent tells you to stop the Gateway, which takes the agent itself offline. ## User Impact User impact: say "connect Linear" in a direct chat, get a sign-in link in the same reply, approve it, and the next message uses Linear. Nothing stops or restarts. `openclaw mcp login` and `logout` now work while the Gateway runs; with the Gateway stopped they keep their existing offline flow. Saving servers from the agent already goes through the running Gateway; routing the `mcp add/set/configure` CLI commands online is a separate follow-up. Security boundary: only the owner can start a shared sign-in, only in a direct chat that has not handled untrusted content, and the link is never posted in a group. Admin Gateway clients (Control UI, local CLI) can also start it. Without `gateway.publicOrigin`, the redirect uses the Gateway's loopback address; on another device you paste the failed redirect URL back. The code is single-use and bound to the original state and PKCE verifier. Existing credentials stay until new ones are saved. ## Why This Change Was Made The running Gateway already owns MCP credentials (SQLite lease on `mcp_oauth_stores`) and already serves `/oauth/mcp/callback`. It is now also the one owner of shared sign-in: - `mcp.authLogin` gains a link mode (`{ serverName, callbackUrl? }`) beside the browser-bound Settings mode. Same method, same admin check, no new method. - `/oauth/mcp/callback` also completes shared attempts, but only ones started in link mode; Settings attempts stay bound to their browser. - The CLI routes login/logout to the running Gateway instead of refusing. - An account first signed in through a different callback (offline CLI loopback or Settings) is not silently broken: a link refuses to renew it, keeps the saved credentials, and names `openclaw mcp logout <name>` or offline sign-in. - Owner turns get `<server>__connect` for unauthorized shared servers, and the `openclaw` tool accepts `connectMcpServer` to return the link in the same reply. The tool now says which parts of a request were not done instead of reporting success. - Docs: `docs/cli/mcp/transports.md` and `docs/tools/mcp.md` no longer contradict each other. Protocol change: `mcp.authLogin` params become a union; existing callers that send `sessionId` are unchanged. No schema or stored-format change; no new config option. ## Evidence **Control UI, isolated Gateway with a real model and an OAuth MCP fixture.** Before: 2 turns, no link, the agent says the Gateway needs an offline window. After: the link arrives in turn 1 (1 min 53 s), approval shows "You're connected.", `openclaw mcp status` reports `authorized`, and the next turn calls the server's tool. The Gateway log shows only config hot reloads, no stop or restart. ### Clean comparison Before (main) and after (this branch). Same prompt, same fixture server; the user avatar is blurred.     ### Annotated comparison    **Telegram DM (real Telegram test server, real model, owner chat).** The bot replied in turn 1 with a **Connect fixture-issues** button; approval reached the Gateway callback (HTTP 200, "You're connected."); the next message produced "Connected successfully. Your assigned issues: FIX-101 … FIX-102" and the fixture recorded the tool call. When the chat was not yet the owner, the bot refused and posted no link. **Regression tests, red on main and green here:** CLI login/logout against a live Gateway (main refuses with "requires exclusive offline state ownership"), link mode and pasted-redirect completion (main rejects without `sessionId`), the owner connect tool without a sender ID, the `openclaw` tool returning the link only after the Gateway applies the committed server, and the pinned-client refusal that keeps saved credentials. New test lines are covered by `config/test-lines-allocations/200538-mcp-online-oauth-login.txt` (373): one regression per owning boundary, plus the `mcp.authLogin` harness moved to test-support to stay under the 1000-line test cap. **Upgrade from 2026.11.4:** credentials saved by the stable CLI stay `authorized` after starting this branch on the same state. **Simplification:** login/logout moved into the existing OAuth CLI module (`mcp-cli.ts` is smaller than on main), owner sign-in into its own small agent module, and add/configure flag helpers into `mcp-cli-server-controls.ts`. Production growth is the link-mode owner (`mcp-oauth-link.ts`), the connect surface, and CLI routing. <details><summary>Known gaps</summary> - The Claude CLI loopback runner has no turn-taint signal, so it gets no connect tool and no delegate link; it fails closed. Embedded and Codex runtimes are covered. - Discord was not run; Telegram was the channel proof. - Separate, pre-existing on main: with an exec or file SecretRef in config, Gateway startup on state written by 2026.11.4 fails with `required secrets are unavailable … disk I/O error`. The upgrade proof above used a config without SecretRefs. Not caused by this change. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…ay (openclaw#200582) Related: openclaw#200538 ## What Problem This Solves `openclaw mcp add`, `set`, `unset`, `configure` and `tools` refuse to run while the Gateway is running and tell you to stop it first. That blocks an operator, or an agent with shell access, from adding an MCP server to a live Gateway, even though the same change through `openclaw config set` already works online. ## User Impact User impact: you can add or change saved MCP servers with `openclaw mcp …` while the Gateway runs; changes apply without a restart. Commands that probe a server first (`mcp add` by default for non-OAuth servers, and `mcp configure --probe`) still need the Gateway stopped, and now say so with the next step: save without probing (`--no-probe`). OAuth servers skip the probe, so `openclaw mcp add linear --url … --auth oauth` followed by `openclaw mcp login linear` works end to end on a running Gateway. With the Gateway stopped, every command behaves as before. Replacing or removing an OAuth server now clears its old saved sign-in no matter how the change was made: CLI, agent, Settings editor, or a hand edit of `openclaw.json`. Previously only the offline CLI did this, so an online change could leave a stale account attached to a new URL. A Gateway restart alone clears nothing. ## Why This Change Was Made The running Gateway is the one config writer. The MCP CLI prepares the same normalized change it would write offline and hands it to the Gateway with the existing config-owner binding, the path `openclaw config set` already uses. Probes are different: they launch the server (Docker launches need exclusive state custody) and can refresh credentials, so the probing path keeps loading, probing and saving inside one offline custody scope, as on main. Credential cleanup moves to the owner that sees every committed change: when the Gateway accepts a new source config, it compares the previous and next MCP servers and clears OAuth credentials for servers whose definition changed or disappeared, using the existing per-server lifecycle lease and the same rule the offline CLI already applied. The offline facade skips its own cleanup when a running Gateway owns config writes, so nothing is cleared twice. No schema, protocol, or config-option change. ## Evidence - **Online routing (process test with a real Gateway owner):** `mcp set`, `configure`, `tools`, `unset` and `add --no-probe` each go through the running Gateway and the Gateway stays up; `mcp add` with its default probe refuses with "Probing a server needs the Gateway stopped" and saves nothing. On main every one of these refuses. - **Credential cleanup (same harness):** an online URL replacement, a removal, and an in-process agent write each clear the stored OAuth credentials; an unchanged OAuth identity keeps them. On main the online cases keep stale credentials. - **Probe custody regression:** a probing `mcp add` runs its probe while holding state ownership, which is what Docker launches require. This is the defect the review caught in the earlier attempt (openclaw#200538). - Focused suites, typecheck, lint, line-cap and test-line ratchets pass; the full build with declarations and the packed Bun install smoke pass. <details><summary>Known local-only flake</summary> `src/cli/mcp-cli.test.ts` "requires initialize to finish within the configured probe timeout" fails on the development host under heavy load on unmodified main as well, and passes in CI. This PR does not change that path. </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…ay (#200582) Related: #200538 `openclaw mcp add`, `set`, `unset`, `configure` and `tools` refuse to run while the Gateway is running and tell you to stop it first. That blocks an operator, or an agent with shell access, from adding an MCP server to a live Gateway, even though the same change through `openclaw config set` already works online. User impact: you can add or change saved MCP servers with `openclaw mcp …` while the Gateway runs; changes apply without a restart. Commands that probe a server first (`mcp add` by default for non-OAuth servers, and `mcp configure --probe`) still need the Gateway stopped, and now say so with the next step: save without probing (`--no-probe`). OAuth servers skip the probe, so `openclaw mcp add linear --url … --auth oauth` followed by `openclaw mcp login linear` works end to end on a running Gateway. With the Gateway stopped, every command behaves as before. Replacing or removing an OAuth server now clears its old saved sign-in no matter how the change was made: CLI, agent, Settings editor, or a hand edit of `openclaw.json`. Previously only the offline CLI did this, so an online change could leave a stale account attached to a new URL. A Gateway restart alone clears nothing. The running Gateway is the one config writer. The MCP CLI prepares the same normalized change it would write offline and hands it to the Gateway with the existing config-owner binding, the path `openclaw config set` already uses. Probes are different: they launch the server (Docker launches need exclusive state custody) and can refresh credentials, so the probing path keeps loading, probing and saving inside one offline custody scope, as on main. Credential cleanup moves to the owner that sees every committed change: when the Gateway accepts a new source config, it compares the previous and next MCP servers and clears OAuth credentials for servers whose definition changed or disappeared, using the existing per-server lifecycle lease and the same rule the offline CLI already applied. The offline facade skips its own cleanup when a running Gateway owns config writes, so nothing is cleared twice. No schema, protocol, or config-option change. - **Online routing (process test with a real Gateway owner):** `mcp set`, `configure`, `tools`, `unset` and `add --no-probe` each go through the running Gateway and the Gateway stays up; `mcp add` with its default probe refuses with "Probing a server needs the Gateway stopped" and saves nothing. On main every one of these refuses. - **Credential cleanup (same harness):** an online URL replacement, a removal, and an in-process agent write each clear the stored OAuth credentials; an unchanged OAuth identity keeps them. On main the online cases keep stale credentials. - **Probe custody regression:** a probing `mcp add` runs its probe while holding state ownership, which is what Docker launches require. This is the defect the review caught in the earlier attempt (#200538). - Focused suites, typecheck, lint, line-cap and test-line ratchets pass; the full build with declarations and the packed Bun install smoke pass. <details><summary>Known local-only flake</summary> `src/cli/mcp-cli.test.ts` "requires initialize to finish within the configured probe timeout" fails on the development host under heavy load on unmodified main as well, and passes in CI. This PR does not change that path. </details> Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 6e38d6d) Release adaptation: retain the release baseline inline MCP control helpers and OAuth registration; apply online routing and revision-bound configure callbacks without restoring the later extracted controls module. Companion #200538 is superseded by this complete fix. Co-authored-by: RomneyDa <[email protected]> (cherry picked from commit 4038419d371c8d583a010a152b4b957b8931c66b)
The Gateway-backed login branch added in openclaw#200538 printed the authorization URL through the redacting console logger, so a JWT-shaped client_id was masked there as well. Write it straight to stdout like the offline flow. Co-Authored-By: Claude Fable 5.2 <[email protected]>







What Problem This Solves
When you ask your agent to connect an OAuth MCP server (for example Linear), it cannot.
openclaw mcp loginrefuses while the Gateway runs, Settings sign-in only works from a browser, and the agent never learns the server is waiting for sign-in. In practice the agent tells you to stop the Gateway, which takes the agent itself offline.User Impact
User impact: say "connect Linear" in a direct chat, get a sign-in link in the same reply, approve it, and the next message uses Linear. Nothing stops or restarts.
openclaw mcp loginandlogoutnow work while the Gateway runs; with the Gateway stopped they keep their existing offline flow. Saving servers from the agent already goes through the running Gateway; routing themcp add/set/configureCLI commands online is a separate follow-up.Security boundary: only the owner can start a shared sign-in, only in a direct chat that has not handled untrusted content, and the link is never posted in a group. Admin Gateway clients (Control UI, local CLI) can also start it. Without
gateway.publicOrigin, the redirect uses the Gateway's loopback address; on another device you paste the failed redirect URL back. The code is single-use and bound to the original state and PKCE verifier. Existing credentials stay until new ones are saved.Why This Change Was Made
The running Gateway already owns MCP credentials (SQLite lease on
mcp_oauth_stores) and already serves/oauth/mcp/callback. It is now also the one owner of shared sign-in:mcp.authLogingains a link mode ({ serverName, callbackUrl? }) beside the browser-bound Settings mode. Same method, same admin check, no new method./oauth/mcp/callbackalso completes shared attempts, but only ones started in link mode; Settings attempts stay bound to their browser.openclaw mcp logout <name>or offline sign-in.<server>__connectfor unauthorized shared servers, and theopenclawtool acceptsconnectMcpServerto return the link in the same reply. The tool now says which parts of a request were not done instead of reporting success.docs/cli/mcp/transports.mdanddocs/tools/mcp.mdno longer contradict each other.Protocol change:
mcp.authLoginparams become a union; existing callers that sendsessionIdare unchanged. No schema or stored-format change; no new config option.Evidence
Control UI, isolated Gateway with a real model and an OAuth MCP fixture. Before: 2 turns, no link, the agent says the Gateway needs an offline window. After: the link arrives in turn 1 (1 min 53 s), approval shows "You're connected.",
openclaw mcp statusreportsauthorized, and the next turn calls the server's tool. The Gateway log shows only config hot reloads, no stop or restart.Clean comparison
Before (main) and after (this branch). Same prompt, same fixture server; the user avatar is blurred.
Annotated comparison
Telegram DM (real Telegram test server, real model, owner chat). The bot replied in turn 1 with a Connect fixture-issues button; approval reached the Gateway callback (HTTP 200, "You're connected."); the next message produced "Connected successfully. Your assigned issues: FIX-101 … FIX-102" and the fixture recorded the tool call. When the chat was not yet the owner, the bot refused and posted no link.
Regression tests, red on main and green here: CLI login/logout against a live Gateway (main refuses with "requires exclusive offline state ownership"), link mode and pasted-redirect completion (main rejects without
sessionId), the owner connect tool without a sender ID, theopenclawtool returning the link only after the Gateway applies the committed server, and the pinned-client refusal that keeps saved credentials. New test lines are covered byconfig/test-lines-allocations/200538-mcp-online-oauth-login.txt(373): one regression per owning boundary, plus themcp.authLoginharness moved to test-support to stay under the 1000-line test cap.Upgrade from 2026.11.4: credentials saved by the stable CLI stay
authorizedafter starting this branch on the same state.Simplification: login/logout moved into the existing OAuth CLI module (
mcp-cli.tsis smaller than on main), owner sign-in into its own small agent module, and add/configure flag helpers intomcp-cli-server-controls.ts. Production growth is the link-mode owner (mcp-oauth-link.ts), the connect surface, and CLI routing.Known gaps
required secrets are unavailable … disk I/O error. The upgrade proof above used a config without SecretRefs. Not caused by this change.