Merge branch 'main' into request-propagation-in-tools

This commit is contained in:
Konstantin Konstantinov 2025-06-24 19:32:49 +03:00 • committed by GitHub
commit 33895f4520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 63 additions and 1 deletions

View file

@ -1212,6 +1212,68 @@ describe("tool()", () => {
}),
).rejects.toThrow(/Tool test has an output schema but no structured content was provided/);
});
/***
* Test: Tool with Output Schema Must Provide Structured Content
*/
test("should skip outputSchema validation when isError is true", async () => {
const mcpServer = new McpServer({
name: "test server",
version: "1.0",
});
const client = new Client({
name: "test client",
version: "1.0",
});
mcpServer.registerTool(
"test",
{
description: "Test tool with output schema but missing structured content",
inputSchema: {
input: z.string(),
},
outputSchema: {
processedInput: z.string(),
resultType: z.string(),
},
},
async ({ input }) => ({
content: [
{
type: "text",
text: `Processed: ${input}`,
},
],
isError: true,
})
);
const [clientTransport, serverTransport] =
InMemoryTransport.createLinkedPair();
await Promise.all([
client.connect(clientTransport),
mcpServer.server.connect(serverTransport),
]);
await expect(
client.callTool({
name: "test",
arguments: {
input: "hello",
},
}),
).resolves.toStrictEqual({
content: [
{
type: "text",
text: `Processed: hello`,
},
],
isError: true,
});
});
/***
* Test: Schema Validation Failure for Invalid Structured Content

View file

@ -200,7 +200,7 @@ export class McpServer {
}
}
if (tool.outputSchema) {
if (tool.outputSchema && !result.isError) {
if (!result.structuredContent) {
throw new McpError(
ErrorCode.InvalidParams,