Skip to content

[IDEA-386673] MCP structured output error responses incorrectly validated against success schema#3439

Open
fvoidCN wants to merge 1 commit intoJetBrains:masterfrom
fvoidCN:fix/mcp-error-structured-content
Open

[IDEA-386673] MCP structured output error responses incorrectly validated against success schema#3439
fvoidCN wants to merge 1 commit intoJetBrains:masterfrom
fvoidCN:fix/mcp-error-structured-content

Conversation

@fvoidCN
Copy link

@fvoidCN fvoidCN commented Feb 25, 2026

When a tool with a typed return value (structured output enabled) throws a
McpExpectedError, the error's mcpErrorStructureContent is forwarded into
CallToolResult. The MCP SDK then validates this payload against the tool's
success output schema, causing -32602 even though the response is an error.

For example, noSuitableProjectError() returns {projects:[...]} as structured
content, but a tool returning BreakpointListResult expects {breakpoints, total}.
The same issue affects any typed tool (e.g. get_all_open_file_paths) when
project resolution fails.

Fix: only populate structuredContent when isError=false, so error responses
are never validated against the success output schema.

@fvoidCN
Copy link
Author

fvoidCN commented Feb 25, 2026

before:

Screenshot 2026-02-25 at 2 07 45 PM

after:

Screenshot 2026-02-25 at 2 09 13 PM

@fvoidCN fvoidCN force-pushed the fix/mcp-error-structured-content branch from 822dee9 to 8b03c9d Compare March 4, 2026 12:31
@fvoidCN fvoidCN changed the title [mcp] Fix: skip structuredContent in error responses to prevent schema validation failure IDEA-386673 MCP structured output error responses incorrectly validated against success schema Mar 4, 2026
@fvoidCN fvoidCN changed the title IDEA-386673 MCP structured output error responses incorrectly validated against success schema [IDEA-386673] MCP structured output error responses incorrectly validated against success schema Mar 4, 2026
Copy link
Collaborator

@nerzhulart nerzhulart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

3 participants