Skip to content

Missing or wrong structuredContent blocks tools from reporting error #654

@Areo-Joe

Description

@Areo-Joe

Describe the bug
When a tool with outputSchema is called, the server sdk checks the result to see if the structuredContent is correct. If not, throw an Error. This blocks tools from reporting error, as the tool can set the isError property to true to indicates any error. However the structuredContent checking is prioritized and always runs first.

To Reproduce
Steps to reproduce the behavior:

  1. create a MCP server
// server.mjs
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer(
  {
    name: "Basic Server",
    version: "1.0.0",
  },
  { capabilities: { tools: {} } }
);

server.registerTool(
  "toolThatFails",
  {
    description: "A tool that fails",
    outputSchema: {
      test: z.string(),
    },
  },
  async () => {
    return {
      content: [
        {
          type: "text",
          text: "It is a message that reports error and should be sent to client",
        },
      ],
      isError: true,
    };
  }
);

const transport = new StdioServerTransport();

server.connect(transport);
  1. create an MCP client and call the tool
// client.mjs
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const client = new Client({
  name: "Basic Client",
  version: "1.0.0",
});
const transport = new StdioClientTransport({
  command: "node",
  args: ["server.mjs"],
});

await client.connect(transport);

console.log(await client.listTools());
console.log(
  await client.callTool({
    name: "toolThatFails",
  })
);

Expected behavior
MCP client should receive the origin error that is reported by the MCP server.

Plus
I do not think it is a by design behavior, as the code in the client sdk side checks the isError property first.

Activity

sushichan044

sushichan044 commented on Jun 20, 2025

@sushichan044
Contributor

I am also facing this issue and I agree with the author's proposed solution.
I believe that a structured output and its schema are meant to define the structure for successful responses, not necessarily for errors or other exceptions.

linked a pull request that will close this issuefix: skip validation if tool reports error #655on Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Areo-Joe@sushichan044

      Issue actions

        Missing or wrong structuredContent blocks tools from reporting error · Issue #654 · modelcontextprotocol/typescript-sdk