fix: return proper MCP error responses from tools#46
Merged
Conversation
This commit adds a --verbose flag to search and fetch commands that provides detailed logging of the search process, including: - Search URLs being accessed - Page loading status - Pagination progress - Results count per page - Total patents collected Additionally, CI has been updated to test verbose mode functionality. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Previously, tool errors were returned as strings in the response content, which does not properly indicate an error condition to MCP clients. This commit updates the search_patents and fetch_patent tool methods to return Result types that map to MCP error responses with the isError field set according to the MCP specification. Changes: - Return Result<String, ErrorData> instead of String from tool methods - Use ErrorData::new with proper error codes (INTERNAL_ERROR, INVALID_PARAMS) - Update tests to check for Ok/Err results instead of string content This ensures that MCP clients receive properly formatted error responses when tools encounter failures, following the MCP specification at: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#calling-tools Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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
Fix MCP server to return proper error responses with
isErrorfield according to the MCP specification, instead of returning error messages as strings in successful responses.Problem
Previously, when tools encountered errors, they would return error messages as strings in the response content. This means:
isErrorfield would befalse(indicating success)contentfieldSolution
Update tool methods to return
Result<String, ErrorData>instead ofString:search_patents- ReturnsErr(ErrorData)on search failuresfetch_patent- ReturnsErr(ErrorData)on fetch failures or "not found" casesChanges
Result<String, ErrorData>for proper error propagationErrorCode::INTERNAL_ERRORfor failures andErrorCode::INVALID_PARAMSfor not found casesis_ok()/is_err()instead of string contentSpecification
This follows the MCP specification for tool errors:
https://modelcontextprotocol.io/specification/2025-11-25/server/tools#calling-tools
Test plan
🤖 Generated with Claude Code