Skip to content

Output validation error: Invalid structured content for tool

Spec
2026-07-28
Evidence
E2Reproducedarm64
TypeScript SDK (server)
@modelcontextprotocol/server@2.4.0
Verified

When a tool declares an outputSchema, the server SDK checks structuredContent against it before the result leaves the server. Our tool declared { sum: number } and returned { total: 'five' }. The TypeScript SDK v2 turned the result into an error result:

Output validation error: Invalid structured content for tool bad_output: sum: Invalid input: expected number, received undefined

with isError: true. This is a bug in the server, not in the client or the model: the tool ran, but its answer was thrown away.

Compare the field names and types in the message with what the handler builds. Typical slips: a renamed field (total vs sum), a number serialized as a string, or a nested object where the schema says flat. Fix whichever side is wrong, and add a test that calls the tool, for example with the Inspector CLI.

If a tool declares outputSchema, every successful result must include structuredContent. A tool that returned only content: [{ type: 'text', … }] got this instead:

Output validation error: Tool text_only has an output schema but no structured content was provided

Either return both (text for clients that only show text, structured data for programs), or remove outputSchema if the tool does not produce structured data.

MCPDev is community documentation. It is not affiliated with the Model Context Protocol project or with the vendors of the clients it covers.