Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: correct unknown tool/prompt/resource error handling #1872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
DePasqualeOrg wants to merge 1 commit into modelcontextprotocol:main
base: main
Choose a base branch
Loading
from DePasqualeOrg:fix/unknown-tool-protocol-error

Conversation

@DePasqualeOrg
Copy link

@DePasqualeOrg DePasqualeOrg commented Jan 15, 2026

While developing my Swift SDK for MCP, I encountered the following MCP spec compliance issue in the Python SDK:

When an unknown tool is called, it throws a ToolError, which is caught by the server's exception handler and converted to a response with isError: true.

The spec distinguishes between protocol errors and tool execution errors:

Protocol Errors:

  1. Protocol Errors: Standard JSON-RPC errors for issues like:
    • Unknown tools
    • Invalid arguments
    • Server errors

Tool Execution Errors:

  1. Tool Execution Errors: Reported in tool results with isError: true:
    • API failures
    • Invalid input data
    • Business logic errors

Protocol error example for unknown tool:

{
 "jsonrpc": "2.0",
 "id": 3,
 "error": {
 "code": -32602,
 "message": "Unknown tool: invalid_tool_name"
 }
}

The same issue applies to prompts and resources. Per the spec:

  • Unknown prompts should return -32602 (INVALID_PARAMS): spec reference
  • Unknown resources should return -32002 (RESOURCE_NOT_FOUND): spec reference

Changes

  • ToolManager: Raises McpError with INVALID_PARAMS (-32602) for unknown tools
  • PromptManager: Raises McpError with INVALID_PARAMS (-32602) for unknown prompts
  • ResourceManager: Raises McpError with RESOURCE_NOT_FOUND (-32002) for unknown resources
  • Added RESOURCE_NOT_FOUND constant to mcp.types

How Has This Been Tested?

I updated the tests to check for the correct error handling.

Breaking Changes

Users who expected the incorrect error handling may need to change their code.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@DePasqualeOrg DePasqualeOrg changed the title (削除) Fix unknown tool/prompt/resource error handling (削除ここまで) (追記) fix: correct unknown tool/prompt/resource error handling (追記ここまで) Jan 15, 2026
Copy link
Member

Kludex commented Jan 21, 2026

@claude can you resolve the conflicts here?

maxisbey reacted with laugh emoji claude[bot] reacted with eyes emoji

@maxisbey maxisbey force-pushed the fix/unknown-tool-protocol-error branch 2 times, most recently from c46e5b0 to 86d3037 Compare January 21, 2026 18:18
@DePasqualeOrg DePasqualeOrg force-pushed the fix/unknown-tool-protocol-error branch from 86d3037 to 1f1e2ad Compare January 23, 2026 10:35
Copy link
Author

I resolved the conflicts. The failing Claude Code Review appears to be due to a permissions issue in this repository's GitHub Actions workflow configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /