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

Preserve structured-only MCP error payloads#1840
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
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