You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Require calling MCP::Client#connect before sending requests on stdio transport
## Motivation and Context
The MCP specification requires an `initialize` request followed by `notifications/initialized`
before any other interaction. Issue modelcontextprotocol#334 makes that handshake explicit on the stdio client,
matching the Python SDK (`ClientSession.initialize()`) and TypeScript SDK (`Client.connect(transport)`).
The change was staged to avoid a hard break. Phase 1 (modelcontextprotocol#336) added `MCP::Client::Stdio#connect`
while keeping an implicit-init compatibility shim on the first `send_request`.
Phase 2 (modelcontextprotocol#338) emitted a deprecation warning when that shim ran. The warning has shipped since 0.16.0,
so this final phase removes the shim.
## How Has This Been Tested?
`send_request` now raises a `RuntimeError` when `connect` has not been called, and no longer
auto-starts the subprocess. `connect` is the sole entry point that spawns the process and
performs the handshake, which avoids leaving an orphaned subprocess behind.
The stdio test suite was reworked to call `connect` explicitly, a regression test was added for
the new guard, and `rake test` passes (1145 runs, 0 failures).
## Breaking Changes
Stdio clients that send requests without calling `MCP::Client#connect` now raise a `RuntimeError`
instead of silently initializing. Call `client.connect` before the first request.
Closesmodelcontextprotocol#334
# Returns true once `connect` (or the implicit handshake on the first
132
-
# `send_request`) has completed. Returns false before the handshake
133
-
# and after `close`.
131
+
# Returns true once `connect` has completed the handshake. Returns false before the handshake and after `close`.
134
132
defconnected?
135
133
@initialized
136
134
end
@@ -140,11 +138,7 @@ def connected?
140
138
# write does not race ahead of the request write on the wire. The yield happens inside `@write_mutex`,
141
139
# so any subsequent `send_notification` write waits for the mutex and is guaranteed to land after the request.
142
140
defsend_request(request:)
143
-
startunless@started
144
-
unless@initialized
145
-
warn("Calling `MCP::Client::Stdio#send_request` without calling `MCP::Client#connect` is deprecated. Use `MCP::Client#connect` before sending requests instead.",uplevel: 1)
146
-
connect
147
-
end
141
+
raise"MCP::Client#connect must be called before sending requests."unless@initialized
/Calling `MCP::Client::Stdio#send_request` without calling `MCP::Client#connect` is deprecated\. Use `MCP::Client#connect` before sending requests instead\./.freeze
0 commit comments