Skip to content

Commit 309aba5

Browse files
committed
add some client docs
1 parent 9ad0d99 commit 309aba5

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
@@ -216,6 +216,47 @@ $ ruby examples/stdio_server.rb
216216
{"jsonrpc":"2.0","id":"2","method":"tools/list"}
217217
```
218218

219+
## MCP Client
220+
221+
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.
222+
223+
### HTTP Client
224+
225+
The `ModelContextProtocol::Client::Http` class provides a simple HTTP client for interacting with MCP servers:
226+
227+
```ruby
228+
client = ModelContextProtocol::Client::Http.new(url: "https://api.example.com/mcp")
229+
230+
# List available tools
231+
tools = client.tools
232+
tools.each do |tool|
233+
puts "Tool: #{tool.name}"
234+
puts "Description: #{tool.description}"
235+
puts "Input Schema: #{tool.input_schema}"
236+
end
237+
238+
# Call a specific tool
239+
response = client.call_tool(
240+
tool: tools.first,
241+
input: { message: "Hello, world!" }
242+
)
243+
```
244+
245+
The HTTP client supports:
246+
- Tool listing via the `tools/list` method
247+
- Tool invocation via the `tools/call` method
248+
- Automatic JSON-RPC 2.0 message formatting
249+
- UUID v7 request ID generation
250+
251+
### Tool Objects
252+
253+
The client provides wrapper objects for tools returned by the server:
254+
255+
- `ModelContextProtocol::Client::Tool` - Represents a single tool with its metadata
256+
- `ModelContextProtocol::Client::Tools` - Collection of tools with enumerable functionality
257+
258+
These objects provide easy access to tool properties like name, description, and input schema.
259+
219260
## Configuration
220261

221262
The gem can be configured using the `MCP.configure` block:

0 commit comments

Comments
 (0)