Skip to content

Commit 281cb4c

Browse files
committed
fix up README with new interface and examples
1 parent dccb29e commit 281cb4c

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

README.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -587,23 +587,50 @@ otherwise `resources/read` requests will be a no-op.
587587

588588
## Building an MCP Client
589589

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.
591592

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+
class CustomTransport
597+
def tools
598+
# Must return Array<MCP::Client::Tool>
599+
end
600+
601+
def call_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.
593610

594611
### HTTP Transport Layer
595612

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:
597623

598624
```ruby
599625
gem 'mcp'
600626
gem 'faraday', '>= 2.0'
601627
```
602628

603-
The `MCP::Client::Http` class provides a simple HTTP client for interacting with MCP servers:
629+
Example usage:
604630

605631
```ruby
606-
client = MCP::Client::HTTP.new(url: "https://api.example.com/mcp")
632+
http_transport = MCP::Client::HTTP.new(url: "https://api.example.com/mcp")
633+
client = MCP::Client.new(transport: http_transport)
607634

608635
# List available tools
609636
tools = client.tools
@@ -620,29 +647,23 @@ response = client.call_tool(
620647
)
621648
```
622649

623-
The HTTP client supports:
624-
- Tool listing via the `tools/list` method
625-
- Tool invocation via the `tools/call` method
626-
- Automatic JSON-RPC 2.0 message formatting
627-
- UUID v7 request ID generation
628-
- Setting headers for things like authorization
629-
630650
#### HTTP Authorization
631651

632-
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:
633653

634654
```ruby
635-
client = MCP::Client::HTTP.new(
655+
http_transport = MCP::Client::HTTP.new(
636656
url: "https://api.example.com/mcp",
637657
headers: {
638658
"Authorization" => "Bearer my_token"
639659
}
640660
)
641661

662+
client = MCP::Client.new(transport: http_transport)
642663
client.tools # will make the call using Bearer auth
643664
```
644665

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.
646667

647668
### Tool Objects
648669

0 commit comments

Comments
 (0)