Skip to content

fix: change saved MCP servers from the CLI without stopping the Gateway - #200582

Merged
obviyus merged 2 commits into
mainfrom
fix/mcp-online-config-writes
Nov 17, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/mcp-online-config-writes

Conversation

@obviyus

@obviyus obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

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 (fix: connect OAuth MCP servers from chat without stopping the Gateway #200538).
  • Focused suites, typecheck, lint, line-cap and test-line ratchets pass; the full build with declarations and the packed Bun install smoke pass.
Known local-only flake

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.

- openclaw mcp set/tools/unset, configure without --probe, and add without a probe
  route to the running Gateway via the config owner instead of refusing.
- add's default probe and configure --probe keep load, probe, and save in one offline
  custody scope (Docker launches need it) and name --no-probe when the Gateway runs.
- The Gateway clears credentials of replaced or removed OAuth servers on every
  accepted config change, including agent writes and hand edits; restarts clear nothing.
@clawsweeper

clawsweeper Bot commented Nov 17, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes agents Agent runtime and tooling size: M labels Nov 17, 2026
@clawsweeper clawsweeper Bot added the clawsweeper:intake:bug Preliminary submission classification; full source review pending. label Nov 17, 2026
- configure applies its flags to the server the write is bound to, so an edit
  that lands after the command reads config is kept, not overwritten.
- Removing an emptied override checks it still matches what was read.
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 17, 2026
@clawsweeper

clawsweeper Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR routes saved MCP server changes through the running Gateway and reconciles retired OAuth credentials when config changes are accepted.

Example: Run openclaw mcp configure docs --timeout 12 while the local Gateway runs.

  • Before: The command refuses because it requires offline state ownership.
  • After: The Gateway saves requestTimeoutMs as 12000 without requiring a restart.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The source design is coherent and regression coverage is meaningful, but required behavior and upgrade evidence remain incomplete and the package-preparation failure is unattributed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators and shell-capable agents must stop the Gateway to use specialized MCP configuration commands even though generic config writes already work online.
Reason: The maintainer-authored direction removes a documented workflow interruption while retaining the existing single-writer boundary and offline probe requirements.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it completes a useful, maintainer-approved CLI workflow while preserving Gateway-owned writes; no definite introduced code defect was found.

Priority: P2
Reviewed head: 2d0aace8440c8641ab4c747e2ffaedffeb909592

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or screenshots showing shipped CLI mutations against a running Gateway, preserved Gateway uptime, offline probe behavior, and OAuth credential retirement; redact keys, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

MCP CLI commands prepare server definitions, the existing config-owner route sends changes to the Gateway, and config acceptance applies them and retires obsolete credentials.

flowchart TD
A[MCP CLI] --> B[Config owner binding]
B --> C[Gateway config patch]
C --> D[Config acceptance]
D --> E[MCP runtime]
D --> F[OAuth credential cleanup]
A --> G[Offline probe custody]
Loading

Technical review

Best possible solution:

Use existing config-owner routing for unprobed saves and Gateway config acceptance for credential cleanup, while retaining offline probe custody.

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

Current-main source deterministically refuses saved-server CLI mutations under a running Gateway owner; no target code was executed during this review.

Is this the best way to solve the issue?

The change uses the existing config writer and credential lifecycle policy, preserves probe custody, and applies configure flags to the revision-bound definition without unnecessary new machinery.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 176f2ff9652e.

Provenance checked

  • CLI state ownership changes intended behavior with a stated reason (510255d: Prevent independent CLI credential and config writes from competing with the running Gateway.)
  • Docker pre-save probes keeps the original intent (ff2580a: Retain exclusive custody through Docker launch and cleanup; add and configure probes remain enclosed by offlineMcpAction.)
  • OAuth identity retirement keeps the original intent (6a4a546: Keep requester credentials separate and remove obsolete operator/requester state when a configured server identity is replaced or removed.)
  • Managed config acceptance keeps the original intent (45257cc: Keep config acceptance and restart settlement under the managed reloader; the added cleanup consumes its accepted source transition.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 6a4a546 adds src/agents/mcp-config-mutation.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6a4a54659329; files: src/agents/mcp-config-mutation.ts)

PR surface

Source +79, Tests +171, Docs +2. Total +252 across 9 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 6 205 126 +79
Tests 2 171 0 +171
Docs 1 10 8 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 386 134 +252

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P2: This restores useful advanced MCP CLI operations during Gateway uptime; existing config commands already provide an online workaround.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: This restores useful advanced MCP CLI operations during Gateway uptime; existing config commands already provide an online workaround.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 17, 2026, 8:02 AM ET / 13:02 UTC.

@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: docker-seed-e2e is red on main, not caused by this PR.

  • Failing job: docker-seed-e2e (CI run 44086053647, merge commit of 2d0aace8 into main 176f2ff9). scripts/check-openclaw-package-tarball.mjs --require-bundled-workspace-deps reports dist/**/…worker… imports missing dist/<dir>/runtime-worker-loader.mjs for 31 worker chunks.
  • Same failure without this PR: CI's exact steps on main at 176f2ff9 (pnpm clean:dist, pnpm build:ci-artifacts, write-unified-entry-dts.ts, package-openclaw-for-docker.mjs --skip-build, then the tarball check) fail identically: 31 imports missing … runtime-worker-loader.mjs.
  • When it started: the last docker-seed-e2e that ran on main passed (run 44073993579, 11:26Z). fix(infra): resolve source worker preload off the main thread #200565 (12:11Z) changed src/infra/runtime-worker-loader.mjs and skipped this job. Every run since that executed it fails.
  • This PR touches only the MCP CLI, MCP config mutation, and Gateway reload cleanup; no build, packaging, or worker code.

Exact-head proof: local ClawSweeper review ready on 2d0aace8; every other required check green; real-Gateway process tests and regression tests pass on this head; full build and packed Bun install smoke passed on this branch.

@obviyus
obviyus merged commit 6e38d6d into main Nov 17, 2026
129 of 132 checks passed
@obviyus
obviyus deleted the fix/mcp-online-config-writes branch November 17, 2026 13:35
@obviyus

obviyus commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 6e38d6d.

  • Bug: openclaw mcp add/set/unset/configure/tools refused while the Gateway ran, and online config changes to an OAuth server left its old sign-in attached.
  • Fix: unprobed MCP writes go through the running Gateway; probes keep offline custody; configure applies its flags to the revision-bound server; the Gateway clears replaced or removed OAuth credentials on every accepted config change.
  • Proof: real-Gateway process tests and the concurrent-edit regression (red on the prior head) pass on this head; local review ready; packed Bun smoke passed.

docker-seed-e2e was overridden: it fails on main without this change (see the override comment).

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 18, 2026
…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]>
RomneyDa added a commit that referenced this pull request Nov 19, 2026
…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)
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 docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant