| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Implements the pattern described in modelcontextprotocol#2153: MCPServer users should raise exceptions and the framework converts them to appropriate protocol responses, without leaking internal details. Changes: - ToolError raised by user → CallToolResult(is_error=True) with user's message - ResourceError raised by user → MCPError (JSON-RPC error) with user's message - PromptError (new) raised by user → MCPError (JSON-RPC error) with user's message - MCPError → re-raised as-is for protocol-level errors - Unexpected exceptions → sanitized message (no internal detail leakage) Files modified: - exceptions.py: Add PromptError class - tools/base.py: Let ToolError/MCPError pass through Tool.run() without wrapping - resources/types.py: Let ResourceError/MCPError pass through FunctionResource.read() - prompts/base.py: Let PromptError/MCPError pass through Prompt.render() - prompts/manager.py: Raise PromptError instead of ValueError for unknown prompts - server.py: Add handler-level error handling to _handle_read_resource() and _handle_get_prompt(), explicit ToolError catch in _handle_call_tool() - __init__.py: Export ToolError, ResourceError, PromptError from package Closes modelcontextprotocol#2153 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Thanks for the PR. Tracking this in #2198 instead. Closing as part of a general backlog cleanup following the v2 release. If this is still relevant against v2, feel free to reopen. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Implements the pattern described in #2153: MCPServer users should raise exceptions to signal errors, and the framework converts them to appropriate protocol responses — without leaking internal details to clients.
Changes
Error propagation — let user-raised exceptions pass through:
Handler-level error conversion — framework catches and converts:
New PromptError class for symmetry with ToolError and ResourceError.
Security improvement (#698): Unexpected exceptions no longer leak internal details (e.g., database connection strings, file paths) to the client. Only user-raised ToolError/ResourceError/PromptError messages reach the client.
User-facing behavior
Test plan
🤖 Generated with Claude Code