fix(mcp): respond to ping requests with an empty result#15701
Merged
aayush-kapoor merged 2 commits intoMay 29, 2026
Conversation
aayush-kapoor
approved these changes
May 29, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 29, 2026
## Background I noticed that `MCPClient.onRequestMessage` replies with a JSON-RPC `method not found` error (`-32601`) to every incoming request that isn't `elicitation/create`. That includes `ping`. Per the [MCP specification on ping](https://modelcontextprotocol.io/specification/2025-06-18/basic/utilities/ping) and the JSON-RPC contract, a `ping` receiver has to respond with an empty result. MCP servers commonly ping their connected clients on an idle timer to confirm the connection is still alive. When the client comes back with an error response instead, the server reads that as a broken peer and disconnects on the next keepalive cycle. If you're using `experimental_createMCPClient` against a server that does idle pings, your session eventually drops. ## Summary Three files touched: - `packages/mcp/src/tool/mcp-client.ts` adds an early return branch in `onRequestMessage` for `ping`, sending back `{jsonrpc: '2.0', id: request.id, result: {}}`. The shape mirrors the existing `elicitation/create` send. No changes to public types or anything users see. - `packages/mcp/src/tool/mcp-client.test.ts` adds a `ping support` describe block built on the same pattern as the existing `elicitation support` test. It pushes a `ping` JSON-RPC request through the mock transport and asserts the client replies with `result: {}`. - `.changeset/mcp-ping-response.md` is the patch changeset. ## Manual Verification Before applying the fix on `main`, I added the new `ping support` test and watched it fail. The client came back with a `-32601` error response instead of an empty result, which is exactly what #6282 describes. With the fix in place, the same test passes, and so do all 61 pre-existing tests in `mcp-client.test.ts`. End to end, this corresponds to running an MCP server that pings on idle (any stdio server using the spec-recommended keepalive cadence), connecting with `experimental_createMCPClient`, and leaving the session quiet past the server's ping interval. Before the fix, the server disconnected when an error response landed. After the fix, the empty result keeps the session alive. ## Checklist - [x] All commits are signed (PRs with unsigned commits cannot be merged) - [x] Tests have been added / updated (for bug fixes / features) - [ ] Documentation has been added / updated (for bug fixes / features) - [x] A _patch_ changeset for relevant packages has been added (for bug fixes / features, run `pnpm changeset` in the project root) - [x] I have reviewed this pull request (self-review) ## Related Issues Closes #6282 Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.com>
Contributor
|
✅ Backport PR created: #15715 |
aayush-kapoor
added a commit
that referenced
this pull request
May 29, 2026
…5715) This is an automated backport of #15701 to the release-v6.0 branch. FYI @joaopedroassad Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Aayush Kapoor <83492835+aayush-kapoor@users.noreply.github.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.
Background
I noticed that
MCPClient.onRequestMessagereplies with a JSON-RPCmethod not founderror (-32601) to every incoming request that isn'telicitation/create. That includesping.Per the MCP specification on ping and the JSON-RPC contract, a
pingreceiver has to respond with an empty result. MCP servers commonly ping their connected clients on an idle timer to confirm the connection is still alive. When the client comes back with an error response instead, the server reads that as a broken peer and disconnects on the next keepalive cycle. If you're usingexperimental_createMCPClientagainst a server that does idle pings, your session eventually drops.Summary
Three files touched:
packages/mcp/src/tool/mcp-client.tsadds an early return branch inonRequestMessageforping, sending back{jsonrpc: '2.0', id: request.id, result: {}}. The shape mirrors the existingelicitation/createsend. No changes to public types or anything users see.packages/mcp/src/tool/mcp-client.test.tsadds aping supportdescribe block built on the same pattern as the existingelicitation supporttest. It pushes apingJSON-RPC request through the mock transport and asserts the client replies withresult: {}..changeset/mcp-ping-response.mdis the patch changeset.Manual Verification
Before applying the fix on
main, I added the newping supporttest and watched it fail. The client came back with a-32601error response instead of an empty result, which is exactly what #6282 describes. With the fix in place, the same test passes, and so do all 61 pre-existing tests inmcp-client.test.ts.End to end, this corresponds to running an MCP server that pings on idle (any stdio server using the spec-recommended keepalive cadence), connecting with
experimental_createMCPClient, and leaving the session quiet past the server's ping interval. Before the fix, the server disconnected when an error response landed. After the fix, the empty result keeps the session alive.Checklist
pnpm changesetin the project root)Related Issues
Closes #6282