From a1838e965aaa954d21f6a11486f49a6f859276c5 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 6 May 2026 09:25:30 +0900 Subject: [PATCH] Add client-level connect handshake to stdio transport ## Motivation and Context Follow-up to https://github.com/modelcontextprotocol/ruby-sdk/pull/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. --- mcp-client-ruby/Gemfile | 2 +- mcp-client-ruby/client.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mcp-client-ruby/Gemfile b/mcp-client-ruby/Gemfile index abb8b873..d9f3d541 100644 --- a/mcp-client-ruby/Gemfile +++ b/mcp-client-ruby/Gemfile @@ -5,4 +5,4 @@ source "https://rubygems.org" gem "anthropic" gem "base64" gem "dotenv" -gem "mcp", '>= 0.9.1' +gem "mcp", '>= 0.15.0' diff --git a/mcp-client-ruby/client.rb b/mcp-client-ruby/client.rb index 1d609ae8..5feffb0f 100644 --- a/mcp-client-ruby/client.rb +++ b/mcp-client-ruby/client.rb @@ -28,6 +28,7 @@ def connect_to_server(server_script_path) @transport = MCP::Client::Stdio.new(command: command, args: [server_script_path]) @mcp_client = MCP::Client.new(transport: @transport) + @mcp_client.connect tool_names = @mcp_client.tools.map(&:name) puts "\nConnected to server with tools: #{tool_names}"