You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: "Understanding and using MCP adapters in RubyLLM"
5
+
nav_order: 4
6
+
description: "Understanding MCP adapters, transports, and building custom transport implementations"
7
7
---
8
8
9
-
# Adapters
9
+
# Adapters & Transports
10
10
{: .no_toc }
11
11
12
12
{: .label .label-green }
13
-
0.8+
13
+
1.0+
14
14
15
-
Starting with version 0.8.0, RubyLLM MCP supports multiple SDK adapters, allowing you to choose between the native full-featured implementation or the official MCP SDK.
15
+
RubyLLM MCP 1.0 provides a mature, stable adapter system with multiple SDK implementations and transport types, giving you complete control over how your application communicates with MCP servers.
16
16
17
17
## Table of contents
18
18
{: .no_toc .text-delta }
@@ -24,43 +24,48 @@ Starting with version 0.8.0, RubyLLM MCP supports multiple SDK adapters, allowin
24
24
25
25
## Overview
26
26
27
-
The adapter pattern in RubyLLM MCP allows you to choose which SDK implementation powers your MCP clients. This gives you flexibility to:
27
+
RubyLLM MCP provides two key architectural components:
28
28
29
-
- Use the native `:ruby_llm` adapter for full MCP feature support build inside the gem
30
-
- Use the official `:mcp_sdk` adapter (still under development, but making great progress)
29
+
**Adapters** - Choose which SDK implementation powers your MCP clients:
30
+
- Use the native `:ruby_llm` adapter for full MCP feature support built inside the gem
31
+
- Use the official `:mcp_sdk` adapter maintained by Anthropic (requires Ruby 3.2+)
31
32
- Mix both adapters in the same application for different servers
32
33
34
+
**Transports** - Handle the communication layer between your Ruby client and MCP servers:
35
+
- Establish connections
36
+
- Send requests and receive responses
37
+
- Manage the connection lifecycle
38
+
- Handle protocol-specific details
39
+
33
40
## Available Adapters
34
41
35
42
### RubyLLM Adapter (`:ruby_llm`)
36
43
37
44
The default, full-featured adapter that implements the complete MCP protocol with extensions.
38
45
39
-
**When to use:**
40
-
-You need advanced features like sampling, roots, or progress tracking
41
-
-You want SSE transport support
42
-
-You need human-in-the-loop approvals
43
-
-You're using elicitation for interactive workflows
46
+
**Key Features:**
47
+
-✅ Complete MCP protocol implementation with advanced features (sampling, roots, progress tracking, elicitation)
48
+
-✅ All transport types supported (stdio, SSE, streamable HTTP)
49
+
-✅ **Custom transport support** - Register and use your own transport implementations
50
+
-✅ Ruby 2.7+ compatible
44
51
45
-
**Advantages:**
46
-
- Complete MCP protocol implementation
47
-
- All transport types supported
48
-
- Additional features beyond core spec
49
-
- Optimized for RubyLLM integration
52
+
**Best for:** Full-featured MCP integrations, custom transport requirements, and advanced protocol features.
50
53
51
54
### MCP SDK Adapter (`:mcp_sdk`)
52
55
53
56
Wraps the official MCP SDK maintained by Anthropic.
54
57
55
-
**When to use:**
56
-
- You prefer the official Anthropic-maintained implementation
57
-
- You only need core MCP features (tools, resources, prompts)
58
-
- You want to ensure compatibility with the reference implementation
58
+
{: .important }
59
+
> **Ruby 3.2+ Required**
60
+
> The official `mcp` gem requires Ruby 3.2 or higher. If you're using an older Ruby version, use the `:ruby_llm` adapter instead.
61
+
62
+
**Key Features:**
63
+
- ✅ Official Anthropic-maintained implementation
64
+
- ✅ Core MCP features (tools, resources, prompts)
65
+
- ✅ Basic transports (stdio, HTTP) with custom wrapper support
66
+
- ⚠️ No custom transport registration - requires Ruby 3.2+
59
67
60
-
**Advantages:**
61
-
- Official Anthropic support
62
-
- Reference implementation compatibility
63
-
- Simpler, focused feature set
68
+
**Best for:** Reference implementation compatibility and core MCP features only.
64
69
65
70
## Feature Comparison
66
71
@@ -98,6 +103,113 @@ Custom transports are implemented by the adapter and are not part of the officia
98
103
|`:streamable_http`| ✅ | Custom |
99
104
|`:sse`| ✅ | Custom |
100
105
106
+
---
107
+
108
+
## Built-in Transport Types
109
+
110
+
### STDIO Transport
111
+
112
+
Best for local MCP servers that communicate via standard input/output:
113
+
114
+
```ruby
115
+
client =RubyLLM::MCP.client(
116
+
name:"local-server",
117
+
transport_type::stdio,
118
+
config: {
119
+
command:"python",
120
+
args: ["-m", "my_mcp_server"],
121
+
env: { "DEBUG" => "1" }
122
+
}
123
+
)
124
+
```
125
+
126
+
**Use cases:**
127
+
128
+
- Local development
129
+
- Command-line MCP servers
130
+
- Subprocess-based servers
131
+
132
+
### SSE Transport (Server-Sent Events)
133
+
134
+
Best for web-based MCP servers using HTTP with server-sent events:
135
+
136
+
```ruby
137
+
client =RubyLLM::MCP.client(
138
+
name:"web-server",
139
+
transport_type::sse,
140
+
config: {
141
+
url:"https://api.example.com/mcp/sse",
142
+
version::http2, # You can force HTTP/1.1 by setting this to :http1, default will try to setup HTTP/2 connection
143
+
headers: { "Authorization" => "Bearer token" }
144
+
}
145
+
)
146
+
```
147
+
148
+
**Use cases:**
149
+
150
+
- Web-based MCP services
151
+
- Real-time communication needs
152
+
- HTTP-based infrastructure
153
+
154
+
### Streamable HTTP Transport
155
+
156
+
Best for HTTP-based MCP servers that support streaming responses:
157
+
158
+
```ruby
159
+
client =RubyLLM::MCP.client(
160
+
name:"streaming-server",
161
+
transport_type::streamable,
162
+
config: {
163
+
url:"https://api.example.com/mcp",
164
+
version::http2, # You can force HTTP/1.1 by setting this to :http1, default will try to setup HTTP/2 connection
165
+
headers: { "Content-Type" => "application/json" }
166
+
}
167
+
)
168
+
```
169
+
170
+
#### OAuth Authentication
171
+
172
+
{: .new }
173
+
OAuth authentication is available in MCP Protocol 2025-06-18 for Streamable HTTP transport.
174
+
175
+
For servers requiring OAuth authentication:
176
+
177
+
```ruby
178
+
client =RubyLLM::MCP.client(
179
+
name:"oauth-server",
180
+
transport_type::streamable,
181
+
config: {
182
+
url:"https://api.example.com/mcp",
183
+
oauth: {
184
+
issuer:"https://oauth.provider.com",
185
+
client_id:"your-client-id",
186
+
client_secret:"your-client-secret",
187
+
scope:"mcp:read mcp:write"# Optional
188
+
}
189
+
}
190
+
)
191
+
```
192
+
193
+
**OAuth Configuration:**
194
+
195
+
| Option | Description | Required |
196
+
|--------|-------------|----------|
197
+
|`issuer`| OAuth provider's issuer URL | Yes |
198
+
|`client_id`| OAuth client identifier | Yes |
199
+
|`client_secret`| OAuth client secret | Yes |
200
+
|`scope`| Requested OAuth scopes | No |
201
+
202
+
The client automatically handles token acquisition, refresh, and authorization headers.
203
+
204
+
**Use cases:**
205
+
206
+
- REST API-based MCP servers
207
+
- HTTP-first architectures
208
+
- Cloud-based MCP services
209
+
- Enterprise servers requiring OAuth
210
+
211
+
---
212
+
101
213
## Configuration
102
214
103
215
### Global Default Adapter
@@ -163,11 +275,15 @@ mcp_servers:
163
275
164
276
### Installation
165
277
278
+
{: .warning }
279
+
> **Ruby 3.2+ Required**
280
+
> The official `mcp` gem requires Ruby 3.2 or higher. Ensure your Ruby version is compatible before proceeding.
281
+
166
282
The official MCP SDK is an optional dependency. Add it to your Gemfile when using the `:mcp_sdk` adapter:
167
283
168
284
```ruby
169
-
gem 'ruby_llm-mcp', '~> 0.8'
170
-
gem 'mcp', '~> 0.4' # Required for mcp_sdk adapter
0 commit comments