-
Notifications
You must be signed in to change notification settings - Fork 354
fix mcp: improve error code detection when listing tools fails #787
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
base: main
Are you sure you want to change the base?
fix mcp: improve error code detection when listing tools fails #787
Conversation
…ty discovery When MCP servers return a -32601 (Method not found) error for unsupported capabilities like resources/templates/list, the error may be wrapped by the transport layer (e.g., Streamable HTTP). The previous code only checked for e.code === -32601, but wrapped errors have the code embedded in the message string instead. This fix checks both: 1. Direct error code property (e.code === -32601) 2. Error code in message string (contains '"code":-32601') This allows capability discovery to gracefully continue when servers don't support certain methods, instead of failing the entire discovery process.
🦋 Changeset detectedLatest commit: f6a503b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
|
this is very silly of the transport. Will have a look, thanks :) |
| const errorCode = getErrorCode(e); | ||
| const errorMessage = toErrorMessage(e); | ||
| const isMethodNotFound = | ||
| errorCode === -32601 || errorMessage.includes('"code":-32601'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thoughts this feels like it will be too broad. Do you have an example of a server which breaks this? I'd prefer to fix this on the MCP SDK side.
mattzcarey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking
When discovering MCP server capabilities, listing tools (and other resources) would often fail because the error code was being read incorrectly.
MCP servers return a
-32601(Method not found) error for unsupported capabilities, but the transport layer (e.g., Streamable HTTP) wraps these errors. The previous code only checked fore.code === -32601, missing cases where the code was embedded in the error message string.This fix properly detects the error in both forms, allowing capability discovery to continue gracefully instead of failing entirely.
Changes