ruby_llm_swarm-mcp 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +277 -0
- data/lib/generators/ruby_llm/mcp/install/install_generator.rb +42 -0
- data/lib/generators/ruby_llm/mcp/install/templates/initializer.rb +56 -0
- data/lib/generators/ruby_llm/mcp/install/templates/mcps.yml +29 -0
- data/lib/generators/ruby_llm/mcp/oauth/install_generator.rb +354 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/concerns/mcp_token_storage.rb.tt +114 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/concerns/user_mcp_oauth_concern.rb.tt +90 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/controllers/mcp_connections_controller.rb.tt +239 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/jobs/cleanup_expired_oauth_states_job.rb.tt +27 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/jobs/example_job.rb.tt +78 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/lib/mcp_client.rb.tt +68 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/migrations/create_mcp_oauth_credentials.rb.tt +19 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/migrations/create_mcp_oauth_states.rb.tt +21 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/models/mcp_oauth_credential.rb.tt +54 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/models/mcp_oauth_state.rb.tt +30 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/views/index.html.erb +646 -0
- data/lib/generators/ruby_llm/mcp/oauth/templates/views/show.html.erb +560 -0
- data/lib/ruby_llm/chat.rb +34 -0
- data/lib/ruby_llm/mcp/adapters/base_adapter.rb +179 -0
- data/lib/ruby_llm/mcp/adapters/mcp_sdk_adapter.rb +292 -0
- data/lib/ruby_llm/mcp/adapters/mcp_transports/coordinator_stub.rb +33 -0
- data/lib/ruby_llm/mcp/adapters/mcp_transports/sse.rb +52 -0
- data/lib/ruby_llm/mcp/adapters/mcp_transports/stdio.rb +52 -0
- data/lib/ruby_llm/mcp/adapters/mcp_transports/streamable_http.rb +86 -0
- data/lib/ruby_llm/mcp/adapters/ruby_llm_adapter.rb +92 -0
- data/lib/ruby_llm/mcp/attachment.rb +18 -0
- data/lib/ruby_llm/mcp/auth/browser/callback_handler.rb +71 -0
- data/lib/ruby_llm/mcp/auth/browser/callback_server.rb +30 -0
- data/lib/ruby_llm/mcp/auth/browser/http_server.rb +112 -0
- data/lib/ruby_llm/mcp/auth/browser/opener.rb +39 -0
- data/lib/ruby_llm/mcp/auth/browser/pages.rb +607 -0
- data/lib/ruby_llm/mcp/auth/browser_oauth_provider.rb +280 -0
- data/lib/ruby_llm/mcp/auth/client_registrar.rb +170 -0
- data/lib/ruby_llm/mcp/auth/discoverer.rb +124 -0
- data/lib/ruby_llm/mcp/auth/flows/authorization_code_flow.rb +105 -0
- data/lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb +66 -0
- data/lib/ruby_llm/mcp/auth/grant_strategies/authorization_code.rb +31 -0
- data/lib/ruby_llm/mcp/auth/grant_strategies/base.rb +31 -0
- data/lib/ruby_llm/mcp/auth/grant_strategies/client_credentials.rb +31 -0
- data/lib/ruby_llm/mcp/auth/http_response_handler.rb +63 -0
- data/lib/ruby_llm/mcp/auth/memory_storage.rb +90 -0
- data/lib/ruby_llm/mcp/auth/oauth_provider.rb +305 -0
- data/lib/ruby_llm/mcp/auth/security.rb +44 -0
- data/lib/ruby_llm/mcp/auth/session_manager.rb +54 -0
- data/lib/ruby_llm/mcp/auth/token_manager.rb +236 -0
- data/lib/ruby_llm/mcp/auth/transport_oauth_helper.rb +107 -0
- data/lib/ruby_llm/mcp/auth/url_builder.rb +76 -0
- data/lib/ruby_llm/mcp/auth.rb +359 -0
- data/lib/ruby_llm/mcp/client.rb +401 -0
- data/lib/ruby_llm/mcp/completion.rb +16 -0
- data/lib/ruby_llm/mcp/configuration.rb +310 -0
- data/lib/ruby_llm/mcp/content.rb +28 -0
- data/lib/ruby_llm/mcp/elicitation.rb +48 -0
- data/lib/ruby_llm/mcp/error.rb +34 -0
- data/lib/ruby_llm/mcp/errors.rb +91 -0
- data/lib/ruby_llm/mcp/logging.rb +16 -0
- data/lib/ruby_llm/mcp/native/cancellable_operation.rb +57 -0
- data/lib/ruby_llm/mcp/native/client.rb +387 -0
- data/lib/ruby_llm/mcp/native/json_rpc.rb +170 -0
- data/lib/ruby_llm/mcp/native/messages/helpers.rb +39 -0
- data/lib/ruby_llm/mcp/native/messages/notifications.rb +42 -0
- data/lib/ruby_llm/mcp/native/messages/requests.rb +206 -0
- data/lib/ruby_llm/mcp/native/messages/responses.rb +106 -0
- data/lib/ruby_llm/mcp/native/messages.rb +36 -0
- data/lib/ruby_llm/mcp/native/notification.rb +16 -0
- data/lib/ruby_llm/mcp/native/protocol.rb +36 -0
- data/lib/ruby_llm/mcp/native/response_handler.rb +110 -0
- data/lib/ruby_llm/mcp/native/transport.rb +88 -0
- data/lib/ruby_llm/mcp/native/transports/sse.rb +607 -0
- data/lib/ruby_llm/mcp/native/transports/stdio.rb +356 -0
- data/lib/ruby_llm/mcp/native/transports/streamable_http.rb +926 -0
- data/lib/ruby_llm/mcp/native/transports/support/http_client.rb +28 -0
- data/lib/ruby_llm/mcp/native/transports/support/rate_limit.rb +49 -0
- data/lib/ruby_llm/mcp/native/transports/support/timeout.rb +36 -0
- data/lib/ruby_llm/mcp/native.rb +12 -0
- data/lib/ruby_llm/mcp/notification_handler.rb +100 -0
- data/lib/ruby_llm/mcp/progress.rb +35 -0
- data/lib/ruby_llm/mcp/prompt.rb +132 -0
- data/lib/ruby_llm/mcp/railtie.rb +14 -0
- data/lib/ruby_llm/mcp/resource.rb +112 -0
- data/lib/ruby_llm/mcp/resource_template.rb +85 -0
- data/lib/ruby_llm/mcp/result.rb +108 -0
- data/lib/ruby_llm/mcp/roots.rb +45 -0
- data/lib/ruby_llm/mcp/sample.rb +152 -0
- data/lib/ruby_llm/mcp/server_capabilities.rb +49 -0
- data/lib/ruby_llm/mcp/tool.rb +228 -0
- data/lib/ruby_llm/mcp/version.rb +7 -0
- data/lib/ruby_llm/mcp.rb +125 -0
- data/lib/tasks/release.rake +23 -0
- metadata +184 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c5ee1e3f459d8555cc547963bd6470dfa16e14c0c57e788064e604084dc6909b
|
|
4
|
+
data.tar.gz: 7b423a5ec9acd5a9554c3a6903bfde6536e30e9c5d5ab9c01aa484cab7bd0fa7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: c144bc4598c9aaff5155f84e188a5b8adb8543caaea84c3d55b244eca0f98f3ed90de465233b2f0887e1231c65e32375b0ea6832fc8ee734693f602e610beada
|
|
7
|
+
data.tar.gz: 5b7d3e98e3126921e49e34a9b9569dbabf21fa5125e6e5342bcaab25b367da38fb13abd751bc9c267f591501fbbdd0d712e07e1d6d393682d3a6cbdc409c725a
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Patrick Vice
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
<img src="/docs/assets/images/rubyllm-mcp-logo-text.svg" alt="RubyLLM" height="120" width="250">
|
|
2
|
+
|
|
3
|
+
**Aiming to make using MCPs with RubyLLM and Ruby as easy as possible.**
|
|
4
|
+
|
|
5
|
+
This project is a Ruby client for the [Model Context Protocol (MCP)](https://modelcontextprotocol.io/), designed to work seamlessly with [RubyLLM](https://github.com/crmne/ruby_llm). This gem enables Ruby applications to connect to MCP servers and use their tools, resources and prompts as part of LLM conversations.
|
|
6
|
+
|
|
7
|
+
For a more detailed guide, see the [RubyLLM::MCP docs](https://rubyllm-mcp.com/).
|
|
8
|
+
|
|
9
|
+
Currently full support for MCP protocol version up to `2025-06-18`.
|
|
10
|
+
|
|
11
|
+
<div class="badge-container">
|
|
12
|
+
<a href="https://badge.fury.io/rb/ruby_llm-mcp"><img src="https://badge.fury.io/rb/ruby_llm-mcp.svg" alt="Gem Version" /></a>
|
|
13
|
+
<a href="https://rubygems.org/gems/ruby_llm-mcp"><img alt="Gem Downloads" src="https://img.shields.io/gem/dt/ruby_llm-mcp"></a>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
## RubyLLM::MCP Features
|
|
17
|
+
|
|
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
|
|
20
|
+
- 🛠️ **Tool Integration**: Automatically converts MCP tools into RubyLLM-compatible tools
|
|
21
|
+
- 📄 **Resource Management**: Access and include MCP resources (files, data) and resource templates in conversations
|
|
22
|
+
- 🎯 **Prompt Integration**: Use predefined MCP prompts with arguments for consistent interactions
|
|
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
|
|
25
|
+
- 🔄 **Multiple Client Management**: Create and manage multiple MCP clients simultaneously for different servers and purposes
|
|
26
|
+
- 📚 **Simple API**: Easy-to-use interface that integrates seamlessly with RubyLLM
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
bundle add ruby_llm-mcp
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
or add this line to your application's Gemfile:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
gem 'ruby_llm-mcp'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
And then execute:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
bundle install
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or install it yourself as:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
gem install ruby_llm-mcp
|
|
50
|
+
```
|
|
51
|
+
|
|
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
|
+
|
|
92
|
+
## Usage
|
|
93
|
+
|
|
94
|
+
### Basic Setup
|
|
95
|
+
|
|
96
|
+
First, configure your RubyLLM client and create an MCP connection:
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
require 'ruby_llm/mcp'
|
|
100
|
+
|
|
101
|
+
# Configure RubyLLM
|
|
102
|
+
RubyLLM.configure do |config|
|
|
103
|
+
config.openai_api_key = "your-api-key"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Connect to an MCP server via SSE
|
|
107
|
+
client = RubyLLM::MCP.client(
|
|
108
|
+
name: "my-mcp-server",
|
|
109
|
+
transport_type: :sse,
|
|
110
|
+
config: {
|
|
111
|
+
url: "http://localhost:9292/mcp/sse"
|
|
112
|
+
}
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Or connect via stdio
|
|
116
|
+
client = RubyLLM::MCP.client(
|
|
117
|
+
name: "my-mcp-server",
|
|
118
|
+
transport_type: :stdio,
|
|
119
|
+
config: {
|
|
120
|
+
command: "node",
|
|
121
|
+
args: ["path/to/mcp-server.js"],
|
|
122
|
+
env: { "NODE_ENV" => "production" }
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Or connect via streamable HTTP
|
|
127
|
+
client = RubyLLM::MCP.client(
|
|
128
|
+
name: "my-mcp-server",
|
|
129
|
+
transport_type: :streamable,
|
|
130
|
+
config: {
|
|
131
|
+
url: "http://localhost:8080/mcp",
|
|
132
|
+
headers: { "Authorization" => "Bearer your-token" }
|
|
133
|
+
}
|
|
134
|
+
)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Using MCP Tools with RubyLLM
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
# Get available tools from the MCP server
|
|
141
|
+
tools = client.tools
|
|
142
|
+
puts "Available tools:"
|
|
143
|
+
tools.each do |tool|
|
|
144
|
+
puts "- #{tool.name}: #{tool.description}"
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Create a chat session with MCP tools
|
|
148
|
+
chat = RubyLLM.chat(model: "gpt-4")
|
|
149
|
+
chat.with_tools(*client.tools)
|
|
150
|
+
|
|
151
|
+
# Ask a question that will use the MCP tools
|
|
152
|
+
response = chat.ask("Can you help me search for recent files in my project?")
|
|
153
|
+
puts response
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Manual Tool Execution
|
|
157
|
+
|
|
158
|
+
You can also execute MCP tools directly:
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
# Tools Execution
|
|
162
|
+
tool = client.tool("search_files")
|
|
163
|
+
|
|
164
|
+
# Execute a specific tool
|
|
165
|
+
result = tool.execute(
|
|
166
|
+
name: "search_files",
|
|
167
|
+
parameters: {
|
|
168
|
+
query: "*.rb",
|
|
169
|
+
directory: "/path/to/search"
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
puts result
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Working with Resources
|
|
177
|
+
|
|
178
|
+
MCP servers can provide access to resources - structured data that can be included in conversations. Resources come in two types: normal resources and resource templates.
|
|
179
|
+
|
|
180
|
+
#### Normal Resources
|
|
181
|
+
|
|
182
|
+
```ruby
|
|
183
|
+
# Get available resources from the MCP server
|
|
184
|
+
resources = client.resources
|
|
185
|
+
puts "Available resources:"
|
|
186
|
+
resources.each do |resource|
|
|
187
|
+
puts "- #{resource.name}: #{resource.description}"
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Access a specific resource by name
|
|
191
|
+
file_resource = client.resource("project_readme")
|
|
192
|
+
content = file_resource.content
|
|
193
|
+
puts "Resource content: #{content}"
|
|
194
|
+
|
|
195
|
+
# Include a resource in a chat conversation for reference with an LLM
|
|
196
|
+
chat = RubyLLM.chat(model: "gpt-4")
|
|
197
|
+
chat.with_resource(file_resource)
|
|
198
|
+
|
|
199
|
+
# Or add a resource directly to the conversation
|
|
200
|
+
file_resource.include(chat)
|
|
201
|
+
|
|
202
|
+
response = chat.ask("Can you summarize this README file?")
|
|
203
|
+
puts response
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
#### Resource Templates
|
|
207
|
+
|
|
208
|
+
Resource templates are parameterized resources that can be dynamically configured:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
# Get available resource templates
|
|
212
|
+
templates = client.resource_templates
|
|
213
|
+
log_template = client.resource_template("application_logs")
|
|
214
|
+
|
|
215
|
+
# Use a template with parameters
|
|
216
|
+
chat = RubyLLM.chat(model: "gpt-4")
|
|
217
|
+
chat.with_resource_template(log_template, arguments: {
|
|
218
|
+
date: "2024-01-15",
|
|
219
|
+
level: "error"
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
response = chat.ask("What errors occurred on this date?")
|
|
223
|
+
puts response
|
|
224
|
+
|
|
225
|
+
# You can also get templated content directly
|
|
226
|
+
content = log_template.to_content(arguments: {
|
|
227
|
+
date: "2024-01-15",
|
|
228
|
+
level: "error"
|
|
229
|
+
})
|
|
230
|
+
puts content
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### Working with Prompts
|
|
234
|
+
|
|
235
|
+
MCP servers can provide predefined prompts that can be used in conversations:
|
|
236
|
+
|
|
237
|
+
```ruby
|
|
238
|
+
# Get available prompts from the MCP server
|
|
239
|
+
prompts = client.prompts
|
|
240
|
+
puts "Available prompts:"
|
|
241
|
+
prompts.each do |prompt|
|
|
242
|
+
puts "- #{prompt.name}: #{prompt.description}"
|
|
243
|
+
prompt.arguments.each do |arg|
|
|
244
|
+
puts " - #{arg.name}: #{arg.description} (required: #{arg.required})"
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Use a prompt in a conversation
|
|
249
|
+
greeting_prompt = client.prompt("daily_greeting")
|
|
250
|
+
chat = RubyLLM.chat(model: "gpt-4")
|
|
251
|
+
|
|
252
|
+
# Method 1: Ask prompt directly
|
|
253
|
+
response = chat.ask_prompt(greeting_prompt, arguments: { name: "Alice", time: "morning" })
|
|
254
|
+
puts response
|
|
255
|
+
|
|
256
|
+
# Method 2: Add prompt to chat and then ask
|
|
257
|
+
chat.with_prompt(greeting_prompt, arguments: { name: "Alice", time: "morning" })
|
|
258
|
+
response = chat.ask("Continue with the greeting")
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
After checking out the repo, run `bundle` to install dependencies. Then, run `bundle exec rake` to run the tests. Tests currently use `bun` to run test MCP servers You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
264
|
+
|
|
265
|
+
There are also examples you you can run to verify the gem is working as expected.
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
bundle exec ruby examples/tools/local_mcp.rb
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Contributing
|
|
272
|
+
|
|
273
|
+
We welcome contributions! Bug reports and pull requests are welcome on GitHub at https://github.com/patvice/ruby_llm-mcp.
|
|
274
|
+
|
|
275
|
+
## License
|
|
276
|
+
|
|
277
|
+
Released under the MIT License.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/generators/base"
|
|
4
|
+
|
|
5
|
+
module RubyLLM
|
|
6
|
+
module MCP
|
|
7
|
+
module Generators
|
|
8
|
+
class InstallGenerator < Rails::Generators::Base
|
|
9
|
+
source_root File.expand_path("templates", __dir__)
|
|
10
|
+
|
|
11
|
+
namespace "ruby_llm:mcp:install"
|
|
12
|
+
|
|
13
|
+
desc "Install RubyLLM MCP configuration files"
|
|
14
|
+
|
|
15
|
+
def create_initializer
|
|
16
|
+
template "initializer.rb", "config/initializers/ruby_llm_mcp.rb"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create_config_file
|
|
20
|
+
template "mcps.yml", "config/mcps.yml"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def display_readme
|
|
24
|
+
return unless behavior == :invoke
|
|
25
|
+
|
|
26
|
+
say "✅ RubyLLM MCP installed!", :green
|
|
27
|
+
say ""
|
|
28
|
+
say "Next steps:", :blue
|
|
29
|
+
say " 1. Configure config/initializers/ruby_llm_mcp.rb (main settings)"
|
|
30
|
+
say " 2. Define servers in config/mcps.yml"
|
|
31
|
+
say " 3. Install MCP servers (e.g., npm install @modelcontextprotocol/server-filesystem)"
|
|
32
|
+
say " 4. Set environment variables for authentication"
|
|
33
|
+
say ""
|
|
34
|
+
say "📚 Full docs: https://www.rubyllm-mcp.com/", :cyan
|
|
35
|
+
say ""
|
|
36
|
+
say "⭐ Help us improve!", :magenta
|
|
37
|
+
say " Report issues or show your support with a GitHub star: https://github.com/patvice/ruby_llm-mcp"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Configure RubyLLM MCP
|
|
4
|
+
RubyLLM::MCP.configure do |config|
|
|
5
|
+
# Default SDK adapter to use (:ruby_llm or :mcp_sdk)
|
|
6
|
+
# - :ruby_llm: Full-featured, supports all MCP features + extensions
|
|
7
|
+
# - :mcp_sdk: Official SDK, limited features but maintained by Anthropic
|
|
8
|
+
config.default_adapter = :ruby_llm
|
|
9
|
+
|
|
10
|
+
# Request timeout in milliseconds
|
|
11
|
+
config.request_timeout = 8000
|
|
12
|
+
|
|
13
|
+
# Maximum connections in the pool
|
|
14
|
+
config.max_connections = Float::INFINITY
|
|
15
|
+
|
|
16
|
+
# Pool timeout in seconds
|
|
17
|
+
config.pool_timeout = 5
|
|
18
|
+
|
|
19
|
+
# Path to MCPs configuration file
|
|
20
|
+
config.config_path = Rails.root.join("config", "mcps.yml")
|
|
21
|
+
|
|
22
|
+
# Launch MCPs (:automatic, :manual)
|
|
23
|
+
config.launch_control = :automatic
|
|
24
|
+
|
|
25
|
+
# Configure roots for file system access (RubyLLM adapter only)
|
|
26
|
+
# config.roots = [
|
|
27
|
+
# Rails.root.to_s
|
|
28
|
+
# ]
|
|
29
|
+
|
|
30
|
+
# Configure sampling (RubyLLM adapter only)
|
|
31
|
+
config.sampling.enabled = false
|
|
32
|
+
|
|
33
|
+
# Set preferred model for sampling
|
|
34
|
+
# config.sampling.preferred_model do
|
|
35
|
+
# "claude-sonnet-4"
|
|
36
|
+
# end
|
|
37
|
+
|
|
38
|
+
# Set a guard for sampling
|
|
39
|
+
# config.sampling.guard do
|
|
40
|
+
# Rails.env.development?
|
|
41
|
+
# end
|
|
42
|
+
|
|
43
|
+
# Event handlers (RubyLLM adapter only)
|
|
44
|
+
# config.on_progress do |progress_token, progress, total|
|
|
45
|
+
# # Handle progress updates
|
|
46
|
+
# end
|
|
47
|
+
|
|
48
|
+
# config.on_human_in_the_loop do |tool_name, arguments|
|
|
49
|
+
# # Return true to allow, false to deny
|
|
50
|
+
# true
|
|
51
|
+
# end
|
|
52
|
+
|
|
53
|
+
# config.on_logging do |level, logger_name, data|
|
|
54
|
+
# # Handle logging from MCP servers
|
|
55
|
+
# end
|
|
56
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
mcp_servers:
|
|
2
|
+
filesystem:
|
|
3
|
+
# SDK adapter to use (optional, defaults to config.default_adapter)
|
|
4
|
+
# Options: ruby_llm, mcp_sdk
|
|
5
|
+
# adapter: ruby_llm
|
|
6
|
+
|
|
7
|
+
transport_type: stdio
|
|
8
|
+
command: npx
|
|
9
|
+
args:
|
|
10
|
+
- "@modelcontextprotocol/server-filesystem"
|
|
11
|
+
- "<%%= Rails.root %>"
|
|
12
|
+
env: {}
|
|
13
|
+
with_prefix: true
|
|
14
|
+
|
|
15
|
+
# Example with MCP SDK (official)
|
|
16
|
+
# weather:
|
|
17
|
+
# adapter: mcp_sdk
|
|
18
|
+
# transport_type: http
|
|
19
|
+
# url: "https://api.example.com/mcp"
|
|
20
|
+
# headers:
|
|
21
|
+
# Authorization: "Bearer <%%= ENV['WEATHER_API_KEY'] %>"
|
|
22
|
+
|
|
23
|
+
# Example with SSE (RubyLLM adapter only)
|
|
24
|
+
# notifications:
|
|
25
|
+
# adapter: ruby_llm
|
|
26
|
+
# transport_type: sse
|
|
27
|
+
# url: "https://api.example.com/mcp/sse"
|
|
28
|
+
# headers:
|
|
29
|
+
# Authorization: "Bearer <%%= ENV['API_KEY'] %>"
|