Skip to content

mcp: omit structured output from error results - #1397

Merged
guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
Ilyuha888:iserror-structured-output
Oct 13, 2026
Merged

guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
Ilyuha888:iserror-structured-output

Conversation

@Ilyuha888

Copy link
Copy Markdown
Contributor

A typed tool handler that reports a tool execution error by returning a result with IsError: true and a nil error still has its Out value marshaled into structuredContent and validated against the output schema. Clients that read structuredContent get a zero value such as {"items":null} next to the error, and an output schema that rejects the zero value turns the tool error into a protocol error (validating tool output: ...).

This change skips the output step for an error result, as toolForErr already does when the handler asks for input. A handler that wants structured data on an error result can still set res.StructuredContent itself; it is passed through unchanged.

Fixes #1387

Tested with go test ./... on Go 1.27.1, darwin/arm64; the new test fails without the change.

A typed tool handler that reports a tool execution error by returning
a result with IsError set (and a nil error) still has its Out value
marshaled into structuredContent and validated against the output
schema. Skip that step for error results, as is already done when the
handler asks for input.

Fixes modelcontextprotocol#1387
@guglielmo-san
guglielmo-san merged commit f5fe54f into modelcontextprotocol:main Oct 13, 2026
9 checks passed
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.

mcp: typed tool handler adds zero structuredContent to an IsError result

2 participants