What happened?
If I create a tool with a structuredContent but no content, I get a typescript error saying that the content field is mandatory. But this is stupid for two reasons:
-
For now at least, it seems like the SDK will anyway add a content automatically if not present… So let me save time (and redundancy) by avoiding to explicitly add it myself.
-
Worst, according to the spec:
For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.
The verb SHOULD is used, and not MUST, which means that we don't strictly need to follow this rule if we don't want to be backward compatible.
What did you expect?
I'd expect typescript to allow tools to return no content but only a structuredContent. Moreover, we should add an option to say if the SDK should add itself a serialization of the structuredContent into content as this is done for now: I believe that it is a good thing to enable it by default as it is done now, but for efficiency reasons it would be great to disable content and only keep structuredContent (at least in v2) since this is allowed by the specification.
Code to reproduce
server.registerTool(
'ping',
{
description: 'Returns a string pong with a timestamp',
outputSchema: z.string()
},
async () => {
const str = `Pong at ${new Date()}`
return {
// content: [{ type: 'text', text: str }], // Error without this line
structuredContent: str
};
}
);
SDK version
2.0.0
Area
Server
What happened?
If I create a tool with a
structuredContentbut nocontent, I get a typescript error saying that thecontentfield is mandatory. But this is stupid for two reasons:For now at least, it seems like the SDK will anyway add a
contentautomatically if not present… So let me save time (and redundancy) by avoiding to explicitly add it myself.Worst, according to the spec:
The verb
SHOULDis used, and notMUST, which means that we don't strictly need to follow this rule if we don't want to be backward compatible.What did you expect?
I'd expect typescript to allow tools to return no
contentbut only astructuredContent. Moreover, we should add an option to say if the SDK should add itself a serialization of thestructuredContentintocontentas this is done for now: I believe that it is a good thing to enable it by default as it is done now, but for efficiency reasons it would be great to disablecontentand only keepstructuredContent(at least in v2) since this is allowed by the specification.Code to reproduce
SDK version
2.0.0
Area
Server