refactor(call): use typed MCP errors instead of string parsing#117
Merged
refactor(call): use typed MCP errors instead of string parsing#117
Conversation
Replace string-based error detection with proper typed error handling for MCP service errors. This preserves structured error information (code, message, data) instead of flattening it to strings. Changes: - Add ToolError::Mcp variant wrapping rmcp::service::ServiceError - Add McpErrorKind enum for structured error analysis - Add analyze_mcp_error() to extract error info from ServiceError - Update call_tool() to propagate typed errors via ? operator - Pattern match on error types instead of regex parsing messages - Handle serde "missing field" format in addition to custom formats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changes
lib/error.rs: AddToolError::Mcpvariant wrappingrmcp::service::ServiceErrorlib/suggest.rs: AddMcpErrorKindenum andanalyze_mcp_error()function for structured error analysislib/suggest.rs: Addextract_missing_field_from_message()to handle both serde and custom error formatslib/suggest.rs: Updateis_missing_param_error()to detect serde "missing field" formatlib/mcp.rs: Simplifycall_tool()to propagate typed errors via?operator instead of stringifyinglib/handlers/tool/call.rs: Pattern match onToolError::Mcpand useMcpErrorKindfor dispatchTest Plan
cargo buildto verify compilationcargo clippyto check for warningstool call <tool> -m <method>without required params