Skip to content

Commit 33895f4

Browse files
Merge branch 'main' into request-propagation-in-tools
2 parents dff036e + c401939 commit 33895f4

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/server/mcp.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,68 @@ describe("tool()", () => {
12121212
}),
12131213
).rejects.toThrow(/Tool test has an output schema but no structured content was provided/);
12141214
});
1215+
/***
1216+
* Test: Tool with Output Schema Must Provide Structured Content
1217+
*/
1218+
test("should skip outputSchema validation when isError is true", async () => {
1219+
const mcpServer = new McpServer({
1220+
name: "test server",
1221+
version: "1.0",
1222+
});
1223+
1224+
const client = new Client({
1225+
name: "test client",
1226+
version: "1.0",
1227+
});
1228+
1229+
mcpServer.registerTool(
1230+
"test",
1231+
{
1232+
description: "Test tool with output schema but missing structured content",
1233+
inputSchema: {
1234+
input: z.string(),
1235+
},
1236+
outputSchema: {
1237+
processedInput: z.string(),
1238+
resultType: z.string(),
1239+
},
1240+
},
1241+
async ({ input }) => ({
1242+
content: [
1243+
{
1244+
type: "text",
1245+
text: `Processed: ${input}`,
1246+
},
1247+
],
1248+
isError: true,
1249+
})
1250+
);
1251+
1252+
const [clientTransport, serverTransport] =
1253+
InMemoryTransport.createLinkedPair();
1254+
1255+
await Promise.all([
1256+
client.connect(clientTransport),
1257+
mcpServer.server.connect(serverTransport),
1258+
]);
1259+
1260+
await expect(
1261+
client.callTool({
1262+
name: "test",
1263+
arguments: {
1264+
input: "hello",
1265+
},
1266+
}),
1267+
).resolves.toStrictEqual({
1268+
content: [
1269+
{
1270+
type: "text",
1271+
text: `Processed: hello`,
1272+
},
1273+
],
1274+
isError: true,
1275+
});
1276+
});
12151277

12161278
/***
12171279
* Test: Schema Validation Failure for Invalid Structured Content

src/server/mcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export class McpServer {
200200
}
201201
}
202202

203-
if (tool.outputSchema) {
203+
if (tool.outputSchema && !result.isError) {
204204
if (!result.structuredContent) {
205205
throw new McpError(
206206
ErrorCode.InvalidParams,

0 commit comments

Comments
 (0)