Skip to content

fix(mcp): preserve server error reasons for structured tool failures - #179345

Merged
steipete merged 2 commits into
mainfrom
fix/mcp-error-results-skip-output-schema
Oct 21, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/mcp-error-results-skip-output-schema

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #179318

What Problem This Solves

Fixes MCP tools losing the server's error reason and recovery guidance when an isError: true result includes structured error details that do not match the tool's success schema.

User Impact

Agents receive the server's error content and can follow its recovery guidance, such as selecting a conversation ID after an ambiguous-contact error.

Why This Change Was Made

The shared MCP result validator now returns immediately for explicit tool errors, matching the MCP client's success-only output-schema validation. Successful results still require valid structured content. Bundle tools, node-host calls, and native stdio continuations share this owner; MCP apps and plugin-backed tools benefit through their existing runtime paths.

The cleanup replaces the redundant missing-content return with the error return: production +4/-4 (net 0), tests +16/-0, docs +7/-0.

Evidence

  • Regression: accepts tool errors without requiring the success output schema (%j) in src/agents/mcp-tool-metadata.test.ts, covering an incompatible structured error envelope and an error without structured content. The structured-envelope case reaches the erroneous schema rejection on the base by source inspection. Existing tests retain successful-result validation coverage.
  • Changed-file oxlint and oxfmt passed; git diff --check passed. Deslop/pr-simplify completed.
  • Codex autoreview: scoped-clean through P2, with no accepted/actionable findings.
  • Exact-head PR CI passed on 3f66c754bff1a8fe900a723e386bfa59acb9ec2b: 33 jobs passed, 27 policy-selected skips, no failures or retries.
  • PR CI is the test gate for the regression, existing MCP coverage, type checking, and repository checks. Tests and typechecks were intentionally not run locally; live proof was intentionally skipped per maintainer policy.

@clawsweeper

clawsweeper Bot commented Oct 21, 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.

@steipete
steipete marked this pull request as ready for review October 21, 2026 09:48
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T09:55:19.365771Z 3f66c75 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: XS labels Oct 21, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR bypasses success-schema validation for explicit MCP tool errors so their explanations and recovery guidance reach the agent.

Example: get_conversation declares an output schema requiring messages but returns isError: true, structuredContent: { error: "ambiguous contact" }, and instructions to call list_conversations.

  • Before: OpenClaw throws a schema mismatch and hides the server's recovery instructions.
  • After: The error result reaches the existing projector, preserving its structured details and recovery instructions.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is narrow and source-supported, with useful regression coverage; the available evidence does not establish an executed end-to-end result.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied evidence comprises source inspection, focused unit regression code, static checks, and pending PR CI rather than a recorded runtime demonstration.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Agents receive a generic schema mismatch instead of an MCP server's explanation and recovery instructions.
Reason: The maintainer-authored direction restores the existing error-result contract with a minimal shared-owner change and no new settings or public API.

Merge readiness

✅ Ready for maintainer review

Keep open: this PR provides a focused repair for a confirmed MCP result-validation bug still present on current main, with no actionable patch defects found.

Priority: P2
Reviewed head: 3f66c754bff1a8fe900a723e386bfa59acb9ec2b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No recorded shipped-entry-point error-envelope scenario or executed base-red/head-green regression is supplied.
Agent review details

How this fits together

The shared MCP catalog owner captures result validators used by Gateway bundle calls, node-host calls, and native stdio continuations; validated results then enter model-facing projection.

flowchart LR
  A[MCP server result] --> B[Transport result parsing]
  B --> C[Shared result validator]
  C --> D[Explicit tool error]
  C --> E[Successful result schema validation]
  D --> F[Existing result projector]
  E --> F
  F --> G[Agent receives result]
Loading

Technical review

Best possible solution:

Retain the shared-owner error bypass and existing success validation, allowing this focused repair to proceed through its normal CI gates.

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

Current-main and released source show that an explicit error containing structured content incompatible with the success schema throws before projection; the linked report supplies an affected server, release, and concrete trigger.

Is this the best way to solve the issue?

The bypass is the smallest complete fix: it uses the existing validator owner, matches the pinned client's contract, preserves successful-result checks, and requires no caller-specific workaround.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 407c8cd adds src/agents/mcp-tool-metadata.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 407c8cdb3440; files: src/agents/mcp-tool-metadata.ts)

PR surface

Source 0, Tests +16, Docs +7. Total +23 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 4 4 0
Tests 1 16 0 +16
Docs 1 7 0 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 27 4 +23

Root-cause cluster

Relationship: same_root_cause
Canonical: #179318
Summary: This PR directly repairs the shared-validator defect documented by the linked issue.

Members:

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

Labels

Label changes:

  • add P2: Structured MCP error envelopes can hide actionable recovery guidance, with a limited blast radius and a focused shared-owner repair.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Structured MCP error envelopes can hide actionable recovery guidance, with a limited blast radius and a focused shared-owner repair.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 October 21, 2026, 6:04 AM ET / 10:04 UTC.

@steipete

Copy link
Copy Markdown
Contributor Author

Exact-head PR CI has passed on 3f66c754bff1a8fe900a723e386bfa59acb9ec2b: 33 successful jobs, no failures or retries.

Per the maintainer proof policy for this repair, PR CI is the proof; local validation is limited to changed-file lint/format. Live entry-point proof and local base-red/head-green execution were intentionally skipped, as documented in the Evidence section. The proof-only note does not require additional runs for this work order. ClawSweeper reported no actionable code findings.

@steipete
steipete merged commit 52ec28b into main Oct 21, 2026
199 of 203 checks passed
@steipete
steipete deleted the fix/mcp-error-results-skip-output-schema branch October 21, 2026 10:19
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. docs Improvements or additions to documentation size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tool results with isError: true are validated against outputSchema, hiding the server's error reason

1 participant