Skip to content

fix: openclaw mcp cannot authorize plugin-contributed MCP servers - #167090

Open
xydigitLybnnnn wants to merge 4 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/165951-mcp-plugin-server-oauth
Open

xydigitLybnnnn wants to merge 4 commits into
openclaw:mainfrom
xydigitLybnnnn:fix/165951-mcp-plugin-server-oauth

Conversation

@xydigitLybnnnn

@xydigitLybnnnn xydigitLybnnnn commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Closes #165951

What Problem This Solves

Fixes: openclaw mcp login <name> fails with "No MCP server named ..." when the MCP server is contributed by an enabled plugin — for example the official @openclaw/gitlab plugin's gitlab server — instead of being saved under mcp.servers in openclaw.json.

User Impact

User impact: after installing a plugin that declares an MCP server, openclaw mcp list, status, doctor, and probe now show that server, and openclaw mcp login <name> completes the OAuth flow the agent runtime already requires. Previously the server was invisible to the CLI even though the Control UI instructed the operator to run exactly that command.

No breaking changes. Write commands (add, set, configure, tools, unset) still read and write only mcp.servers.

Why This Change Was Made

Agent runtimes merge MCP servers from two sources: servers declared by enabled plugins, overlaid by the operator's mcp.servers config. The CLI read only mcp.servers, so plugin-declared servers were unreachable and could never be authorized.

Read and OAuth commands (list, show, status, doctor, probe, login, logout) now resolve the same effective set as the runtime — plugin declarations first, then mcp.servers overrides — while write commands keep operating on the config-only registry they own. Unlike the runtime merge, disabled config entries stay visible so status and doctor can still report them. Credentials keep using the existing operatorMcpOAuthIdentity(name, url) key, so a CLI login is picked up by the runtime with no extra wiring.

Review follow-ups (second commit)

  • Workspace scope is no longer invented. When the control plane resolves no workspace owner (multiple explicit agents without a system owner), resolvePluginControlPlaneWorkspace intentionally returns an omitted scope. The CLI now preserves that omission instead of falling back to process.cwd(), so only shared plugin inventory is used, as the existing contract requires. loadEnabledBundleMcpConfig / loadEnabledBundleConfig accept an omitted workspaceDir.
  • Plugin launch ownership is preserved in probes. probe and doctor --probe no longer copy plugin-declared servers into mcp.servers; doing so relabelled them as operator-configured and dropped prepareDataDirsByServer, so an Agent-bundle stdio server declaring cwd: "${PLUGIN_DATA}" failed to launch. They now receive the resolved plugin inventory and scope the runtime with includeServerNames, so plugin stdio servers keep their launch-directory ownership.

Docs updated to state the read/OAuth vs. write scope.

Evidence

Real behavior proof: shipped CLI, before vs. after

Both runs use the same fixture: a local, loopback-only OAuth 2.1 + MCP server (synthetic tokens and client id; no external endpoints) plus a temp $HOME containing one installed bundle plugin that declares { "type": "http", "url": "http://127.0.0.1:8799/mcp", "auth": "oauth" }. The CLI is the shipped entry point (node scripts/run-node.mjs, the same one pnpm openclaw runs).

  • Base: upstream/main @ 54bd6ecee18
  • After: this branch @ fd3b32c1ed0

Before — the plugin server is invisible, so login is rejected:

$ openclaw mcp list --json
{}
exit=0

$ openclaw mcp login gitlab
No MCP server named "gitlab" in <temp-home>/.openclaw/openclaw.json. Run openclaw mcp list to see configured servers.
exit=1

After — discover, authorize, then reuse the credential from the runtime:

$ openclaw mcp list --json
{
  "gitlab": {
    "url": "http://127.0.0.1:8799/mcp",
    "auth": "oauth",
    "transport": "streamable-http"
  }
}
exit=0

$ openclaw mcp login gitlab
Open this URL to authorize "gitlab":
http://127.0.0.1:8799/authorize?response_type=code&client_id=mock-client-id&code_challenge=<redacted-pkce>&code_challenge_method=S256&redirect_uri=http%3A%2F%2F127.0.0.1%3A8989%2Foauth%2Fcallback&state=<redacted-state>&resource=http%3A%2F%2F127.0.0.1%3A8799%2Fmcp
Waiting for the browser to return to OpenClaw...
MCP OAuth credentials saved for "gitlab".

$ openclaw mcp status --verbose
- gitlab: streamable-http oauth authorized
  oauth: authorized
exit=0

$ openclaw mcp probe gitlab --json
{
  "generatedAt": "2026-10-08T12:26:29.344Z",
  "servers": {
    "gitlab": {
      "launch": "http://127.0.0.1:8799/mcp",
      "tools": 1,
      "codexApprovalMode": "auto",
      "approvalHint": "tools have no safety annotations; calls require approval in prompting session postures",
      "requestTimeoutMs": 60000
    }
  },
  "tools": [ "gitlab__proof_echo" ],
  "diagnostics": []
}
exit=0

The authorization leg is a genuine loopback redirect: the fixture performs dynamic client registration, redirects to http://127.0.0.1:8989/oauth/callback with an authorization code, and exchanges that code at its token endpoint. The final probe is the agent runtime's own MCP transport authenticating with the stored credential — it reaches the fixture and lists proof_echo, so credential reuse is demonstrated end to end rather than mocked.

Checks

  • pnpm tsgo:core — pass.
  • node scripts/run-oxlint.mjs --tsconfig tsconfig.core.json <changed files> — 0 warnings, 0 errors.
  • oxfmt --check and git diff --check — clean.
  • pnpm test src/cli/mcp-cli.plugin-servers.test.ts src/cli/mcp-cli.test.ts — the new regression test passes; mcp-cli.test.ts is 30 passed / 1 failed, and the single failure (requires initialize to finish within the configured probe timeout before saving) is a timing-sensitive test that also fails on a clean upstream/main checkout in this environment.
Focused test output
 ✓ src/cli/mcp-cli.plugin-servers.test.ts > mcp cli plugin-contributed servers > lists and authorizes MCP servers contributed by enabled plugins
 FAIL src/cli/mcp-cli.test.ts > mcp cli > requires initialize to finish within the configured probe timeout before saving
 Test Files  1 failed | 1 passed (2)
      Tests  1 failed | 30 passed (31)

AI involvement disclosure

Implemented by an AI agent with human direction and review. A human chose the approach (resolve the runtime's effective server set for read/OAuth commands rather than syncing plugin servers back into config) and reviewed the result; reproduction, coding, and verification were executed by the agent.

Rollback plan

Revert these commits. The change only alters how the CLI resolves and probes the MCP server set; no config, schema, or persisted state is migrated, so a revert restores the previous behavior immediately with no data cleanup.

Read and OAuth `openclaw mcp` commands listed only `mcp.servers` from
config, so MCP servers declared by enabled plugins (for example the
official GitLab plugin's `gitlab` server) were invisible to the CLI and
could not be authorized, even though agent runtimes already load them.

Resolve the same effective server set as the runtime for `list`, `show`,
`status`, `doctor`, `probe`, `login`, and `logout`: plugin declarations
overlaid by `mcp.servers` overrides. Write commands keep operating on the
config-only registry; disabled config entries stay visible so `status`
and `doctor` can still report them.
@clawsweeper

clawsweeper Bot commented Oct 8, 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 cli CLI command changes size: S labels Oct 8, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

The MCP CLI includes enabled plugins’ servers in read, diagnostic, and OAuth commands while keeping configuration writes separate.

Example: An enabled GitLab plugin declares the OAuth MCP server gitlab.

  • Before: openclaw mcp login gitlab reports that no server named gitlab exists.
  • After: The CLI discovers gitlab, completes OAuth login, and reuses the credential when probing its tools.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong supplied CLI proof supports a useful fix, but the retained Doctor defect prevents a correctness pass.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The supplied shipped-CLI trace at fd3b32c exercises a temporary installed plugin against a real loopback OAuth/MCP fixture, completes callback and token exchange, and demonstrates credential reuse through the production runtime probe; subsequent extraction and base integration preserve that central path.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: The runtime tells operators to authorize a plugin MCP server through a CLI command that cannot find it.
Reason: The change repairs an established integration contract using existing plugin discovery, transport, and OAuth owners.

Merge readiness

⛔ Needs changes before merge - 1 item remains

This PR fixes a real CLI discovery and authorization gap that remains on current main, but the previously reported Doctor preflight defect still blocks merge.

Priority: P2
Reviewed head: d024c86ea2412734f172da06f8ed9f869a2504d7

Before merge

  • Allow launch-owned data directories through Doctor preflight (P2) - This expands Doctor to enabled plugin declarations, including a valid Agent bundle with command "node" and cwd "${PLUGIN_DATA}". Before its first launch, that directory intentionally does not exist: bundle inspection records prepareDataDirsByServer, and the stdio transport creates it during start. collectMcpDoctorIssues still reports "stdio cwd does not exist" at lines 386–387, then skips probing because an error exists. Consequently both doctor and doctor --probe reject a valid server before preparation can run. Carry the existing ownership metadata into static validation while retaining errors for missing operator-owned directories. This retains the prior finding.

Findings

  • [P2] Allow launch-owned data directories through Doctor preflight — src/cli/mcp-cli.ts:851

Tests

  • Missing end-to-end proof: The supplied HTTP OAuth proof does not exercise first-launch Agent-bundle Doctor, and a base-failing run of the added regression test is not shown.
Agent review details

How this fits together

Plugin manifests and operator configuration supply MCP server definitions; the CLI resolves them for inspection, transport probes, and OAuth credential management.

flowchart LR
  A[Enabled plugin manifests] --> C[Effective MCP inventory]
  B[Operator configuration] --> C
  C --> D[CLI inspection and Doctor]
  C --> E[OAuth login]
  E --> F[Credential store]
  C --> G[MCP runtime probes]
  F --> G
Loading

Technical review

Best possible solution:

Carry existing plugin data-directory ownership into Doctor’s static validation while preserving errors for missing operator-owned directories.

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

Current-main source confirms the config-only CLI lookup, and the supplied before/after CLI trace demonstrates the reported failure; this read-only review executed no target code.

Is this the best way to solve the issue?

Resolving plugin declarations through existing inventory owners is appropriate, but Doctor must consume their launch-directory ownership before applying its existing cwd validation.

Full review comments:

  • [P2] Allow launch-owned data directories through Doctor preflight — src/cli/mcp-cli.ts:851
    This expands Doctor to enabled plugin declarations, including a valid Agent bundle with command "node" and cwd "${PLUGIN_DATA}". Before its first launch, that directory intentionally does not exist: bundle inspection records prepareDataDirsByServer, and the stdio transport creates it during start. collectMcpDoctorIssues still reports "stdio cwd does not exist" at lines 386–387, then skips probing because an error exists. Consequently both doctor and doctor --probe reject a valid server before preparation can run. Carry the existing ownership metadata into static validation while retaining errors for missing operator-owned directories. This retains the prior finding.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/cli/mcp-cli.plugin-servers.test.ts src/cli/mcp-cli.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • git diff --check
  • Exercise shipped CLI Doctor and Doctor --probe against an isolated Agent bundle with cwd "${PLUGIN_DATA}" before the directory exists; static inspection must leave it absent and probing must launch successfully.
  • Verify a missing operator-owned cwd remains an error and the focused regression fails on the reviewed head.

What I checked:

  • Current main still has the central defect: At the fetched main revision, list, status, login, and logout still use loadMcpConfig without loading plugin-contributed servers. (src/cli/mcp-cli.ts:1228, f443e5272fa6)
  • Introduced effective inventory: The new loader uses existing plugin inventory and activation owners, preserves omitted workspace scope, and overlays operator definitions by server name. (src/cli/mcp-cli.plugin-servers.ts:43, d024c86ea241)
  • Doctor rejects launch-owned directories: Doctor now includes plugin servers, but its existing cwd check reports an error for a missing plugin data directory and prevents probe execution. (src/cli/mcp-cli.ts:851, d024c86ea241)
  • Directory creation belongs to transport launch: Bundle inspection records prepareDataDirsByServer without creating the directory; the real stdio transport creates prepareDataDir before spawning the server. (src/agents/mcp-stdio-transport.ts:77, d024c86ea241)
  • Existing contract and provenance: The merged Agent Plugins implementation explicitly made PLUGIN_DATA creation a launch responsibility; its existing bundle test asserts that inspection leaves the directory absent. feat(plugins): support the Agent Plugins bundle format #120115. (src/plugins/bundle-mcp.test.ts:452, f4387b7a5eff)
  • Supplied shipped-entry-point proof: The PR body records before/after CLI output using a real loopback OAuth and MCP fixture: plugin discovery, browser callback, token exchange, authorized status, and a runtime probe returning gitlab__proof_echo. (fd3b32c1ed09)

Likely related people:

  • Peter Steinberger: Raw commit f4387b7 adds src/plugins/bundle-mcp.ts:460 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f4387b7a5eff; files: src/plugins/bundle-mcp.ts)
  • Jason (Json): Raw commit aee4670 adds src/plugins/bundle-mcp.ts:238 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: aee46707ba10; files: src/plugins/bundle-mcp.ts)
  • Patrick Erichsen: Raw commit 62d0c5f adds src/plugins/bundle-mcp.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 62d0c5f3b66c; files: src/plugins/bundle-mcp.ts)

PR surface

Source +121, Tests +81, Docs 0. Total +202 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 216 95 +121
Tests 3 85 4 +81
Docs 2 9 9 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 310 108 +202

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #165951
Summary: The canonical issue describes the same config-only CLI lookup; another open PR attempts the same repair but has its own unresolved compatibility defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The fix restores plugin MCP authorization, with a bounded Doctor defect remaining for first-launch stdio servers.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-08T09:35:20.492Z sha ec174aa :: needs real behavior proof before merge. :: [P2] Honor intentional omission of workspace discovery | [P2] Preserve plugin launch metadata when probing plugin servers
  • reviewed 2026-10-08T12:39:25.400Z sha fd3b32c :: needs changes before merge. :: [P2] Allow launch-owned data directories through Doctor preflight
  • reviewed 2026-10-08T12:47:43.988Z sha fd3b32c :: needs changes before merge. :: [P2] Allow launch-owned data directories through Doctor preflight
  • reviewed 2026-10-13T07:47:27.875Z sha 9bf1260 :: needs changes before merge. :: [P2] Allow launch-owned data directories through Doctor preflight

Reviewed October 13, 2026, 10:18 AM ET / 14:18 UTC (Revision 5).

Review follow-up for the plugin-contributed MCP server fix:

- Do not invent a working directory when the control plane deliberately
  resolves no workspace owner (multiple explicit agents, no system owner).
  Pass the omitted scope through so shared plugin inventory is used, as the
  existing workspace-resolution contract requires.
- Probe and doctor runtimes no longer copy plugin-declared servers into
  `mcp.servers`, which relabelled them as operator-configured and dropped
  the plugin's `PLUGIN_DATA` launch-directory ownership. They now receive
  the resolved plugin inventory and scope the runtime with
  `includeServerNames`, so plugin stdio servers still get their launch
  directories prepared.
@xydigitLybnnnn

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 8, 2026
The line-cap ratchet rejected src/cli/mcp-cli.ts growth (over-cap files may
not gain lines). Move the plugin-aware effective-config loader and the
probe/doctor runtime helpers into mcp-cli.plugin-servers.ts so the command
module shrinks back below its inherited allowance; no behavior or coverage
changes.
Resolve conflicts with upstream's mcp CLI refactor: keep the new
offlineMcpAction state-owner wrappers and the extracted mcp-cli-oauth
module, and adapt them to the plugin-aware effective server view so
probe, doctor, login, and logout still reach plugin-contributed servers.

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

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M 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.

[Bug]: Official @openclaw/gitlab plugin declares an MCP server that's invisible to openclaw mcp CLI, blocking OAuth authorization

1 participant