TypeScript SDK tool with outputSchema swallows thrown errors (MCP error -32602)
When registering a tool with an outputSchema using the McpServer class in @modelcontextprotocol/typescript-sdk, errors thrown inside the tool call are swallowed and replaced with
MCP error -32602: Tool ${toolName} has an output schema but no structured content was provided. The same happens when returning{ content: ..., isError: true }. Which SDK version fixes this, and what is the workaround for older versions?Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/699
4 answers
Fixed in @modelcontextprotocol/typescript-sdk 1.15.0. The issue was closed as stale (NOT_PLANNED), but a commenter verified the fix on 1.15.0: the framework now automatically catches errors thrown inside a tool call and converts them to the standard message format with
{isError: true, ...}, so your original error propagates instead of being replaced by the confusingMCP error -32602: Tool ${toolName} has an output schema but no structured content was providedmessage. Upgrade to 1.15.0 or later and re-test.If you cannot upgrade and must use outputSchema with the McpServer class, the workaround shown in the thread is to always include a
structuredContentobject in the tool result that matches the outputSchema, in addition to the text content. For example, a tool with an outputSchema describing{temperature, conditions, humidity}should return:json{ "content": [ { "type": "text", "text": "{\"temperature\": 22.5, \"conditions\": \"Partly cloudy\", \"humidity\": 65}" } ], "structuredContent": { "temperature": 22.5, "conditions": "Partly cloudy", "humidity": 65 } }This requirement is visible in the source around
src/server/mcp.tslines 203-204 but is not documented, which is why the error message is misleading. As general advice: treatstructuredContentas mandatory whenever a tool declares an outputSchema, since older SDK versions do not map thrown errors toisErroron their own.Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Registered a tool with an outputSchema and threw an error inside the tool call. The thrown error was swallowed and replaced with
MCP error -32602: Tool ... has an output schema but no structured content was provided; returning{ content: ..., isError: true }had the same result.Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/699 (opens external site)
Did this work for you?What @sergii-kamenskyi tried on GitHub (Worked)
Upgraded to @modelcontextprotocol/typescript-sdk 1.15.0 and let the tool throw errors. The framework now automatically catches the error and converts it to the message format with
{isError: true, ...}.Did this work for you?What @z3media tried on GitHub (Outcome unclear)
Suggested adding a
structuredContentobject that matches the outputSchema to every tool result alongside the text content, providing a full tool definition and JSON-RPC response example to demonstrate the expected shape.Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server