Skip to content

Commit d8e1caf

Browse files
committed
add some client docs
1 parent 43d4dd0 commit d8e1caf

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,47 @@ $ ./stdio_server.rb
110110
{"jsonrpc":"2.0","id":"3","result":["ExampleTool"]}
111111
```
112112

113+
## MCP Client
114+
115+
The `ModelContextProtocol::Client` module provides client implementations for interacting with MCP servers. Currently, it supports HTTP transport for making JSON-RPC requests to MCP servers.
116+
117+
### HTTP Client
118+
119+
The `ModelContextProtocol::Client::Http` class provides a simple HTTP client for interacting with MCP servers:
120+
121+
```ruby
122+
client = ModelContextProtocol::Client::Http.new(url: "https://api.example.com/mcp")
123+
124+
# List available tools
125+
tools = client.tools
126+
tools.each do |tool|
127+
puts "Tool: #{tool.name}"
128+
puts "Description: #{tool.description}"
129+
puts "Input Schema: #{tool.input_schema}"
130+
end
131+
132+
# Call a specific tool
133+
response = client.call_tool(
134+
tool: tools.first,
135+
input: { message: "Hello, world!" }
136+
)
137+
```
138+
139+
The HTTP client supports:
140+
- Tool listing via the `tools/list` method
141+
- Tool invocation via the `tools/call` method
142+
- Automatic JSON-RPC 2.0 message formatting
143+
- UUID v7 request ID generation
144+
145+
### Tool Objects
146+
147+
The client provides wrapper objects for tools returned by the server:
148+
149+
- `ModelContextProtocol::Client::Tool` - Represents a single tool with its metadata
150+
- `ModelContextProtocol::Client::Tools` - Collection of tools with enumerable functionality
151+
152+
These objects provide easy access to tool properties like name, description, and input schema.
153+
113154
## Configuration
114155

115156
The gem can be configured using the `ModelContextProtocol.configure` block:

0 commit comments

Comments
 (0)