Repository navigation
fix(mcp): return structured error for unknown tool calls - #444
Miracle656 merged 1 commit into
Conversation
|
@rupesh-kumar-sah Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
When an unknown tool was requested, BazaarMcpServer threw a raw Error producing an unparseable JSON-RPC fault instead of an MCP CallToolResult with isError: true. Return a structured ERR_UNKNOWN_TOOL error response containing the list of valid tool names with length-bounded, sanitized input name. Closes Divinity-Labs#415
aaa2903 to
b9ab065
Compare
|
Merged to An unknown tool name threw, so the SDK surfaced a JSON-RPC transport error and the calling agent got nothing to branch on — which is exactly what #415 describes. It now answers with Listing the valid tools in the reason is the detail I'd single out. A model that guessed a tool name can correct itself straight from the response instead of needing another round trip to One fix on merge. // The handler throws, so the SDK surfaces this as a JSON-RPC error rather
// than a structured McpErrorResponse — the agent gets no error code.
await expect(callTool('bazaar_refund')).rejects.toThrow('Unknown tool: bazaar_refund');So that test was pinning the bug you were fixing. I inverted the assertion rather than deleting it — it now checks For your awareness: #561 implements the same issue. #415 is assigned to you, so yours is the one I reviewed and merged; I'll note the duplication there. Lens: 116 files, 1,428 tests passing, typecheck clean. |
Summary
When an unknown tool was requested,
BazaarMcpServerthrew an unhandledError, causing the JSON-RPC transport to fail with a protocol fault (-32603 Internal error) instead of an MCPCallToolResultwithisError: true.This PR replaces the raw exception with a structured
ERR_UNKNOWN_TOOLerror response that lists valid tool names (bazaar_search,paid_call) and length-bounds the untrusted input name.Changes
ERR_UNKNOWN_TOOLtoMCP_ERROR_CODESinsrc/mcp/codes.ts.VALID_TOOL_NAMESinsrc/mcp/server.ts.createErrorResponse('ERR_UNKNOWN_TOOL', ...)inCallToolRequestSchemahandler.tests/mcp.test.tsverifying error shape, valid tool list inclusion, and length bounding.Closes #415