ruby-sdk/lib/mcp/server
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Koichi ITO bea636c007 Refuse server-to-client requests in the modern lifecycle per SEP-2575
## Motivation and Context

The modern lifecycle removes server-initiated JSON-RPC requests: a stateless server has no connection to send them on,
and SEP-2322 multi round-trip `input_required` results replace what sampling and elicitation covered before.
`StdioTransport#send_request` already says so, refusing outright when its session is modern.
`StreamableHTTPTransport#send_request` says nothing, so a modern handler that reaches for elicitation
or sampling falls through to the session lookup and is told `Session not found: <uuid>` against a session id it never chose.
Failing is right, the explanation is not: `handle_modern` mints a session per request without ever registering it in `@sessions`,
so that lookup cannot succeed for a modern request no matter what the handler does.

`send_request` now refuses a modern-era session up front with the message `StdioTransport` uses, which turns
an incidental registration detail into a stated rule and leaves the rest of the method a legacy-only path by construction.
Callers see the same `RuntimeError` class as before, only with a message naming the actual constraint.

## How Has This Been Tested?

A new test in `test/mcp/server/transports/streamable_http_transport_test.rb` sends `elicitation/create` from
a session constructed with `era: :modern` and asserts the SEP-2575 message. It sits with the existing guard tests for stateless mode,
a missing `session_id`, and an unknown session, which still pass unchanged.
`bundle exec rake` is green, and both conformance legs pass their baseline check.

## Breaking Changes

None. The call already failed; only the message changes.
2026-08-13 23:25:04 +09:00
..
transports Refuse server-to-client requests in the modern lifecycle per SEP-2575 2026-08-13 23:25:04 +09:00
capabilities.rb Support Capability Extensions per SEP-2133 2026-06-14 17:20:45 +09:00
input_required_result.rb Let Handlers Return Multi Round-Trip input_required Results per SEP-2322 2026-08-08 15:07:16 +09:00
pagination.rb Support pagination per MCP specification 2026-04-18 18:23:30 +09:00
pending_response.rb Bound server-to-client requests with a timeout 2026-08-13 23:16:59 +09:00
request_state_security.rb Add opt-in requestState sealing via RequestStateSecurity 2026-08-08 18:54:14 +09:00
transports.rb Use autoload to defer loading of unused subsystems 2026-03-12 14:08:27 +09:00