⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

fix mcp: improve error code detection when listing tools fails#787

Open
kooba wants to merge 3 commits intocloudflare:mainfrom
kooba:fix/mcp-method-not-found-error-handling
Open

fix mcp: improve error code detection when listing tools fails#787
kooba wants to merge 3 commits intocloudflare:mainfrom
kooba:fix/mcp-method-not-found-error-handling

Conversation

@kooba
Copy link

@kooba kooba commented Jan 16, 2026

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 for e.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

  • Reuse existing getErrorCode helper from errors.ts for consistent error code extraction
  • Check both direct error code and message string for -32601

Jakub Borys added 2 commits January 14, 2026 16:44
…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-bot
Copy link

changeset-bot bot commented Jan 16, 2026

🦋 Changeset detected

Latest commit: f6a503b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agents Patch

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 16, 2026

Open in StackBlitz

npm i https://pkg.pr.new/cloudflare/agents@787

commit: f6a503b

@mattzcarey mattzcarey self-assigned this Jan 16, 2026
@mattzcarey
Copy link
Contributor

this is very silly of the transport. Will have a look, thanks :)

@nikraimo83 nikraimo83 mentioned this pull request Jan 29, 2026
@mattzcarey mattzcarey self-requested a review February 2, 2026 18:30
const errorCode = getErrorCode(e);
const errorMessage = toErrorMessage(e);
const isMethodNotFound =
errorCode === -32601 || errorMessage.includes('"code":-32601');
Copy link
Contributor

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.

Copy link
Contributor

@mattzcarey mattzcarey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blocking

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.

3 participants