Skip to content

refactor(call): use typed MCP errors instead of string parsing#117

Merged
appcypher merged 1 commit intomainfrom
appcypher/typed-mcp-errors
Feb 11, 2026
Merged

refactor(call): use typed MCP errors instead of string parsing#117
appcypher merged 1 commit intomainfrom
appcypher/typed-mcp-errors

Conversation

@appcypher
Copy link
Copy Markdown
Member

Summary

  • Replace string-based error detection with proper typed error handling for MCP service errors
  • Preserve structured error information (code, message, data) instead of flattening to strings
  • Enables better error messages by accessing typed fields like JSON-RPC error codes
  • Fixes issue where "missing field" errors from serde weren't being detected

Changes

  • lib/error.rs: Add ToolError::Mcp variant wrapping rmcp::service::ServiceError
  • lib/suggest.rs: Add McpErrorKind enum and analyze_mcp_error() function for structured error analysis
  • lib/suggest.rs: Add extract_missing_field_from_message() to handle both serde and custom error formats
  • lib/suggest.rs: Update is_missing_param_error() to detect serde "missing field" format
  • lib/mcp.rs: Simplify call_tool() to propagate typed errors via ? operator instead of stringifying
  • lib/handlers/tool/call.rs: Pattern match on ToolError::Mcp and use McpErrorKind for dispatch

Test Plan

  • Run cargo build to verify compilation
  • Run cargo clippy to check for warnings
  • Test with a tool that requires parameters: tool call <tool> -m <method> without required params
  • Verify error output shows the missing parameter name and lists required/optional parameters from schema

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
@appcypher appcypher merged commit 3883b84 into main Feb 11, 2026
10 checks passed
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.

1 participant