Skip to content

Add client-level connect handshake to stdio transport#133

Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:add_connect_to_stdio_client
Open

Add client-level connect handshake to stdio transport#133
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:add_connect_to_stdio_client

Conversation

@koic
Copy link
Copy Markdown
Member

@koic koic commented May 6, 2026

Motivation and Context

Follow-up to modelcontextprotocol/ruby-sdk#336

mcp gem 0.15.0 introduced an explicit MCP::Client#connect method for the stdio transport, aligning with the Python and TypeScript SDKs which require explicit handshake calls regardless of transport type:

This sample is updated to call @mcp_client.connect explicitly after creating the client, demonstrating the recommended initialization pattern. The Gemfile constraint is bumped to >= 0.15.0 to require the new API.

How Has This Been Tested?

Ran the sample against weather-server-ruby and confirmed the connection, tool listing, and chat loop continue to work as expected.

Breaking Changes

None. The change updates the sample to use the new explicit connect API, which was added as a non-breaking addition in mcp gem 0.15.0.

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

## Motivation and Context

Follow-up to modelcontextprotocol/ruby-sdk#336

mcp gem 0.15.0 introduced an explicit `MCP::Client#connect` method for the stdio transport,
aligning with the Python and TypeScript SDKs which require explicit handshake calls regardless
of transport type:

- Python SDK: `ClientSession.initialize()`
  https://github.com/modelcontextprotocol/python-sdk
- TypeScript SDK: `Client.connect(transport)`
  https://github.com/modelcontextprotocol/typescript-sdk

This sample is updated to call `@mcp_client.connect` explicitly after creating the client,
demonstrating the recommended initialization pattern. The Gemfile constraint is bumped to `>= 0.15.0`
to require the new API.

## How Has This Been Tested?

Ran the sample against `weather-server-ruby` and confirmed the connection, tool listing,
and chat loop continue to work as expected.

## Breaking Changes

None. The change updates the sample to use the new explicit `connect` API,
which was added as a non-breaking addition in mcp gem 0.15.0.
@koic koic force-pushed the add_connect_to_stdio_client branch from 4f7f7e5 to a1838e9 Compare May 6, 2026 00:27
koic added a commit to koic/modelcontextprotocol that referenced this pull request May 6, 2026
## Motivation and Context

Follow-up to modelcontextprotocol/ruby-sdk#336 and
modelcontextprotocol/quickstart-resources#133.

The Ruby example in `docs/docs/develop/build-client.mdx` constructed `MCP::Client`
with a stdio transport and immediately called `client.tools`, relying on the implicit
`initialize_session` that the stdio transport performed on the first request.

ruby-sdk PR modelcontextprotocol#336 added `MCP::Client#connect` for the stdio transport so that
the explicit `initialize` plus `notifications/initialized` handshake is exposed
at the public API level, matching the Python SDK (`ClientSession.initialize()`)
and the TypeScript SDK (`Client.connect(transport)`). The implicit-init path is
preserved as a backwards-compatible shim, but new code is expected to call `connect` explicitly.

This change updates the Ruby example so readers learn the explicit `@mcp_client.connect`
pattern from the start, consistent with how the Python and TypeScript examples present
the handshake.

## How Has This Been Tested?

- Re-read the surrounding `connect_to_server` example in
  `docs/docs/develop/build-client.mdx` to confirm `@mcp_client.connect`
  fits naturally between the client construction and the subsequent
  `@mcp_client.tools` call.
- Ran `npm run prep` to confirm there are no documentation warnings or
  errors introduced by the change.

## Breaking Changes

None. This is a documentation-only change that adds a single explicit `connect` call to
the Ruby client example. No schema, navigation, or runtime behavior is affected.
mcp-commander Bot pushed a commit to modelcontextprotocol/modelcontextprotocol that referenced this pull request May 6, 2026
## Motivation and Context

Follow-up to modelcontextprotocol/ruby-sdk#336 and
modelcontextprotocol/quickstart-resources#133.

The Ruby example in `docs/docs/develop/build-client.mdx` constructed `MCP::Client`
with a stdio transport and immediately called `client.tools`, relying on the implicit
`initialize_session` that the stdio transport performed on the first request.

ruby-sdk PR #336 added `MCP::Client#connect` for the stdio transport so that
the explicit `initialize` plus `notifications/initialized` handshake is exposed
at the public API level, matching the Python SDK (`ClientSession.initialize()`)
and the TypeScript SDK (`Client.connect(transport)`). The implicit-init path is
preserved as a backwards-compatible shim, but new code is expected to call `connect` explicitly.

This change updates the Ruby example so readers learn the explicit `@mcp_client.connect`
pattern from the start, consistent with how the Python and TypeScript examples present
the handshake.

## How Has This Been Tested?

- Re-read the surrounding `connect_to_server` example in
  `docs/docs/develop/build-client.mdx` to confirm `@mcp_client.connect`
  fits naturally between the client construction and the subsequent
  `@mcp_client.tools` call.
- Ran `npm run prep` to confirm there are no documentation warnings or
  errors introduced by the change.

## Breaking Changes

None. This is a documentation-only change that adds a single explicit `connect` call to
the Ruby client example. No schema, navigation, or runtime behavior is affected.
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.

1 participant