Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,9 @@ export class McpServer {
await this.validateToolOutput(tool, result, request.params.name);
return result;
} catch (error) {
if (error instanceof ProtocolError && error.code === ProtocolErrorCode.UrlElicitationRequired) {
throw error; // Return the error to the caller without wrapping in CallToolResult
if (error instanceof ProtocolError) {
// Protocol errors should be returned as JSON-RPC errors, not wrapped in CallToolResult
throw error;
}
return this.createToolError(error instanceof Error ? error.message : String(error));
}
Expand Down
28 changes: 10 additions & 18 deletions test/integration/test/server/mcp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1837,25 +1837,17 @@ describe('Zod v4', () => {

await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);

const result = await client.request(
{
method: 'tools/call',
params: {
name: 'nonexistent-tool'
}
},
CallToolResultSchema
);

expect(result.isError).toBe(true);
expect(result.content).toEqual(
expect.arrayContaining([
await expect(
client.request(
{
type: 'text',
text: expect.stringContaining('Tool nonexistent-tool not found')
}
])
);
method: 'tools/call',
params: {
name: 'nonexistent-tool'
}
},
CallToolResultSchema
)
).rejects.toThrow(/Tool nonexistent-tool not found/);
});

/***
Expand Down
Loading