Skip to content

Preserve structured-only MCP error payloads - #1840

Open
sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-structured-error-content
Open

sylvesterkaczmarek wants to merge 1 commit into
anthropics:mainfrom
sylvesterkaczmarek:fix/mcp-structured-error-content

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

Preserve MCP error details when a CallToolResult contains structuredContent but no regular content blocks.

_convert_tool_result() currently handles isError before the existing structuredContent fallback. As a result, an MCP result such as content=[], structuredContent={...}, isError=True raises ToolError([]) and discards the only useful error payload. The tool runner then surfaces a generic Tool error instead of the structured details returned by the MCP server.

Fix

Read structuredContent before branching on isError and use it as the error fallback only when normal content is empty.

Precedence remains:

  • explicit MCP content blocks win when present;
  • otherwise structured error content is JSON-encoded and preserved in ToolError;
  • an error with neither form keeps the existing empty-error behavior;
  • successful structured-only results keep the existing JSON-string fallback.

Regression coverage

Adds focused tests covering:

  • structured-only MCP errors preserve their payload;
  • explicit error content still takes precedence over structuredContent;
  • structured-only successful results remain unchanged.

The production change is confined to the hand-maintained MCP tool-result conversion helper.

@sylvesterkaczmarek
sylvesterkaczmarek requested a review from a team as a code owner August 16, 2026 23:30
@sylvesterkaczmarek
sylvesterkaczmarek force-pushed the fix/mcp-structured-error-content branch from cbae8b4 to 31e2022 Compare September 12, 2026 21:34
Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com>
@sylvesterkaczmarek
sylvesterkaczmarek force-pushed the fix/mcp-structured-error-content branch from 31e2022 to da8b9dc Compare September 28, 2026 08:41
@sylvesterkaczmarek

Copy link
Copy Markdown
Author

Ported the structured-only MCP error fix onto current main. Explicit MCP error content still wins; when error content is empty, structuredContent is JSON-preserved in ToolError; successful structured-only results retain the existing JSON-string fallback. Validation: the full tests/lib/tools suite passes 542 tests with 1 expected xfail, Pyright reports 0 errors/warnings, Ruff is clean, and git diff --check passes. The replacement commit da8b9dc is GitHub Verified.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant