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
What happened?
I created a tool that outputs a structured content like:
Using only static analysis, we can directly see that this won't work, since
outputSchemaexpects an object butstructuredContentoutputs 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
SDK version
2.0.0
Area
Server