Skip to content

fix(mcp): return structured error with valid tool list on unknown tool - #561

Open
sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:fix/mcp-unknown-tool-error-415
Open

sparkysolutions10-pixel wants to merge 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:fix/mcp-unknown-tool-error-415

Conversation

@sparkysolutions10-pixel

Copy link
Copy Markdown
Contributor

Summary

Closes #415

Returns a structured error with a code and the list of valid tool names when an unknown tool is called, instead of throwing a raw protocol-level exception.

Changes

  • Structured Error Return: Replaced throw new Error(\Unknown tool: ...`)with structured error response usingERR_UNKNOWN_TOOL`.
  • Valid Tools List: Included validTools: ['bazaar_search', 'paid_call'] in the error response and message so calling agents can inspect and self-correct immediately.
  • Input Sanitization & Length Bounding: Sanitized the echoed tool name by bounding it to 64 characters and stripping non-printable/control characters.

Tests

  • Added unit tests in tests/mcp.test.ts:
    • returns a structured error instead of throwing a raw exception
    • lists all valid tool names in the error response
    • length-bounds and sanitises untrusted input in tool name echo
  • All 12 tests pass (npx vitest run tests/mcp.test.ts).

@sparkysolutions10-pixel
sparkysolutions10-pixel force-pushed the fix/mcp-unknown-tool-error-415 branch from b3409c6 to ef3f5c1 Compare October 19, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

An unknown tool name throws a raw exception

1 participant