You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+36-15Lines changed: 36 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -587,23 +587,50 @@ otherwise `resources/read` requests will be a no-op.
587
587
588
588
## Building an MCP Client
589
589
590
-
The `MCP::Client` module provides client implementations for interacting with MCP servers. Currently, it supports HTTP transport for making JSON-RPC requests to MCP servers.
590
+
The `MCP::Client` class provides an interface for interacting with MCP servers.
591
+
Clients are initialized with a transport layer instance that instructs them how to interact with the server.
591
592
592
-
**Note:** The client HTTP transport requires the `faraday` gem. Add `gem 'faraday', '>= 2.0'` to your Gemfile if you plan to use the client HTTP transport functionality.
593
+
If the transport layer you need is not included in the gem, you can build and pass your own instances so long as they conform to the following interface:
594
+
595
+
```ruby
596
+
classCustomTransport
597
+
deftools
598
+
# Must return Array<MCP::Client::Tool>
599
+
end
600
+
601
+
defcall_tool(tool:, input:)
602
+
# tool: MCP::Client::Tool
603
+
# input: Hash - the arguments to pass to the tool
604
+
# Returns: Hash - the content from the response (typically response.dig("result", "content"))
605
+
end
606
+
end
607
+
```
608
+
609
+
**Note:** We strongly recommend returning `MCP::Client::Tool` instances rather than custom tool objects with the same interface, as this ensures compatibility with future SDK features and provides a consistent interface.
593
610
594
611
### HTTP Transport Layer
595
612
596
-
You'll need to add `faraday` as a dependency to use the HTTP transport layer.
613
+
Use the `MCP::Client::Http` transport to interact with MCP servers using simple HTTP requests.
614
+
615
+
The HTTP client supports:
616
+
- Tool listing via the `tools/list` method
617
+
- Tool invocation via the `tools/call` method
618
+
- Automatic JSON-RPC 2.0 message formatting
619
+
- UUID v7 request ID generation
620
+
- Setting headers for things like authorization
621
+
622
+
You'll need to add `faraday` as a dependency in order to use the HTTP transport layer:
597
623
598
624
```ruby
599
625
gem 'mcp'
600
626
gem 'faraday', '>= 2.0'
601
627
```
602
628
603
-
The `MCP::Client::Http` class provides a simple HTTP client for interacting with MCP servers:
By default, the HTTP client has no authentication, but it supports custom headers for authentication. For example, to use Bearer token authentication:
652
+
By default, the HTTP transport layer provides no authentication to the server, but you can provide custom headers if you need authentication. For example, to use Bearer token authentication:
client.tools # will make the call using Bearer auth
643
664
```
644
665
645
-
You can add any custom headers needed for your authentication scheme. The client will include these headers in all requests.
666
+
You can add any custom headers needed for your authentication scheme, or for any other purpose. The client will include these headers on every requests.
0 commit comments