Skip to content

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

Merged
aayush-kapoor merged 2 commits into
vercel:mainfrom
joaopedroassad:fix-mcp-ping-empty-result
May 29, 2026
Merged

fix(mcp): respond to ping requests with an empty result#15701
aayush-kapoor merged 2 commits into
vercel:mainfrom
joaopedroassad:fix-mcp-ping-empty-result

Conversation

@joaopedroassad
Copy link
Copy Markdown
Contributor

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 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

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features, run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Closes #6282

@aayush-kapoor aayush-kapoor enabled auto-merge (squash) May 29, 2026 18:08
@aayush-kapoor aayush-kapoor merged commit dcefad3 into vercel:main May 29, 2026
48 of 49 checks passed
@aayush-kapoor aayush-kapoor added backport Admins only: add this label to a pull request in order to backport it to the prior version and removed backport Admins only: add this label to a pull request in order to backport it to the prior version labels 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>
@github-actions
Copy link
Copy Markdown
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>
@github-actions
Copy link
Copy Markdown
Contributor

🚀 Published in:

Package Version
@ai-sdk/google 4.0.0-canary.75 github npm
@ai-sdk/google-vertex 5.0.0-canary.98 github npm
@ai-sdk/mcp 2.0.0-canary.56 github npm
@ai-sdk/react 4.0.0-canary.162 github npm
@ai-sdk/xai 4.0.0-canary.69 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.

MCP Client does not respond to ping requests from server

2 participants