Skip to content

Require calling MCP::Client#connect before sending requests on stdio transport#427

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:require_connect_stdio
Open

Require calling MCP::Client#connect before sending requests on stdio transport#427
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:require_connect_stdio

Conversation

@koic

@koic koic commented Jun 26, 2026

Copy link
Copy Markdown
Member

Motivation and Context

The MCP specification requires an initialize request followed by notifications/initialized before any other interaction. Issue #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 (#336) added MCP::Client::Stdio#connect while keeping an implicit-init compatibility shim on the first send_request. Phase 2 (#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.

Closes #334

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

…o 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.

Closes modelcontextprotocol#334
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.

Remove stdio's implicit init and require client.connect universally

1 participant