SIGN IN SIGN UP

fix(mcp): respond to ping requests with an empty result (#15701)

## 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>
J
Joao Assad committed
dcefad368bdb879e19ef64d4496beca0369df17b
Parent: 3215032
Committed by GitHub <noreply@github.com> on 5/29/2026, 6:14:46 PM