Skip to content

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

Description

@tobiasBora

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

  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

Activity

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

    v2Ideas, requests and plans for v2 of the SDK which will incorporate major changes and fixes

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions