server error if tool declares outputSchema but no structuredContent in result

This commit is contained in:
Basil Hosmer 2025-05-21 15:42:14 -04:00
commit aeb7b8d741
No known key found for this signature in database

View file

@ -198,7 +198,14 @@ export class McpServer {
}
}
if (tool.outputSchema && result.structuredContent) {
if (tool.outputSchema) {
if (!result.structuredContent) {
throw new McpError(
ErrorCode.InvalidParams,
`Tool ${request.params.name} has an output schema but no structured content was provided`,
);
}
// if the tool has an output schema, validate structured content
const parseResult = await tool.outputSchema.safeParseAsync(
result.structuredContent,