Repository navigation
fix #174272: carry upstream MCP server instructions through the loopback bridge - #174396
wangjx-xydt wants to merge 2 commits into
Conversation
Agents served through the loopback MCP bridge received upstream tools but not the servers' instructions from the initialize result, so server-level usage guidance silently diverged from direct connections. Capture the sanitized instructions into the session catalog when connecting upstream, and aggregate them per server into the loopback initialize reply for servers that still serve at least one tool under the effective policy. Fixes openclaw#174272
|
🦞👀 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 real behavior proof before merge. What this changesThis PR captures upstream MCP instructions in the runtime catalog and adds policy-filtered aggregation to loopback initialization replies. Example: The supplied helper tests provide a legal server with instructions saying “Cite authority levels.”
Review scores
ProductKind: Bug fix · Worth it: No · Fix scope: Partial Merge readiness⛔ Blocked before merge - 4 items remain Keep open for correction: catalog capture is useful, but the loopback change misses the confirmed embedded-runtime failure and a new mock violates the CI ratchet. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherConfigured MCP servers connect natively to CLI backends, while embedded agents consume OpenClaw's MCP catalog; the loopback bridge separately exposes Gateway tools. flowchart TD
A[Configured MCP server] --> B[Native CLI MCP configuration]
B --> C[CLI agent]
A --> D[OpenClaw MCP catalog]
D --> E[Embedded tool assembly]
E --> F[Embedded model request]
G[Gateway tools] --> H[Loopback MCP bridge]
Technical reviewBest possible solution: Retain catalog capture and deliver policy-filtered server guidance through the existing embedded prompt owner. Do we have a high-confidence way to reproduce the issue? Source confirms the catalog omission and unchanged embedded consumer; the reporter's official-release request capture supports that failure, while their correction disproves the stated Claude loopback route. Is this the best way to solve the issue? Capturing instructions at the catalog owner is sound, but forwarding them through loopback does not reach the reproduced embedded model request. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cb196c383039. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +60, Tests +221. Total +281 across 8 files. Added test files: 3. View PR surface stats
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: No label 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 October 16, 2026, 12:26 PM ET / 16:26 UTC. |
…tructions coverage Import SessionMcpRuntime from the types barrel, brace the server.listen promise executor, and spread the original module in the manager-api mock.
Managed Claude turns used to connect configured MCP servers natively and received each server's initialize instructions. The bridge kept the tools but dropped the instructions. Capture them in the session MCP catalog and return them from the loopback initialize reply, ordered by server name, for servers that still have a listed tool. Catalog capture follows the approach proposed in openclaw#174396. Co-authored-by: VACInc <[email protected]>
) * fix(claude-cli): stop cache-prefix churn after child completion Ordinary local claude-cli turns now use the same exact OpenClaw-mediated tool projection as verified child completions, so a completion no longer swaps the tools-first cached prefix of a running native session. Co-authored-by: VACInc <[email protected]> * test(claude-cli): expect the mediated surface on ordinary turns Co-authored-by: VACInc <[email protected]> * test(claude-cli): select native tools in the workspace-only override case Managed Claude turns are mediated by default, so the agent workspace-only override is covered on the explicit native-selection path that still exposes native file tools. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): serve configured MCP servers through the loopback bridge Exclusive CLI runs omit native MCP servers because the CLI would call them outside OpenClaw's per-turn caps. Managed local Claude turns are now all exclusive, so configured mcp.servers disappeared from ordinary turns. Materialize the session's configured MCP tools for the run and serve them through the loopback grant. They pass the same Gateway policy pipeline and exact grant allowlist as other tools, so ordinary and completion turns list one catalog while each turn's cap still decides what is listed and callable. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): ignore request echoes when checking for orphaned tool calls Claude Code logs api-request-blob records that repeat already answered tool calls under role=assistant. Counting them made a finished turn look orphaned until the final reply was written, so a completion that resumed the parent right after a spawn reset its native session. Only user and assistant conversation records now count. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): keep skill_workshop stable on internal turns Only human turns receive personal-library authoring, so completion and other internal turns published a different skill_workshop definition and broke the native prompt cache for profiled users. Since #176587 this also affects token-authenticated clients. CLI turns without authoring now reuse the session's last human shape with an expired grant, as goal continuation already does. The definition stays identical and every call, including Workshop calls through the workspace-default wrapper, is refused, so no sandboxed internal turn gains Workshop access. Co-authored-by: VACInc <[email protected]> * fix(skill-workshop): keep workspace Workshop on internal CLI turns The stable skill_workshop shape for internal turns refused every call, including workspace Workshop calls that an unsandboxed no-grant turn may make on main. Pass the run's sandbox state to the workspace-default wrapper so the expired grant refuses only personal-library calls and sandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * fix(mcp): recheck loopback grant at configured-server I/O The loopback handler checked grant and completion lineage before executing a tool, but a configured MCP tool could still reach its server after that check, for example after waiting for a session reconnection. Carry the caller's check into MCP tools/call so it runs immediately before server I/O. Co-authored-by: VACInc <[email protected]> * fix(mcp): serve configured server instructions through the loopback Managed Claude turns used to connect configured MCP servers natively and received each server's initialize instructions. The bridge kept the tools but dropped the instructions. Capture them in the session MCP catalog and return them from the loopback initialize reply, ordered by server name, for servers that still have a listed tool. Catalog capture follows the approach proposed in #174396. Co-authored-by: VACInc <[email protected]> * fix(mcp): guard every bridged request and serve server instructions whole Resource reads, prompt fetches and paginated lists now recheck the loopback caller's grant and completion lineage at the request boundary, as tool calls already did. Configured server instructions are no longer capped at 1,200 characters. A Gateway loopback test revokes a real grant or reassigns a real completion lineage during a server-driven catalog refresh. Co-authored-by: VACInc <[email protected]> * test(gateway): prove Workshop shape and refusal on completion turns Through the real loopback, a completion turn after a human turn lists the same skill_workshop definition, refuses personal-library calls without reaching the human grant, and keeps unsandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * test(gateway): prove sandboxed completions cannot write through Workshop Sandboxed completion turns, with or without skill_workshop admitted by the sandbox tool policy, list the same Workshop surface as the human turn and refuse a workspace create before any file changes. The Gateway authority file runs in the database-worker project, which owns the main-thread shared-state broker. Drops the mock-sequenced revocation case now covered by real grant and lineage owners. Co-authored-by: VACInc <[email protected]> * test(cli-runner): drop Workshop helper cases covered by the Gateway suite Definition parity, personal refusal and workspace access are now proven through the real loopback; keep session isolation and latest-shape cases. Co-authored-by: VACInc <[email protected]> * test(gateway): wait for list_changed delivery instead of sleeping The probe follows each tools/list_changed with a ping on the same SSE stream; the client handles stream messages in order, so its ping reply proves the notification was consumed before the next call. Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: Marvinthebored <[email protected]> Co-authored-by: VACInc <[email protected]> Co-authored-by: roboclaw-bot <[email protected]>
) fix(mcp): give embedded agents the MCP server's instructions, capped per server MCP servers can publish usage guidance in their initialize result (for example "Before using lookup, always confirm the account name"). Embedded agents received the server's tools but never that guidance. The instructions read by #172026 are now also delivered to embedded agents, alongside the server's tools, in the system prompt, Tool Search and Code Mode, only for servers that still back at least one usable tool. Each server's text is capped at 2,000 characters for embedded prompts (cut at a character boundary with a truncation note), and OpenClaw prompt markers in it are neutralized. Claude CLI loopback delivery keeps the full text, as #172026 intends. This matches how Codex surfaces server instructions as the tool namespace description. Proof: built Gateway with a stdio MCP server and a recording provider. On main the provider request had the tools but not the instructions (twice). With this change the instructions are present (twice); a server with over 2,000 characters shows the capped prefix with one truncation note; a server without instructions leaves the prompt unchanged; Claude CLI loopback still gets the full text. A live gpt-5.4-mini turn passes. Supersedes #174425, #174508 and #174396. Thanks @xiaopan-xydt. Co-authored-by: Ayaan Zaidi <[email protected]>
|
Thanks @wangjx-xydt. This fixed the same gap for the Claude CLI loopback bridge, which #172026 has since covered (it serves MCP server instructions whole over loopback), and #174342 (f874f24) now delivers them to embedded agents too. Closing as superseded. Your PR is credited in the #174342 merge. |
…claw#172026) * fix(claude-cli): stop cache-prefix churn after child completion Ordinary local claude-cli turns now use the same exact OpenClaw-mediated tool projection as verified child completions, so a completion no longer swaps the tools-first cached prefix of a running native session. Co-authored-by: VACInc <[email protected]> * test(claude-cli): expect the mediated surface on ordinary turns Co-authored-by: VACInc <[email protected]> * test(claude-cli): select native tools in the workspace-only override case Managed Claude turns are mediated by default, so the agent workspace-only override is covered on the explicit native-selection path that still exposes native file tools. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): serve configured MCP servers through the loopback bridge Exclusive CLI runs omit native MCP servers because the CLI would call them outside OpenClaw's per-turn caps. Managed local Claude turns are now all exclusive, so configured mcp.servers disappeared from ordinary turns. Materialize the session's configured MCP tools for the run and serve them through the loopback grant. They pass the same Gateway policy pipeline and exact grant allowlist as other tools, so ordinary and completion turns list one catalog while each turn's cap still decides what is listed and callable. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): ignore request echoes when checking for orphaned tool calls Claude Code logs api-request-blob records that repeat already answered tool calls under role=assistant. Counting them made a finished turn look orphaned until the final reply was written, so a completion that resumed the parent right after a spawn reset its native session. Only user and assistant conversation records now count. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): keep skill_workshop stable on internal turns Only human turns receive personal-library authoring, so completion and other internal turns published a different skill_workshop definition and broke the native prompt cache for profiled users. Since openclaw#176587 this also affects token-authenticated clients. CLI turns without authoring now reuse the session's last human shape with an expired grant, as goal continuation already does. The definition stays identical and every call, including Workshop calls through the workspace-default wrapper, is refused, so no sandboxed internal turn gains Workshop access. Co-authored-by: VACInc <[email protected]> * fix(skill-workshop): keep workspace Workshop on internal CLI turns The stable skill_workshop shape for internal turns refused every call, including workspace Workshop calls that an unsandboxed no-grant turn may make on main. Pass the run's sandbox state to the workspace-default wrapper so the expired grant refuses only personal-library calls and sandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * fix(mcp): recheck loopback grant at configured-server I/O The loopback handler checked grant and completion lineage before executing a tool, but a configured MCP tool could still reach its server after that check, for example after waiting for a session reconnection. Carry the caller's check into MCP tools/call so it runs immediately before server I/O. Co-authored-by: VACInc <[email protected]> * fix(mcp): serve configured server instructions through the loopback Managed Claude turns used to connect configured MCP servers natively and received each server's initialize instructions. The bridge kept the tools but dropped the instructions. Capture them in the session MCP catalog and return them from the loopback initialize reply, ordered by server name, for servers that still have a listed tool. Catalog capture follows the approach proposed in openclaw#174396. Co-authored-by: VACInc <[email protected]> * fix(mcp): guard every bridged request and serve server instructions whole Resource reads, prompt fetches and paginated lists now recheck the loopback caller's grant and completion lineage at the request boundary, as tool calls already did. Configured server instructions are no longer capped at 1,200 characters. A Gateway loopback test revokes a real grant or reassigns a real completion lineage during a server-driven catalog refresh. Co-authored-by: VACInc <[email protected]> * test(gateway): prove Workshop shape and refusal on completion turns Through the real loopback, a completion turn after a human turn lists the same skill_workshop definition, refuses personal-library calls without reaching the human grant, and keeps unsandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * test(gateway): prove sandboxed completions cannot write through Workshop Sandboxed completion turns, with or without skill_workshop admitted by the sandbox tool policy, list the same Workshop surface as the human turn and refuse a workspace create before any file changes. The Gateway authority file runs in the database-worker project, which owns the main-thread shared-state broker. Drops the mock-sequenced revocation case now covered by real grant and lineage owners. Co-authored-by: VACInc <[email protected]> * test(cli-runner): drop Workshop helper cases covered by the Gateway suite Definition parity, personal refusal and workspace access are now proven through the real loopback; keep session isolation and latest-shape cases. Co-authored-by: VACInc <[email protected]> * test(gateway): wait for list_changed delivery instead of sleeping The probe follows each tools/list_changed with a ping on the same SSE stream; the client handles stream messages in order, so its ping reply proves the notification was consumed before the next call. Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: Marvinthebored <[email protected]> Co-authored-by: VACInc <[email protected]> Co-authored-by: roboclaw-bot <[email protected]>
…claw#174342) fix(mcp): give embedded agents the MCP server's instructions, capped per server MCP servers can publish usage guidance in their initialize result (for example "Before using lookup, always confirm the account name"). Embedded agents received the server's tools but never that guidance. The instructions read by openclaw#172026 are now also delivered to embedded agents, alongside the server's tools, in the system prompt, Tool Search and Code Mode, only for servers that still back at least one usable tool. Each server's text is capped at 2,000 characters for embedded prompts (cut at a character boundary with a truncation note), and OpenClaw prompt markers in it are neutralized. Claude CLI loopback delivery keeps the full text, as openclaw#172026 intends. This matches how Codex surfaces server instructions as the tool namespace description. Proof: built Gateway with a stdio MCP server and a recording provider. On main the provider request had the tools but not the instructions (twice). With this change the instructions are present (twice); a server with over 2,000 characters shows the capped prefix with one truncation note; a server without instructions leaves the prompt unchanged; Claude CLI loopback still gets the full text. A live gpt-5.4-mini turn passes. Supersedes openclaw#174425, openclaw#174508 and openclaw#174396. Thanks @xiaopan-xydt. Co-authored-by: Ayaan Zaidi <[email protected]>
) * fix(claude-cli): stop cache-prefix churn after child completion Ordinary local claude-cli turns now use the same exact OpenClaw-mediated tool projection as verified child completions, so a completion no longer swaps the tools-first cached prefix of a running native session. Co-authored-by: VACInc <[email protected]> * test(claude-cli): expect the mediated surface on ordinary turns Co-authored-by: VACInc <[email protected]> * test(claude-cli): select native tools in the workspace-only override case Managed Claude turns are mediated by default, so the agent workspace-only override is covered on the explicit native-selection path that still exposes native file tools. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): serve configured MCP servers through the loopback bridge Exclusive CLI runs omit native MCP servers because the CLI would call them outside OpenClaw's per-turn caps. Managed local Claude turns are now all exclusive, so configured mcp.servers disappeared from ordinary turns. Materialize the session's configured MCP tools for the run and serve them through the loopback grant. They pass the same Gateway policy pipeline and exact grant allowlist as other tools, so ordinary and completion turns list one catalog while each turn's cap still decides what is listed and callable. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): ignore request echoes when checking for orphaned tool calls Claude Code logs api-request-blob records that repeat already answered tool calls under role=assistant. Counting them made a finished turn look orphaned until the final reply was written, so a completion that resumed the parent right after a spawn reset its native session. Only user and assistant conversation records now count. Co-authored-by: VACInc <[email protected]> * fix(claude-cli): keep skill_workshop stable on internal turns Only human turns receive personal-library authoring, so completion and other internal turns published a different skill_workshop definition and broke the native prompt cache for profiled users. Since #176587 this also affects token-authenticated clients. CLI turns without authoring now reuse the session's last human shape with an expired grant, as goal continuation already does. The definition stays identical and every call, including Workshop calls through the workspace-default wrapper, is refused, so no sandboxed internal turn gains Workshop access. Co-authored-by: VACInc <[email protected]> * fix(skill-workshop): keep workspace Workshop on internal CLI turns The stable skill_workshop shape for internal turns refused every call, including workspace Workshop calls that an unsandboxed no-grant turn may make on main. Pass the run's sandbox state to the workspace-default wrapper so the expired grant refuses only personal-library calls and sandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * fix(mcp): recheck loopback grant at configured-server I/O The loopback handler checked grant and completion lineage before executing a tool, but a configured MCP tool could still reach its server after that check, for example after waiting for a session reconnection. Carry the caller's check into MCP tools/call so it runs immediately before server I/O. Co-authored-by: VACInc <[email protected]> * fix(mcp): serve configured server instructions through the loopback Managed Claude turns used to connect configured MCP servers natively and received each server's initialize instructions. The bridge kept the tools but dropped the instructions. Capture them in the session MCP catalog and return them from the loopback initialize reply, ordered by server name, for servers that still have a listed tool. Catalog capture follows the approach proposed in #174396. Co-authored-by: VACInc <[email protected]> * fix(mcp): guard every bridged request and serve server instructions whole Resource reads, prompt fetches and paginated lists now recheck the loopback caller's grant and completion lineage at the request boundary, as tool calls already did. Configured server instructions are no longer capped at 1,200 characters. A Gateway loopback test revokes a real grant or reassigns a real completion lineage during a server-driven catalog refresh. Co-authored-by: VACInc <[email protected]> * test(gateway): prove Workshop shape and refusal on completion turns Through the real loopback, a completion turn after a human turn lists the same skill_workshop definition, refuses personal-library calls without reaching the human grant, and keeps unsandboxed workspace calls. Co-authored-by: VACInc <[email protected]> * test(gateway): prove sandboxed completions cannot write through Workshop Sandboxed completion turns, with or without skill_workshop admitted by the sandbox tool policy, list the same Workshop surface as the human turn and refuse a workspace create before any file changes. The Gateway authority file runs in the database-worker project, which owns the main-thread shared-state broker. Drops the mock-sequenced revocation case now covered by real grant and lineage owners. Co-authored-by: VACInc <[email protected]> * test(cli-runner): drop Workshop helper cases covered by the Gateway suite Definition parity, personal refusal and workspace access are now proven through the real loopback; keep session isolation and latest-shape cases. Co-authored-by: VACInc <[email protected]> * test(gateway): wait for list_changed delivery instead of sleeping The probe follows each tools/list_changed with a ping on the same SSE stream; the client handles stream messages in order, so its ping reply proves the notification was consumed before the next call. Co-authored-by: VACInc <[email protected]> --------- Co-authored-by: Marvinthebored <[email protected]> Co-authored-by: VACInc <[email protected]> Co-authored-by: roboclaw-bot <[email protected]> (cherry picked from commit 77d9f42) Co-authored-by: RomneyDa <[email protected]>
Summary
instructions(theInitializeResult.instructionsusage guidance) never reaches agents served through the OpenClaw loopback MCP bridge: the client runtime never reads the field from upstream servers, and the bridge'sinitializereply has noinstructions— so bridged agents silently lose server-level guidance that directly connected agents receive (issue [Bug]: MCP server instructions are dropped for agents using the loopback MCP bridge #174272).client.getInstructions()into the session catalog (sanitized like other untrusted MCP metadata), and the loopback bridge aggregates catalog instructions into itsinitializereply, labeled per server, only for servers that still serve at least one tool under the effective policy.src/agents/agent-bundle-mcp-types.ts,src/agents/agent-bundle-mcp-runtime.ts,src/gateway/mcp-http.ts,src/gateway/mcp-http.handlers.ts, plus newsrc/gateway/mcp-http.instructions.tsand tests.instructionsfrom that one handshake instead of triggering connections ortools/listfrom the HTTP handler; servers whose tools are fully denied contribute nothing; instructions text is scrubbed by the existingsanitizeMcpMetadataText(prompt-injection patterns redacted, length cap shared with other MCP metadata).Fixes #174272
Real behavior proof
instructions, so server-level usage rules (ranking, quota, safety) silently diverged between bridged and direct connections.node:httpfixture returning a multi-paragraphinstructionsstring) handshake with the real session MCP runtime, plus the real loopbackinitializehandler and the real aggregation helper against policy-filtered tool lists.session MCP runtimestdio variant of the catalog test could not run on this machine (its process-ownership admission blocks child spawning for every such test, including pre-existing ones on pristine main); the streamable-http path above exercises the sameloadCatalogcapture code.initializereply now carries aggregated, per-server-labeled, sanitized upstream instructions, so bridged agents receive the same server-level guidance as directly connected agents.Regression Test Plan
Root Cause
loadCatalogreadgetServerCapabilities()/getServerVersion()from the upstream initialize result but nevergetInstructions(), and the loopbackinitializehandler never emitted aninstructionsfield.