Skip to content

Commit cda977e

Browse files
committed
updated readme.md
1 parent a1391d3 commit cda977e

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

README.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This project is a Ruby client for the [Model Context Protocol (MCP)](https://mod
1212
- 🛠️ **Tool Integration**: Automatically converts MCP tools into RubyLLM-compatible tools
1313
- 📄 **Resource Management**: Access and include MCP resources (files, data) and resource templates in conversations
1414
- 🎯 **Prompt Integration**: Use predefined MCP prompts with arguments for consistent interactions
15+
- 🎛️ **Client Features**: Support for sampling and roots
1516
- 🎨 **Enhanced Chat Interface**: Extended RubyLLM chat methods for seamless MCP integration
1617
- 📚 **Simple API**: Easy-to-use interface that integrates seamlessly with RubyLLM
1718

@@ -462,6 +463,81 @@ puts result
462463
# Result: { status: "success", data: "Processed data" }
463464
```
464465

466+
## Client Features
467+
468+
The RubyLLM::MCP client provides support functionality that can be exposed to MCP servers. These features must be explicitly configured before creating client objects to ensure you're opting into this functionality.
469+
470+
### Roots
471+
472+
Roots provide MCP servers with access to underlying file system information. The implementation starts with a lightweight approach due to the MCP specification's current limitations on root usage.
473+
474+
When roots are configured, the client will:
475+
476+
- Expose roots as a supported capability to MCP servers
477+
- Support dynamic addition and removal of roots during the client lifecycle
478+
- Fire `notifications/roots/list_changed` events when roots are modified
479+
480+
#### Configuration
481+
482+
```ruby
483+
RubyLLM::MCP.config do |config|
484+
config.roots = ["to/a/path", Rails.root]
485+
end
486+
487+
client = RubyLLM::MCP::Client.new(...)
488+
```
489+
490+
#### Usage
491+
492+
```ruby
493+
# Access current root paths
494+
client.roots.paths
495+
# => ["to/a/path", #<Pathname:/to/rails/root/path>]
496+
497+
# Add a new root (fires list_changed notification)
498+
client.roots.add("new/path")
499+
client.roots.paths
500+
# => ["to/a/path", #<Pathname:/to/rails/root/path>, "new/path"]
501+
502+
# Remove a root (fires list_changed notification)
503+
client.roots.remove("to/a/path")
504+
client.roots.paths
505+
# => [#<Pathname:/to/rails/root/path>, "new/path"]
506+
```
507+
508+
### Sampling
509+
510+
Sampling allows MCP servers to offload LLM requests to the MCP client rather than making them directly from the server. This enables MCP servers to optionally use LLM connections through the client.
511+
512+
#### Configuration
513+
514+
```ruby
515+
RubyLLM::MCP.configure do |config|
516+
config.sampling.enabled = true
517+
config.sampling.preferred_model = "gpt-4.1"
518+
519+
# Optional: Use a block for dynamic model selection
520+
config.sampling.preferred_model do |model_preferences|
521+
model_preferences.hints.first
522+
end
523+
524+
# Optional: Add guards to filter sampling requests
525+
config.sampling.guard do |sample|
526+
sample.message.include("Hello")
527+
end
528+
end
529+
```
530+
531+
#### How It Works
532+
533+
With the above configuration:
534+
535+
- Clients will respond to all incoming sample requests using the specified model (`gpt-4.1`)
536+
- Sample messages will only be approved if they contain the word "Hello" (when using the guard)
537+
- The `preferred_model` can be a string or a proc that provides dynamic model selection based on MCP server characteristics
538+
539+
The `preferred_model` proc receives model preferences from the MCP server, allowing you to make intelligent model selection decisions based on the server's requirements for success.
540+
465541
## Transport Types
466542

467543
### SSE (Server-Sent Events)

0 commit comments

Comments
 (0)