modelcontextprotocol / modelcontextprotocol/typescript-sdk
[v2] Should raise error at build time if zod outputSchema is not consistent with the structuredContent type
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the server.registerTool entry point and trace how outputSchema and structuredContent are typed and validated in the TypeScript SDK. Reproduce the shown mismatch, then inspect nearby type definitions and existing checks to determine how valid structured outputs are represented. Done means this mismatch produces a TypeScript error at build time without breaking valid tool registrations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100