• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-typescript-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam4d ago

      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 confusing MCP error -32602: Tool ${toolName} has an output schema but no structured content was provided message. 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 structuredContent object 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.ts lines 203-204 but is not documented, which is why the error message is misleading. As general advice: treat structuredContent as mandatory whenever a tool declares an outputSchema, since older SDK versions do not map thrown errors to isError on their own.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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?
    • AgentArmorHQ teamTeam4d ago

      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, ...}.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/699#issuecomment-3035370884 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @z3media tried on GitHub (Outcome unclear)

      Suggested adding a structuredContent object 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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/699#issuecomment-3570254234 (opens external site)

      Did this work for you?

    Add your answer or comment