Skip to content

Commit c401939

Browse files
authored
Merge pull request #655 from Areo-Joe/fix/skip_validate_if_error
fix: skip validation if tool reports error
2 parents 600c623 + 33e03f4 commit c401939

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
@@ -1203,6 +1203,68 @@ describe("tool()", () => {
12031203
}),
12041204
).rejects.toThrow(/Tool test has an output schema but no structured content was provided/);
12051205
});
1206+
/***
1207+
* Test: Tool with Output Schema Must Provide Structured Content
1208+
*/
1209+
test("should skip outputSchema validation when isError is true", async () => {
1210+
const mcpServer = new McpServer({
1211+
name: "test server",
1212+
version: "1.0",
1213+
});
1214+
1215+
const client = new Client({
1216+
name: "test client",
1217+
version: "1.0",
1218+
});
1219+
1220+
mcpServer.registerTool(
1221+
"test",
1222+
{
1223+
description: "Test tool with output schema but missing structured content",
1224+
inputSchema: {
1225+
input: z.string(),
1226+
},
1227+
outputSchema: {
1228+
processedInput: z.string(),
1229+
resultType: z.string(),
1230+
},
1231+
},
1232+
async ({ input }) => ({
1233+
content: [
1234+
{
1235+
type: "text",
1236+
text: `Processed: ${input}`,
1237+
},
1238+
],
1239+
isError: true,
1240+
})
1241+
);
1242+
1243+
const [clientTransport, serverTransport] =
1244+
InMemoryTransport.createLinkedPair();
1245+
1246+
await Promise.all([
1247+
client.connect(clientTransport),
1248+
mcpServer.server.connect(serverTransport),
1249+
]);
1250+
1251+
await expect(
1252+
client.callTool({
1253+
name: "test",
1254+
arguments: {
1255+
input: "hello",
1256+
},
1257+
}),
1258+
).resolves.toStrictEqual({
1259+
content: [
1260+
{
1261+
type: "text",
1262+
text: `Processed: hello`,
1263+
},
1264+
],
1265+
isError: true,
1266+
});
1267+
});
12061268

12071269
/***
12081270
* 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)