Skip to content

Commit 3b08a4a

Browse files
authored
Merge pull request patvice#89 from patvice/mcp-offical-sdk-support
Support offical MCP Gem as a Backend
2 parents edcc9b3 + ff8dc84 commit 3b08a4a

File tree

342 files changed

+20798
-10381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

342 files changed

+20798
-10381
lines changed

.github/workflows/cicd.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
ruby: ['3.1.3', '3.2', '3.3', '3.4']
14+
ruby: ['3.1', '3.2', '3.3', '3.4']
1515

1616
steps:
1717
- uses: actions/checkout@v4
@@ -39,4 +39,5 @@ jobs:
3939
- name: Run specs
4040
run: bundle exec rake
4141
env:
42+
CI: "true"
4243
GITHUB_ACTIONS: "true"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@
1818
Gemfile.lock
1919

2020
node_modules/
21+
.vcr_debug.log

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ source "https://rubygems.org"
55
gemspec
66

77
group :development do
8+
if RUBY_VERSION >= "3.2.0"
9+
gem "mcp", "~> 0.4"
10+
end
11+
812
# Development dependencies
913
gem "activesupport"
1014
gem "bundler", ">= 2.0"

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ Currently full support for MCP protocol version up to `2025-06-18`.
1515

1616
## RubyLLM::MCP Features
1717

18-
- 🔌 **Multiple Transport Types**: Streamable HTTP, and STDIO and legacy SSE transports
18+
- 🎛️ **Dual SDK Support** _(v0.8+)_: Choose between native full-featured implementation or official MCP SDK
19+
- 🔌 **Multiple Transport Types**: Streamable HTTP, STDIO, and SSE transports
1920
- 🛠️ **Tool Integration**: Automatically converts MCP tools into RubyLLM-compatible tools
2021
- 📄 **Resource Management**: Access and include MCP resources (files, data) and resource templates in conversations
2122
- 🎯 **Prompt Integration**: Use predefined MCP prompts with arguments for consistent interactions
22-
- 🎛️ **Client Features**: Support for sampling, roots, and elicitation
23-
- 🎨 **Enhanced Chat Interface**: Extended RubyLLM chat methods for seamless MCP integration
23+
- 🎨 **Client Features**: Support for sampling, roots, progress tracking, human-in-the-loop, and elicitation
24+
- 🔧 **Enhanced Chat Interface**: Extended RubyLLM chat methods for seamless MCP integration
2425
- 🔄 **Multiple Client Management**: Create and manage multiple MCP clients simultaneously for different servers and purposes
2526
- 📚 **Simple API**: Easy-to-use interface that integrates seamlessly with RubyLLM
2627

@@ -48,6 +49,46 @@ Or install it yourself as:
4849
gem install ruby_llm-mcp
4950
```
5051

52+
## Choosing an Adapter
53+
54+
Starting with version 0.8.0, RubyLLM MCP supports multiple SDK adapters:
55+
56+
### RubyLLM Adapter (Default)
57+
58+
The native implementation with full MCP protocol support:
59+
60+
```ruby
61+
client = RubyLLM::MCP.client(
62+
name: "server",
63+
adapter: :ruby_llm, # Default, can be omitted
64+
transport_type: :stdio,
65+
config: { command: "mcp-server" }
66+
)
67+
```
68+
69+
**Features**: All MCP features including SSE transport, sampling, roots, progress tracking, etc.
70+
71+
### MCP SDK Adapter
72+
73+
The official Anthropic-maintained SDK:
74+
75+
```ruby
76+
# Add to Gemfile
77+
gem 'mcp', '~> 0.4'
78+
79+
# Use in code
80+
client = RubyLLM::MCP.client(
81+
name: "server",
82+
adapter: :mcp_sdk,
83+
transport_type: :stdio,
84+
config: { command: "mcp-server" }
85+
)
86+
```
87+
88+
**Features**: Core MCP features (tools, resources, prompts). No SSE, sampling, or advanced features.
89+
90+
See the [Adapters Guide](https://rubyllm-mcp.com/guides/adapters.html) for detailed comparison.
91+
5192
## Usage
5293

5394
### Basic Setup

docs/configuration.md

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,38 @@ RubyLLM::MCP.configure do |config|
7575
end
7676
```
7777

78+
## Adapter Selection
79+
80+
{: .label .label-green }
81+
0.8+
82+
83+
RubyLLM MCP supports multiple SDK adapters. Choose between the native full-featured implementation or the official MCP SDK.
84+
85+
### Default Adapter
86+
87+
Set the default adapter for all clients:
88+
89+
```ruby
90+
RubyLLM::MCP.configure do |config|
91+
# Options: :ruby_llm (default), :mcp_sdk
92+
config.default_adapter = :ruby_llm
93+
end
94+
```
95+
96+
### Adapter Options
97+
98+
**`:ruby_llm`** (default)
99+
- Full MCP protocol implementation
100+
- All transport types (stdio, SSE, HTTP)
101+
- Advanced features (sampling, roots, progress tracking, etc.)
102+
103+
**`:mcp_sdk`**
104+
- Official Anthropic-maintained SDK
105+
- Core features only (tools, resources, prompts)
106+
- Limited transport support (stdio, HTTP - no SSE)
107+
108+
See the [Adapters Guide]({% link guides/adapters.md %}) for detailed feature comparison and usage examples.
109+
78110
## Client Configuration
79111

80112
### Basic Client Options
@@ -85,6 +117,7 @@ All MCP clients support these common options:
85117
client = RubyLLM::MCP.client(
86118
name: "unique-client-name", # Required: unique identifier
87119
transport_type: :stdio, # Required: :stdio, :sse, or :streamable
120+
adapter: :ruby_llm, # Optional: :ruby_llm (default) or :mcp_sdk
88121
start: true, # Optional: auto-start connection (default: true)
89122
request_timeout: 8000, # Optional: timeout in milliseconds (default: 8000)
90123
config: { # Required: transport-specific configuration
@@ -142,9 +175,13 @@ config: {
142175

143176
Best for web-based MCP servers using Server-Sent Events:
144177

178+
{: .warning }
179+
> SSE transport is only supported with `adapter: :ruby_llm`. The `:mcp_sdk` adapter does not support SSE.
180+
145181
```ruby
146182
client = RubyLLM::MCP.client(
147183
name: "web-server",
184+
adapter: :ruby_llm, # Required for SSE
148185
transport_type: :sse,
149186
config: {
150187
url: "https://api.example.com/mcp/sse", # Required: SSE endpoint
@@ -371,19 +408,19 @@ The RubyLLM MCP client supports multiple protocol versions. You can access these
371408

372409
```ruby
373410
# Latest supported protocol version
374-
puts RubyLLM::MCP::Protocol.latest_version
411+
puts RubyLLM::MCP::Native::Protocol.latest_version
375412
# => "2025-06-18"
376413

377414
# Default version used for negotiation
378-
puts RubyLLM::MCP::Protocol.default_negotiated_version
415+
puts RubyLLM::MCP::Native::Protocol.default_negotiated_version
379416
# => "2025-03-26"
380417

381418
# All supported versions
382-
puts RubyLLM::MCP::Protocol.supported_versions
419+
puts RubyLLM::MCP::Native::Protocol.supported_versions
383420
# => ["2025-06-18", "2025-03-26", "2024-11-05", "2024-10-07"]
384421

385422
# Check if a version is supported
386-
RubyLLM::MCP::Protocol.supported_version?("2025-06-18")
423+
RubyLLM::MCP::Native::Protocol.supported_version?("2025-06-18")
387424
# => true
388425
```
389426

0 commit comments

Comments
 (0)