rails-active-mcp 0.1.7 → 2.0.8
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 +4 -4
- data/README.md +106 -279
- data/changelog.md +69 -0
- data/docs/DEBUGGING.md +5 -5
- data/docs/README.md +130 -142
- data/examples/rails_app_integration.md +405 -0
- data/exe/rails-active-mcp-server +153 -76
- data/gemfiles/rails_7.1.gemfile +34 -0
- data/lib/generators/rails_active_mcp/install/install_generator.rb +19 -39
- data/lib/generators/rails_active_mcp/install/templates/README.md +134 -188
- data/lib/generators/rails_active_mcp/install/templates/initializer.rb +65 -28
- data/lib/generators/rails_active_mcp/install/templates/mcp.ru +7 -3
- data/lib/rails_active_mcp/configuration.rb +37 -98
- data/lib/rails_active_mcp/console_executor.rb +13 -3
- data/lib/rails_active_mcp/engine.rb +36 -24
- data/lib/rails_active_mcp/sdk/server.rb +183 -0
- data/lib/rails_active_mcp/sdk/tools/console_execute_tool.rb +103 -0
- data/lib/rails_active_mcp/sdk/tools/dry_run_tool.rb +73 -0
- data/lib/rails_active_mcp/sdk/tools/model_info_tool.rb +106 -0
- data/lib/rails_active_mcp/sdk/tools/safe_query_tool.rb +77 -0
- data/lib/rails_active_mcp/tasks.rake +236 -80
- data/lib/rails_active_mcp/version.rb +1 -1
- data/lib/rails_active_mcp.rb +5 -11
- data/rails_active_mcp.gemspec +62 -11
- metadata +83 -24
- data/app/controllers/rails_active_mcp/mcp_controller.rb +0 -80
- data/lib/rails_active_mcp/mcp_server.rb +0 -383
- data/lib/rails_active_mcp/railtie.rb +0 -70
- data/lib/rails_active_mcp/stdio_server.rb +0 -517
- data/lib/rails_active_mcp/tools/console_execute_tool.rb +0 -61
- data/lib/rails_active_mcp/tools/dry_run_tool.rb +0 -41
- data/lib/rails_active_mcp/tools/model_info_tool.rb +0 -70
- data/lib/rails_active_mcp/tools/safe_query_tool.rb +0 -41
data/docs/README.md
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
# Rails Active MCP Documentation
|
2
2
|
|
3
3
|
## Introduction
|
4
|
-
Rails Active MCP is a Ruby gem that integrates the Model Context Protocol (MCP) into Rails applications. It provides a secure, configurable, and
|
4
|
+
Rails Active MCP is a Ruby gem that integrates the Model Context Protocol (MCP) into Rails applications using the official MCP Ruby SDK. It provides a secure, configurable, and professional server for AI agents and developer tools to interact with your Rails app via the standardized MCP protocol.
|
5
5
|
|
6
6
|
## How It Works
|
7
|
-
- **
|
8
|
-
- **
|
9
|
-
- **
|
10
|
-
- **
|
7
|
+
- **Official MCP SDK**: Built on the official MCP Ruby SDK (`mcp` gem) for robust protocol handling
|
8
|
+
- **Professional Implementation**: Automatic instrumentation, timing, and error reporting
|
9
|
+
- **Tooling**: Exposes four powerful tools (console execution, model info, safe queries, code analysis) to MCP clients
|
10
|
+
- **Safety**: Advanced safety checks, read-only modes, and audit logging protect your application from dangerous operations
|
11
|
+
- **Integration**: Easily added to any Rails application via a generator, with simplified configuration
|
11
12
|
|
12
13
|
## MCP Protocol Overview
|
13
|
-
- **MCP**: The Model Context Protocol is a standard for structured, secure, and auditable access to application internals for AI agents and developer tools
|
14
|
-
- **
|
15
|
-
|
16
|
-
|
17
|
-
- `tools/call`: Executes a tool with given arguments.
|
18
|
-
- `resources/list` and `resources/read`: (Stubbed, for future resource access.)
|
19
|
-
- **JSON-RPC 2.0**: All communication uses JSON-RPC 2.0 over HTTP POST.
|
14
|
+
- **MCP**: The Model Context Protocol is a standard for structured, secure, and auditable access to application internals for AI agents and developer tools
|
15
|
+
- **Official SDK**: Uses the official MCP Ruby SDK for protocol compliance and future-proof compatibility
|
16
|
+
- **STDIO Transport**: Perfect for Claude Desktop integration
|
17
|
+
- **JSON-RPC 2.0**: All communication uses JSON-RPC 2.0 with automatic protocol handling
|
20
18
|
|
21
19
|
## Installation & Setup
|
22
20
|
1. Add to your Gemfile:
|
@@ -28,158 +26,148 @@ Rails Active MCP is a Ruby gem that integrates the Model Context Protocol (MCP)
|
|
28
26
|
bundle install
|
29
27
|
rails generate rails_active_mcp:install
|
30
28
|
```
|
31
|
-
This creates an initializer
|
29
|
+
This creates an initializer and sets up the Rails integration.
|
32
30
|
3. Start the server:
|
33
|
-
|
34
|
-
|
35
|
-
|
31
|
+
```bash
|
32
|
+
bundle exec rails-active-mcp-server
|
33
|
+
```
|
36
34
|
|
37
35
|
## Configuration
|
38
36
|
Edit `config/initializers/rails_active_mcp.rb`:
|
39
|
-
- Enable/disable the server
|
40
|
-
- Safety mode (production = strict)
|
41
|
-
- Allowed/blocked models
|
42
|
-
- Enable/disable mutation tools
|
43
|
-
- Audit log location
|
44
|
-
- Environment presets: `production_mode!`, `strict_mode!`, `permissive_mode!`
|
45
37
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
38
|
+
```ruby
|
39
|
+
RailsActiveMcp.configure do |config|
|
40
|
+
# Core configuration options
|
41
|
+
config.allowed_commands = %w[
|
42
|
+
ls pwd cat head tail grep find wc
|
43
|
+
rails console rails runner
|
44
|
+
bundle exec rspec bundle exec test
|
45
|
+
git status git log git diff
|
46
|
+
]
|
47
|
+
config.command_timeout = 30
|
48
|
+
config.enable_logging = true
|
49
|
+
config.log_level = :info
|
50
|
+
end
|
51
|
+
```
|
51
52
|
|
52
|
-
|
53
|
+
## Available Tools
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
- **Audit Logging**: All executions are logged to `log/rails_active_mcp.log`
|
58
|
-
- **Configurable**: Fine-tune what is allowed per environment
|
55
|
+
### 1. console_execute
|
56
|
+
**Purpose:**
|
57
|
+
Execute Ruby code in the Rails console context with safety checks and timeout protection.
|
59
58
|
|
60
|
-
|
61
|
-
-
|
62
|
-
-
|
59
|
+
**Features:**
|
60
|
+
- Built-in dangerous operation detection
|
61
|
+
- Configurable execution timeout
|
62
|
+
- All executions logged for audit
|
63
|
+
- Safe execution environment
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
- Follows standard Ruby/Rails conventions for gems, engines, and generators.
|
67
|
-
- MCP protocol compliance is maintained as per [modelcontextprotocol.io](https://modelcontextprotocol.io/introduction).
|
65
|
+
**Example Usage in Claude:**
|
66
|
+
> "Execute `User.where(active: true).count`"
|
68
67
|
|
69
|
-
|
68
|
+
---
|
70
69
|
|
71
|
-
###
|
70
|
+
### 2. model_info
|
72
71
|
**Purpose:**
|
73
|
-
|
74
|
-
|
75
|
-
**
|
76
|
-
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
80
|
-
|
81
|
-
**
|
82
|
-
|
83
|
-
- On error: Error message and class.
|
84
|
-
|
85
|
-
**Example Usage:**
|
86
|
-
```json
|
87
|
-
{
|
88
|
-
"method": "tools/call",
|
89
|
-
"params": {
|
90
|
-
"name": "rails_console_execute",
|
91
|
-
"arguments": {
|
92
|
-
"code": "User.count"
|
93
|
-
}
|
94
|
-
}
|
95
|
-
}
|
96
|
-
```
|
72
|
+
Get detailed information about Rails models including schema, associations, and validations.
|
73
|
+
|
74
|
+
**Features:**
|
75
|
+
- Schema information (column types, constraints, indexes)
|
76
|
+
- Association details (has_many, belongs_to, has_one relationships)
|
77
|
+
- Validation rules and constraints
|
78
|
+
- Available instance and class methods
|
79
|
+
|
80
|
+
**Example Usage in Claude:**
|
81
|
+
> "Show me the User model structure"
|
97
82
|
|
98
83
|
---
|
99
84
|
|
100
|
-
###
|
85
|
+
### 3. safe_query
|
101
86
|
**Purpose:**
|
102
|
-
|
103
|
-
|
104
|
-
**
|
105
|
-
-
|
106
|
-
-
|
107
|
-
-
|
108
|
-
-
|
109
|
-
|
110
|
-
**
|
111
|
-
|
112
|
-
- On error: Error message (e.g., model not found).
|
113
|
-
|
114
|
-
**Example Usage:**
|
115
|
-
```json
|
116
|
-
{
|
117
|
-
"method": "tools/call",
|
118
|
-
"params": {
|
119
|
-
"name": "rails_model_info",
|
120
|
-
"arguments": {
|
121
|
-
"model": "User"
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}
|
125
|
-
```
|
87
|
+
Execute safe, read-only database queries with automatic safety analysis.
|
88
|
+
|
89
|
+
**Features:**
|
90
|
+
- Read-only operations only (SELECT queries)
|
91
|
+
- Automatic query analysis for safety
|
92
|
+
- Result limiting to prevent large data dumps
|
93
|
+
- Works within your model definitions
|
94
|
+
|
95
|
+
**Example Usage in Claude:**
|
96
|
+
> "Get the 10 most recent orders"
|
126
97
|
|
127
98
|
---
|
128
99
|
|
129
|
-
###
|
100
|
+
### 4. dry_run
|
130
101
|
**Purpose:**
|
131
|
-
|
132
|
-
|
133
|
-
**
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
|
139
|
-
**
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
**
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
102
|
+
Analyze Ruby code for safety without executing it.
|
103
|
+
|
104
|
+
**Features:**
|
105
|
+
- Risk assessment and categorization
|
106
|
+
- Safety analysis with detailed feedback
|
107
|
+
- Recommendations for safer alternatives
|
108
|
+
- Zero execution guarantee
|
109
|
+
|
110
|
+
**Example Usage in Claude:**
|
111
|
+
> "Analyze this code for safety: `User.delete_all`"
|
112
|
+
|
113
|
+
## Security & Safety
|
114
|
+
- **Safety Checker**: Blocks dangerous operations (mass deletions, system commands, file access)
|
115
|
+
- **Read-Only Detection**: Identifies and promotes safe read-only operations
|
116
|
+
- **Audit Logging**: All executions are logged with detailed context
|
117
|
+
- **Configurable**: Fine-tune safety levels per environment
|
118
|
+
|
119
|
+
## Architecture
|
120
|
+
|
121
|
+
### Built on Official MCP Ruby SDK
|
122
|
+
Rails Active MCP leverages the official MCP Ruby SDK for:
|
123
|
+
|
124
|
+
- **Professional Protocol Handling**: Robust JSON-RPC 2.0 implementation
|
125
|
+
- **Built-in Instrumentation**: Automatic timing and error reporting
|
126
|
+
- **Future-Proof**: Automatic updates as MCP specification evolves
|
127
|
+
- **Standards Compliance**: Full MCP protocol compatibility
|
128
|
+
|
129
|
+
### Server Implementation
|
130
|
+
The server is implemented in `lib/rails_active_mcp/sdk/server.rb` and provides:
|
131
|
+
|
132
|
+
- **STDIO Transport**: Perfect for Claude Desktop integration
|
133
|
+
- **Tool Registration**: Automatic discovery of available tools
|
134
|
+
- **Error Handling**: Comprehensive error reporting and recovery
|
135
|
+
- **Rails Integration**: Deep integration with Rails applications
|
136
|
+
|
137
|
+
### Tool Architecture
|
138
|
+
Each tool is implemented as a separate class in `lib/rails_active_mcp/sdk/tools/`:
|
139
|
+
|
140
|
+
- `ConsoleExecuteTool`: Safe code execution
|
141
|
+
- `ModelInfoTool`: Model introspection
|
142
|
+
- `SafeQueryTool`: Read-only database access
|
143
|
+
- `DryRunTool`: Code safety analysis
|
144
|
+
|
145
|
+
## Testing & Development
|
146
|
+
|
147
|
+
### Running Tests
|
148
|
+
```bash
|
149
|
+
$ bundle exec rspec
|
157
150
|
```
|
158
151
|
|
159
|
-
|
152
|
+
### Testing MCP Integration
|
153
|
+
```bash
|
154
|
+
$ ./bin/test-mcp-output
|
155
|
+
```
|
160
156
|
|
161
|
-
###
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
**Input Parameters:**
|
166
|
-
- `code` (string, required): Ruby code to analyze.
|
167
|
-
|
168
|
-
**Output:**
|
169
|
-
- Code, safety status, read-only status, risk level, summary, violations, and recommendations.
|
170
|
-
|
171
|
-
**Example Usage:**
|
172
|
-
```json
|
173
|
-
{
|
174
|
-
"method": "tools/call",
|
175
|
-
"params": {
|
176
|
-
"name": "rails_dry_run",
|
177
|
-
"arguments": {
|
178
|
-
"code": "User.delete_all"
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
157
|
+
### Debugging
|
158
|
+
Set the debug environment variable for detailed logging:
|
159
|
+
```bash
|
160
|
+
$ RAILS_MCP_DEBUG=1 bundle exec rails-active-mcp-server
|
182
161
|
```
|
183
162
|
|
184
|
-
|
185
|
-
|
163
|
+
## Extending the Gem
|
164
|
+
The gem is designed to be extensible. You can add custom tools by:
|
165
|
+
|
166
|
+
1. Creating new tool classes in your application
|
167
|
+
2. Following the MCP tool interface pattern
|
168
|
+
3. Registering tools with the server during initialization
|
169
|
+
|
170
|
+
Each tool must implement the standard MCP tool interface with proper input schemas and error handling.
|
171
|
+
|
172
|
+
|
173
|
+
For more details, see the main project README or explore the source code in `lib/rails_active_mcp/sdk/`.
|