[v2] Should raise error at build time if zod outputSchema is not consistent with the structuredContent type

Author: tobiasBoraCreated Sep 3, 2026Updated Sep 14, 2026
Labelsv2

What happened?

I created a tool that outputs a structured content like:

  server.registerTool(
    'ping',
    {
      description: 'Returns a string pong with a timestamp',
      outputSchema: z.object({data: z.string()}) // <---- Wrong return type, should be simply z.string()!
    },
    async () => {
      const str = `Pong at ${new Date()}`
      return {
        content: [{ type: 'text', text: str }], // It seems to be added automatically by the library, but typescript complains if only structuredContent is present
        structuredContent: str
      };
    }
  );

Using only static analysis, we can directly see that this won't work, since outputSchema expects an object but structuredContent outputs a string… and indeed, at runtime this produces an error. Yet, I'd love this kind of error to be catched at build time, with a proper Typescript error.

What did you expect?

An error.

Code to reproduce

typescript
  server.registerTool(
    'ping',
    {
      description: 'Returns a string pong with a timestamp',
      outputSchema: z.object({data: z.string()}) // <---- Wrong return type, should be simply z.string()!
    },
    async () => {
      const str = `Pong at ${new Date()}`
      return {
        content: [{ type: 'text', text: str }], // It seems to be added automatically by the library, but typescript complains if only structuredContent is present
        structuredContent: str
      };
    }
  );

SDK version

2.0.0

Area

Server

Source: modelcontextprotocol/typescript-sdk