Skip to content

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

Merged
aayush-kapoor merged 1 commit into
release-v6.0from
backport-pr-15701-to-release-v6.0
May 29, 2026
Merged

Backport: fix(mcp): respond to ping requests with an empty result#15715
aayush-kapoor merged 1 commit into
release-v6.0from
backport-pr-15701-to-release-v6.0

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

This is an automated backport of #15701 to the release-v6.0 branch. FYI @joaopedroassad

## 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>
auto-merge was automatically disabled May 29, 2026 18:42

Pull request was closed

@aayush-kapoor aayush-kapoor reopened this May 29, 2026
@aayush-kapoor aayush-kapoor enabled auto-merge (squash) May 29, 2026 18:45
@aayush-kapoor aayush-kapoor merged commit ec5fceb into release-v6.0 May 29, 2026
48 checks passed
@aayush-kapoor aayush-kapoor deleted the backport-pr-15701-to-release-v6.0 branch May 29, 2026 18:49
@github-actions
Copy link
Copy Markdown
Contributor Author

🚀 Published in:

Package Version
@ai-sdk/mcp 1.0.45 github npm
@ai-sdk/xai 3.0.93 github npm

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.

1 participant