ruby-sdk/test/mcp
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Koichi ITO ac7598a13d Support server-to-client ping per MCP specification
## Motivation and Context

The MCP specification defines `ping` as a bidirectional utility: either party may issue it.
https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/ping

The previous PR added `MCP::Client#ping`. This PR adds the symmetric server-side send capability,
`ServerSession#ping`.

This aligns the Ruby SDK with the Python SDK (`ServerSession.send_ping`) and
the TypeScript SDK (`Server.ping()`), both of which expose a server-initiated ping.
In practice this enables a Ruby MCP server to health-check non-Ruby clients
(e.g., Claude Desktop, the Python or TypeScript SDK client) during long-running tool operations.

Scope is intentionally server-only: this PR does not add client-side inbound request dispatch,
which is a larger refactor outside the ping utility. A Ruby `MCP::Client` therefore still cannot receive
a server-initiated ping; that gap is tracked as a separate follow-up.

## How Has This Been Tested?

New file `test/mcp/server_session_ping_test.rb` covers:

- success (empty `result` returned)
- `related_request_id` propagated through the transport when a session ID is set
- `ValidationError` when the transport returns `nil`
- `ValidationError` when the transport returns a non-Hash `result`
- transport-level errors propagate unchanged
- ping succeeds without any client capability declaration (per spec, ping has no capability gate)

`test/mcp/server_context_test.rb` adds two tests for `ServerContext#ping` delegation
(happy path and `NoMethodError` when the session lacks `#ping`).

The existing server-side `ping` handler tests continue to pass unchanged.

## Breaking Changes

None. `MCP::ServerContext#ping` and `MCP::Server::ValidationError` are purely additive.
2026-05-22 11:28:51 +09:00
..
client Add OAuth 2.1 client support for MCP authorization flow 2026-05-17 00:48:41 +09:00
prompt Add _meta field to resource, content, and result classes 2026-04-11 15:08:55 +09:00
resource Add _meta field to resource, content, and result classes 2026-04-11 15:08:55 +09:00
server Reject duplicate initialize requests (#350) 2026-05-18 00:00:23 -04:00
tool Advertise JSON Schema 2020-12 dialect on emitted tool schemas 2026-05-11 13:44:30 +09:00
annotations_test.rb Replace assert_empty with assert_equal using explicit literals 2026-02-24 16:09:34 +09:00
cancellation_test.rb Support notifications/cancelled per MCP specification 2026-05-03 04:02:22 +09:00
client_test.rb fix: preserve client tool output schemas 2026-05-11 21:44:26 -04:00
configuration_test.rb feat: add opt-in tool output validation 2026-05-12 16:20:43 -04:00
content_test.rb Add _meta field to resource, content, and result classes 2026-04-11 15:08:55 +09:00
icon_test.rb Replace assert_empty with assert_equal using explicit literals 2026-02-24 16:09:34 +09:00
instrumentation_test.rb Add around_request hook for request instrumentation 2026-04-11 13:54:47 +09:00
logging_message_notification_test.rb Add logging support 2026-01-26 22:23:46 +09:00
methods_test.rb Add roots/list and notifications/roots/list_changed support 2026-04-15 02:39:14 +09:00
progress_test.rb Auto-set server.transport in Transport#initialize 2026-04-09 12:08:55 +09:00
prompt_test.rb Fix Prompt#validate_arguments! crash when arguments are nil 2026-03-01 17:21:41 +09:00
resource_template_test.rb Add _meta field to resource, content, and result classes 2026-04-11 15:08:55 +09:00
resource_test.rb Add _meta field to resource, content, and result classes 2026-04-11 15:08:55 +09:00
server_cancellation_test.rb Support notifications/cancelled per MCP specification 2026-05-03 04:02:22 +09:00
server_context_test.rb Support server-to-client ping per MCP specification 2026-05-22 11:28:51 +09:00
server_elicitation_test.rb Support notifications/cancelled per MCP specification 2026-05-03 04:02:22 +09:00
server_notification_test.rb Auto-set server.transport in Transport#initialize 2026-04-09 12:08:55 +09:00
server_progress_test.rb Auto-set server.transport in Transport#initialize 2026-04-09 12:08:55 +09:00
server_roots_test.rb Add roots/list and notifications/roots/list_changed support 2026-04-15 02:39:14 +09:00
server_sampling_test.rb Support notifications/cancelled per MCP specification 2026-05-03 04:02:22 +09:00
server_session_ping_test.rb Support server-to-client ping per MCP specification 2026-05-22 11:28:51 +09:00
server_test.rb Reject duplicate initialize requests (#350) 2026-05-18 00:00:23 -04:00
string_utils_test.rb Fix ReDoS vulnerability in StringUtils#underscore 2026-01-09 01:14:52 +09:00
tool_test.rb Advertise JSON Schema 2020-12 dialect on emitted tool schemas 2026-05-11 13:44:30 +09:00
transport_test.rb Remove redundant require statements 2025-08-02 00:57:31 +09:00