Python: fix(python): treat any MCP ping JSON-RPC error as unsupported, not just -32601 - #7656
Open
Diego Casati (dcasati) wants to merge 1 commit into
Conversation
…st -32601
MCPTool._ensure_connected() used a periodic `ping` as a connection health
check. When the server rejected `ping` with an McpError, the code only
treated error code -32601 ("Method not found", the JSON-RPC-spec-correct
code for an unimplemented method) as "ping unsupported, keep using this
connection". Any other error code fell through to a reconnect attempt.
Some real-world MCP servers -- e.g. Microsoft Fabric's Data Agent MCP
endpoint -- reject an unsupported `ping` with a different code (-32600
"Invalid Request") instead. Since that server only implements initialize,
notifications/initialized, tools/list, and tools/call, every single tool
call triggered this same failed-ping path, and instead of just disabling
future pings, the client attempted an unnecessary reconnect. That reconnect
can itself fail in ways unrelated to the original (harmless) ping
rejection, breaking an otherwise fully working MCP tool.
Any well-formed JSON-RPC error response to ping -- regardless of its
specific error code -- already proves the connection is alive: the server
received the request and replied. It just means the server doesn't
support (or accept) the optional ping method. This change treats any
McpError from send_ping() the same way: disable future pings and continue
using the existing connection, without attempting a reconnect. Only
non-McpError exceptions (timeouts, transport/connection failures) --
where we genuinely don't know if the server is still reachable -- still
trigger a reconnect, unchanged from before.
Added a regression test (nonstandard error code -32600) alongside the
existing -32601 test to cover this.
Diego Casati (dcasati)
deployed
to
github-app-auth
August 13, 2026 20:53 — with
GitHub Actions
Active
Diego Casati (dcasati)
deployed
to
github-app-auth
August 13, 2026 20:53 — with
GitHub Actions
Active
Diego Casati (dcasati)
deployed
to
github-app-auth
August 13, 2026 20:53 — with
GitHub Actions
Active
Diego Casati (dcasati)
deployed
to
github-app-auth
August 13, 2026 20:53 — with
GitHub Actions
Active
Contributor
There was a problem hiding this comment.
Pull request overview
Updates MCP connection health checks to treat any JSON-RPC ping error as evidence of a live connection.
Changes:
- Disables future pings after any
McpError. - Retains reconnect behavior for transport and other non-MCP failures.
- Adds regression coverage for error code
-32600.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/_mcp.py |
Broadens unsupported-ping handling. |
python/packages/core/tests/core/test_mcp.py |
Tests nonstandard ping error handling. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
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.
Hi,
MCPTool._ensure_connected() used a periodic
pingas a connection health check.When the server rejected
pingwith an McpError, the code only treated error code -32601 ("Method not found", the JSON-RPC-spec-correct code for an unimplemented method) as "ping unsupported, keep using this connection". Any other error code fell through to a reconnect attempt.It seems like some real-world MCP servers (like the Microsoft Fabric's Data Agent MCP endpoint) reject an unsupported
pingwith a different code (-32600 "Invalid Request") instead. Since that server only implements initialize, notifications/initialized, tools/list, and tools/call, every single tool call triggered this same failed-ping path, and instead of just disabling future pings, the client attempted an unnecessary reconnect. That reconnect can itself fail in ways unrelated to the original (harmless) ping rejection, breaking an otherwise fully working MCP tool.Any well-formed JSON-RPC error response to ping - regardless of its specific error code - already proves the connection is alive: the server received the request and replied. It just means the server doesn't support (or accept) the optional ping method.
This change treats any McpError from send_ping() the same way: disable future pings and continue using the existing connection, without attempting a reconnect. Only non-McpError exceptions (timeouts, transport/connection failures) -- where we genuinely don't know if the server is still reachable -- still trigger a reconnect, unchanged from before.
Added a regression test (nonstandard error code -32600) alongside the existing -32601 test to cover this.
Motivation & Context
Description & Review Guide
Related Issue
Fixes #
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.