Skip to content

fix(mcp): surface resolved tool failures to clients - #126472

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa24-mcp-tool-errors
Aug 19, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa24-mcp-tool-errors

Conversation

@steipete

@steipete steipete commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where MCP clients could receive a resolved OpenClaw tool failure as an ordinary successful tool result. Plugin tools, built-in OpenClaw tools, and Codex supervision tools share this server path, so a failed or blocked tool could be shown to the calling agent without MCP's failure signal.

Why This Change Was Made

The shared MCP handler now projects OpenClaw's canonical resolved tool-result failure classification into MCP's isError: true field while preserving the original result content. Successful results remain unchanged, including the intentional contract that a completed shell result with a nonzero exit code is not automatically a tool failure.

This reuses the existing isToolResultError owner instead of introducing a second MCP-specific classifier.

User Impact

MCP clients can now distinguish resolved tool failures from successful tool results and let the agent respond or self-correct appropriately. There is no configuration, protocol-version, storage, or migration change.

Evidence

Exact PR head: 38f5444305723e2058b8958339bce17c314ba1ad

Exact-head CI: run 32313158695 is green, including openclaw/ci-gate: https://github.com/openclaw/openclaw/actions/runs/32313158695

  • Pre-fix regression proof: the new resolved-failure cases produced five expected failures because isError was absent.
  • node scripts/run-vitest.mjs src/mcp/plugin-tools-serve.test.ts src/mcp/plugin-tools-mcp-client.test.ts — 21/21 passed on the exact head.
  • node scripts/run-vitest.mjs src/mcp — 66/66 passed on the exact head, covering all current MCP server surfaces after rebasing onto origin/main.
  • The linked @modelcontextprotocol/sdk in-memory client/server test proves the error bit survives real MCP framing while result content remains intact.
  • node scripts/check-changed.mjs -- src/mcp/plugin-tools-handlers.ts src/mcp/plugin-tools-mcp-client.test.ts src/mcp/plugin-tools-serve.test.ts — passed, including core/core-test types, targeted lint, boundary guards, dead-export checks, and import-cycle architecture.
  • ./node_modules/.bin/oxfmt --check src/mcp/plugin-tools-handlers.ts src/mcp/plugin-tools-mcp-client.test.ts src/mcp/plugin-tools-serve.test.ts — passed.
  • git diff --check origin/main...HEAD — passed.
  • Fresh Codex autoreview: clean, no accepted/actionable findings; correctness confidence 0.99.
  • Production LOC: +3/-0. Tests: +61/-0. The production growth is the single canonical import, classification, and conditional MCP projection needed to preserve the existing tool-result contract at the shared framing boundary.
  • External live proof is not needed: this is a deterministic local protocol-framing defect with no provider, network, credential, channel, or platform dependency.

AI-assisted: yes. I reviewed the complete handler, its three server callers, adjacent tests, the MCP SDK contract, and the Codex MCP client behavior, and I understand the change.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 19, 2026 23:25
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Aug 19, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 7:30 PM ET / 23:30 UTC.

ClawSweeper review

What this changes

Projects OpenClaw’s canonical resolved tool-failure classification into the MCP isError result field while preserving the returned tool content.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep this maintainer-labeled PR open: current main still omits the MCP failure signal for resolved tool failures, while the proposed shared-boundary projection matches the existing canonical classifier and has no blocking defect found.

Priority: P2
Reviewed head: 38f5444305723e2058b8958339bce17c314ba1ad

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused reuse of the canonical classifier with direct handler and MCP-client regression coverage.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored PR is not subject to the external contributor proof gate; its MCP SDK in-memory client/server test is useful supplemental protocol evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This maintainer-authored PR is not subject to the external contributor proof gate; its MCP SDK in-memory client/server test is useful supplemental protocol evidence.
Evidence reviewed 6 items Current-main gap: Current main serializes a resolved tool result’s content but does not project the canonical failure state into isError; unknown and thrown errors already set that field.
Canonical owner reuse: The existing classifier defines failed, blocked, timeout, explicit-failure, and completed-process semantics; the patch calls it rather than recreating MCP-specific policy.
Shared protocol boundary: Every MCP server created through this entry point delegates tool calls to the shared handler, including the plugin, OpenClaw, and Codex-supervision server constructors.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/mcp/plugin-tools-mcp-client.test.ts

Result: FAIL (partial) — step 2 expect_output delivers resolved tool failures as MCP errors: expected terminal output was not visible within 30 seconds: "delivers resolved tool failures as MCP errors"

node scripts/run-vitest.mjs src/mcp/plugin-tools-mcp-client.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126472-RWANMJ/target$ node scripts/run-vitest.mjs src/mcp/plugin-tools-mcp-client.test.ts
node scripts/run-vitest.mjs src/mcp/plugin-tools-mcp-client.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126472-RWANMJ/target

 ✓  unit  src/mcp/plugin-tools-mcp-client.test.ts (2 tests) 50ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  23:31:18
   Duration  11.24s (transform 8.88s, setup 1.06s, import 9.78s, tests 50ms, environment 0ms)

[test] passed 1 Vitest shard in 21.86s
runner@runnervm76f27:/tmp/clawsweeper-live-proof-126472-RWANMJ/target$ node scripts/run-vitest.mjs src/mcp/plugin-tools-mcp-client.test.ts
[test] starting test/vitest/vitest.unit.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126472-RWANMJ/target
































Assertions:

  • FAIL expect_output: delivers resolved tool failures as MCP errors

How this fits together

OpenClaw’s MCP servers expose registered tools to MCP clients. Their shared handler executes a tool, converts its content into MCP blocks, and returns a protocol result that clients use to distinguish success from failure.

flowchart LR
  A[MCP client] --> B[MCP server]
  B --> C[Shared tool handler]
  C --> D[OpenClaw tool]
  D --> E[Canonical failure classifier]
  E --> F[MCP result]
  F --> G[Client recovery]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is behind current main and required exact-head checks were still running; refresh against current main and revalidate before merge.
  • Complete next step (P2) - No repair is indicated; retain this maintainer-labeled PR for the normal refreshed-head CI and merge review.
Agent review details

Security

None.

PR surface

Source +3, Tests +61. Total +64 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 0 +3
Tests 2 61 0 +61
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 64 0 +64

Review metrics

Metric Value Why it matters
Production versus test delta production +3, tests +61 The small production addition reuses the existing classifier; the test growth covers both classifications and MCP client framing.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep failure policy in isToolResultError and merge this shared MCP projection once the refreshed head has green exact-head validation.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep failure policy in isToolResultError and merge this shared MCP projection once the refreshed head has green exact-head validation.

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

Yes: current main’s shared handler returns resolved failed results without isError, while the canonical classifier already identifies those results as failures.

Is this the best way to solve the issue?

Yes: projecting the existing canonical classification at the one shared MCP framing boundary avoids duplicate policy and covers all MCP server callers.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 1762f43a34c5.

Labels

Label changes:

  • add P2: This is a bounded client-visible protocol correctness fix with no demonstrated data-loss, security, or availability impact.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external contributor proof gate; its MCP SDK in-memory client/server test is useful supplemental protocol evidence.

Label justifications:

  • P2: This is a bounded client-visible protocol correctness fix with no demonstrated data-loss, security, or availability impact.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This maintainer-authored PR is not subject to the external contributor proof gate; its MCP SDK in-memory client/server test is useful supplemental protocol evidence.

Evidence

What I checked:

  • Current-main gap: Current main serializes a resolved tool result’s content but does not project the canonical failure state into isError; unknown and thrown errors already set that field. (src/mcp/plugin-tools-handlers.ts:106, 1762f43a34c5)
  • Canonical owner reuse: The existing classifier defines failed, blocked, timeout, explicit-failure, and completed-process semantics; the patch calls it rather than recreating MCP-specific policy. (src/agents/tool-result-error.ts:86, 38f544430572)
  • Shared protocol boundary: Every MCP server created through this entry point delegates tool calls to the shared handler, including the plugin, OpenClaw, and Codex-supervision server constructors. (src/mcp/tools-stdio-server.ts:11, 38f544430572)
  • Regression coverage: The added table protects the canonical result classifications, and the added MCP SDK client/server test verifies that the error bit and original content reach a client. (src/mcp/plugin-tools-mcp-client.test.ts:63, 38f544430572)
  • Feature provenance: Commit 3415519 introduced both the handler and canonical classifier; blame of the pre-patch handler attributes the omitted resolved-result projection to that commit. (src/mcp/plugin-tools-handlers.ts:106, 341551937ef0)
  • Release status: The PR head is not contained in any local release tag, including the supplied latest release, so this remains an unshipped fix. (38f544430572)

Likely related people:

  • steipete: Introduced the shared MCP handler and canonical tool-result classifier in the immediately preceding feature commit, which contains the pre-patch omission. (role: feature introducer and recent area contributor; confidence: high; commits: 341551937ef0, 38f544430572; files: src/mcp/plugin-tools-handlers.ts, src/agents/tool-result-error.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch against current main and confirm the exact refreshed head’s required checks are green.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@steipete

Copy link
Copy Markdown
Contributor Author

Land-ready proof for 38f5444305723e2058b8958339bce17c314ba1ad:

  • Root cause: the shared MCP handler preserved resolved tool content but discarded OpenClaw's canonical resolved failure classification, so MCP clients received an ordinary success result.
  • Architectural owner and fix: src/mcp/plugin-tools-handlers.ts now reuses isToolResultError and projects only canonical failures as isError: true. No old or parallel path was added; plugin, built-in OpenClaw, and Codex-supervision MCP servers all inherit the same shared fix.
  • Focused proof: node scripts/run-vitest.mjs src/mcp/plugin-tools-serve.test.ts src/mcp/plugin-tools-mcp-client.test.ts — 21/21 passed.
  • Shared-server proof: node scripts/run-vitest.mjs src/mcp — 66/66 passed on the current exact head.
  • Changed gates: node scripts/check-changed.mjs -- src/mcp/plugin-tools-handlers.ts src/mcp/plugin-tools-mcp-client.test.ts src/mcp/plugin-tools-serve.test.ts — passed, including core/core-test types, targeted lint, boundary/dead-export guards, and import-cycle architecture.
  • Formatting/diff: ./node_modules/.bin/oxfmt --check src/mcp/plugin-tools-handlers.ts src/mcp/plugin-tools-mcp-client.test.ts src/mcp/plugin-tools-serve.test.ts and git diff --check origin/main...HEAD — passed.
  • Independent review: .agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output — clean, no accepted/actionable findings.
  • Exact-head CI: run 32313158695 is green, including openclaw/ci-gate: https://github.com/openclaw/openclaw/actions/runs/32313158695
  • LOC: production +3/-0; tests +61/-0. The production growth is the canonical import, classification, and conditional MCP projection required at the shared framing boundary.
  • ClawSweeper disposition: exact-head review found no actionable findings and requires normal maintainer review. Its only Rank-up move was another current-main refresh. Skipped: the branch was refreshed once before publication as requested, exact-head CI is green, current main advanced afterward without a reported conflict, and the repository-native prepare step owns the strict current-main test-merge gate. No behavior changed after review, so no re-review was requested.
  • External-live gap: none required for this bounded deterministic protocol-framing defect. The real MCP SDK linked client/server test exercises framing without any provider, channel, credential, network, or platform dependency.

Best-fix verdict: this is the canonical shared-boundary repair. An MCP-local status list would duplicate policy, and changing each server caller separately would leave divergent sibling behavior.

@steipete
steipete merged commit c5fd625 into main Aug 19, 2026
232 checks passed
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@steipete
steipete deleted the codex/autoqa24-mcp-tool-errors branch August 19, 2026 23:44
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant