Add HTTP client connect for initialize handshake#1
Closed
atesgoral wants to merge 1 commit intoag/client-session-terminationfrom
Closed
Add HTTP client connect for initialize handshake#1atesgoral wants to merge 1 commit intoag/client-session-terminationfrom
atesgoral wants to merge 1 commit intoag/client-session-terminationfrom
Conversation
Per MCP spec, clients must send an `initialize` request followed by a `notifications/initialized` notification before issuing any other requests. The server's `InitializeResult` (protocol version, server capabilities, server info, instructions) negotiates the session for the lifetime of the connection. `MCP::Client::HTTP#connect` performs the full handshake, caches the server's `InitializeResult`, and exposes it via the `server_info` reader. `connected?` reports handshake completion. `connect` is idempotent — a second call returns the cached result without contacting the server. After `close`, state is cleared and `connect` will handshake again. https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization
Owner
Author
|
Reopening on upstream — this is the fork-local copy used only for visualizing the stack. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
MCP::Client::HTTP#connectto perform the MCP initialization handshake: sends theinitializerequest, followed by the requirednotifications/initializednotification, and caches the server'sInitializeResult(protocol version, capabilities, server info, instructions).connect(client_info:, protocol_version:, capabilities:)— idempotent; a second call returns the cached result without contacting the server. Afterclose, state is cleared andconnectwill handshake again.connected?— predicate set only after the full handshake completes (not mid-handshake), so a failed notification send leaves the transport in a consistent state.server_info— reader exposing the cachedInitializeResult.Replaces the previous pattern where callers had to construct the
initializerequest manually. E.g.:`rubytransport = MCP::Client::HTTP.new(url: "https://api.example.com/mcp")
transport.connect
client = MCP::Client.new(transport: transport)
`Stacked on modelcontextprotocol#326; will re-target to
mainonce that merges.Test plan
client_info/protocol_version/capabilities, idempotence, JSON-RPC error response, missingresult,connected?lifecycle throughclose, reconnect aftercloserake test— 775 runs, 1927 assertions, 0 failuresrubocopclean on touched filesexamples/streamable_http_server.rb: connect → tools → close → reconnect