Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ stdio_transport = MCP::Client::Stdio.new(
)
client = MCP::Client.new(transport: stdio_transport)

# Perform the MCP initialization handshake before sending any requests.
# Negotiate the protocol lifecycle before sending any requests.
client.connect

# List available tools.
Expand Down
2 changes: 1 addition & 1 deletion docs/_client/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ transport = MCP::Client::HTTP.new(
oauth: provider,
)
client = MCP::Client.new(transport: transport)
client.connect # `initialize` is sent here; if the server replies 401 the OAuth flow runs and the handshake is retried with the acquired token
client.connect # the lifecycle is established here; if the server replies 401 the OAuth flow runs and the request is retried with the acquired token
client.tools
```

Expand Down
4 changes: 2 additions & 2 deletions docs/_client/lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This page covers `MCP::Client#connect` and how it negotiates between the two.

## Handshake

Call `MCP::Client#connect` to perform the MCP [initialization handshake](https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization) before sending any other requests. The client sends an `initialize` request through the transport, followed by the required `notifications/initialized` notification, and caches the server's `InitializeResult` (protocol version, capabilities, server info, instructions):
Call `MCP::Client#connect` before sending any other requests. On the handshake lifecycle it performs the MCP [initialization handshake](https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization): the client sends an `initialize` request through the transport, followed by the required `notifications/initialized` notification, and caches the server's `InitializeResult` (protocol version, capabilities, server info, instructions):

```ruby
client.connect
Expand All @@ -22,7 +22,7 @@ client.connected? # => true
client.server_info # => cached InitializeResult
```

`connect` accepts optional `client_info:`, `protocol_version:`, and `capabilities:` keyword arguments. It is idempotent: a second call returns the cached result without contacting the server. After `close`, state is cleared and `connect` will handshake again.
`connect` accepts optional `client_info:`, `protocol_version:`, and `capabilities:` keyword arguments. It is idempotent: a second call returns the cached result without contacting the server. After `close`, state is cleared and `connect` establishes the lifecycle again.

This applies to both the Stdio and HTTP transports described on the [Transports](/client/transports/) page.

Expand Down
6 changes: 3 additions & 3 deletions docs/_client/transports.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ stdio_transport = MCP::Client::Stdio.new(
)
client = MCP::Client.new(transport: stdio_transport)

# Perform the MCP initialization handshake before sending any requests.
# Negotiate the protocol lifecycle before sending any requests.
client.connect

# List available tools.
Expand All @@ -57,7 +57,7 @@ stdio_transport.close
The stdio transport automatically handles:

- Spawning the server process with `Open3.popen3`
- MCP protocol initialization handshake (`initialize` request + `notifications/initialized`)
- Lifecycle negotiation (a `server/discover` probe, or `initialize` + `notifications/initialized` on the handshake lifecycle)
- JSON-RPC 2.0 message framing over newline-delimited JSON
- Answering server `ping` requests; see [Answering Server Pings](/client/ping/#answering-server-pings)

Expand Down Expand Up @@ -93,7 +93,7 @@ Example usage:
http_transport = MCP::Client::HTTP.new(url: "https://api.example.com/mcp")
client = MCP::Client.new(transport: http_transport)

# Perform the MCP initialization handshake before sending any requests.
# Negotiate the protocol lifecycle before sending any requests.
client.connect

# List available tools
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ stdio_transport = MCP::Client::Stdio.new(
)
client = MCP::Client.new(transport: stdio_transport)

# Perform the MCP initialization handshake before sending any requests.
# Negotiate the protocol lifecycle before sending any requests.
client.connect

# List available tools.
Expand Down
Loading