Support ping client API per MCP specification#324
Merged
koic merged 1 commit intomodelcontextprotocol:mainfrom Apr 20, 2026
Merged
Support ping client API per MCP specification#324koic merged 1 commit intomodelcontextprotocol:mainfrom
ping client API per MCP specification#324koic merged 1 commit intomodelcontextprotocol:mainfrom
Conversation
## Motivation and Context The MCP specification defines the `ping` utility for verifying that the peer of a connection is still responsive. The Ruby SDK server side already replies to incoming `ping` requests with an empty result, but `MCP::Client` had no public API to send a `ping` request. Users had to build the JSON-RPC payload themselves and call the transport directly. This adds a client-side counterpart to the existing server handler and aligns the Ruby SDK in spirit with the Python and TypeScript SDKs, which expose `ClientSession.send_ping` and `Client.ping` respectively. Those SDKs validate the response envelope via type schemas (`EmptyResult` / `EmptyResultSchema`) and raise their validation library's generic exception (Pydantic's `ValidationError` / Zod's `ZodError`). The Ruby client applies a Hash type check on `result` (matching Python's behavior of requiring a dict while allowing arbitrary contents) and raises a new `MCP::Client::ValidationError` for malformed responses, keeping `MCP::Client::ServerError` reserved for JSON-RPC error responses. ## How Has This Been Tested? Client tests cover: - request structure (method is `ping`, no `params`) - empty result on success - `ServerError` on JSON-RPC error response - `ValidationError` on a response missing `result` - `ValidationError` on a `result` of the wrong type (e.g., String) - propagation of transport-level errors raised by `transport.send_request` The existing server-side `ping` handler tests continue to pass unchanged. ## Breaking Changes None. `MCP::Client#ping` and `MCP::Client::ValidationError` are purely additive. The server-side `ping` handler behavior is unchanged.
atesgoral
approved these changes
Apr 20, 2026
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.
Motivation and Context
The MCP specification defines the
pingutility for verifying that the peer of a connection is still responsive. The Ruby SDK server side already replies to incomingpingrequests with an empty result, butMCP::Clienthad no public API to send apingrequest. Users had to build the JSON-RPC payload themselves and call the transport directly.This adds a client-side counterpart to the existing server handler and aligns the Ruby SDK in spirit with the Python and TypeScript SDKs, which expose
ClientSession.send_pingandClient.pingrespectively. Those SDKs validate the response envelope via type schemas (EmptyResult/EmptyResultSchema) and raise their validation library's generic exception (Pydantic'sValidationError/ Zod'sZodError). The Ruby client applies a Hash type check onresult(matching Python's behavior of requiring a dict while allowing arbitrary contents) and raises a newMCP::Client::ValidationErrorfor malformed responses, keepingMCP::Client::ServerErrorreserved for JSON-RPC error responses.How Has This Been Tested?
Client tests cover:
ping, noparams)ServerErroron JSON-RPC error responseValidationErroron a response missingresultValidationErroron aresultof the wrong type (e.g., String)transport.send_requestThe existing server-side
pinghandler tests continue to pass unchanged.Breaking Changes
None.
MCP::Client#pingandMCP::Client::ValidationErrorare purely additive. The server-sidepinghandler behavior is unchanged.Types of changes
Checklist