rails-active-mcp 0.1.1
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/.idea/.gitignore +8 -0
- data/.idea/discord.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/rails-active-mcp-gem.iml +111 -0
- data/.idea/vcs.xml +6 -0
- data/README.md +369 -0
- data/changelog.md +59 -0
- data/docs/README.md +185 -0
- data/exe/rails-active-mcp-server +24 -0
- data/lib/generators/rails_active_mcp/install/install_generator.rb +37 -0
- data/lib/generators/rails_active_mcp/install/templates/README.md +60 -0
- data/lib/generators/rails_active_mcp/install/templates/initializer.rb +39 -0
- data/lib/generators/rails_active_mcp/install/templates/mcp.ru +7 -0
- data/lib/rails_active_mcp/configuration.rb +95 -0
- data/lib/rails_active_mcp/console_executor.rb +378 -0
- data/lib/rails_active_mcp/engine.rb +32 -0
- data/lib/rails_active_mcp/mcp_server.rb +374 -0
- data/lib/rails_active_mcp/railtie.rb +48 -0
- data/lib/rails_active_mcp/safety_checker.rb +149 -0
- data/lib/rails_active_mcp/tasks.rake +154 -0
- data/lib/rails_active_mcp/tools/console_execute_tool.rb +61 -0
- data/lib/rails_active_mcp/tools/dry_run_tool.rb +41 -0
- data/lib/rails_active_mcp/tools/model_info_tool.rb +70 -0
- data/lib/rails_active_mcp/tools/safe_query_tool.rb +41 -0
- data/lib/rails_active_mcp/version.rb +5 -0
- data/lib/rails_active_mcp.rb +59 -0
- data/mcp.ru +5 -0
- data/rails_active_mcp.gemspec +49 -0
- metadata +241 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c88ad5ec7c769714d518060dff566fd4578f8831b02128be92f3f741d481886f
|
4
|
+
data.tar.gz: a57f58673130bfd1d3a66847cdcdf16c1b1629f1bb82a28ed75fb8ff44a01acc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ddb8d8c4627ea15b8290923c1dc00edb8e98e34ef6c26bf3b0ecce25c5cbb72cad22a7df5aa2d2bd4f7b878a8ac584b7df73f3e08128af10624aa0c0d3592997
|
7
|
+
data.tar.gz: 50ca2b25b14d8e927f916ce21cfca0c19d0bbd287aafd56416ef379174fffe5ee7959e29a6d6da1f5e95cec9b83e4b4fa352d68d3eb5778f75065e83f674febe
|
data/.idea/.gitignore
ADDED
data/.idea/discord.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/rails-active-mcp-gem.iml" filepath="$PROJECT_DIR$/.idea/rails-active-mcp-gem.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
@@ -0,0 +1,111 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="jdk" jdkName="asdf: 3.4.2" jdkType="RUBY_SDK" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="actioncable (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="actionmailbox (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="actionmailer (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="actionpack (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="actiontext (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="actionview (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="activejob (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="activemodel (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="activerecord (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="activestorage (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.3, asdf: 3.4.2) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="base64 (v0.3.0, asdf: 3.4.2) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="benchmark (v0.4.1, asdf: 3.4.2) [gem]" level="application" />
|
28
|
+
<orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.2.2, asdf: 3.4.2) [gem]" level="application" />
|
29
|
+
<orderEntry type="library" scope="PROVIDED" name="builder (v3.3.0, asdf: 3.4.2) [gem]" level="application" />
|
30
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.6.9, asdf: 3.4.2) [gem]" level="application" />
|
31
|
+
<orderEntry type="library" scope="PROVIDED" name="byebug (v12.0.0, asdf: 3.4.2) [gem]" level="application" />
|
32
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.3.5, asdf: 3.4.2) [gem]" level="application" />
|
33
|
+
<orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.5.3, asdf: 3.4.2) [gem]" level="application" />
|
34
|
+
<orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, asdf: 3.4.2) [gem]" level="application" />
|
35
|
+
<orderEntry type="library" scope="PROVIDED" name="date (v3.4.1, asdf: 3.4.2) [gem]" level="application" />
|
36
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.2, asdf: 3.4.2) [gem]" level="application" />
|
37
|
+
<orderEntry type="library" scope="PROVIDED" name="drb (v2.2.3, asdf: 3.4.2) [gem]" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="erb (v5.0.1, asdf: 3.4.2) [gem]" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="erubi (v1.13.1, asdf: 3.4.2) [gem]" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="factory_bot (v6.5.4, asdf: 3.4.2) [gem]" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="factory_bot_rails (v6.5.0, asdf: 3.4.2) [gem]" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="globalid (v1.2.1, asdf: 3.4.2) [gem]" level="application" />
|
43
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.7, asdf: 3.4.2) [gem]" level="application" />
|
44
|
+
<orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.0, asdf: 3.4.2) [gem]" level="application" />
|
45
|
+
<orderEntry type="library" scope="PROVIDED" name="irb (v1.15.2, asdf: 3.4.2) [gem]" level="application" />
|
46
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.12.2, asdf: 3.4.2) [gem]" level="application" />
|
47
|
+
<orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.5, asdf: 3.4.2) [gem]" level="application" />
|
48
|
+
<orderEntry type="library" scope="PROVIDED" name="lint_roller (v1.1.0, asdf: 3.4.2) [gem]" level="application" />
|
49
|
+
<orderEntry type="library" scope="PROVIDED" name="logger (v1.7.0, asdf: 3.4.2) [gem]" level="application" />
|
50
|
+
<orderEntry type="library" scope="PROVIDED" name="loofah (v2.24.1, asdf: 3.4.2) [gem]" level="application" />
|
51
|
+
<orderEntry type="library" scope="PROVIDED" name="mail (v2.8.1, asdf: 3.4.2) [gem]" level="application" />
|
52
|
+
<orderEntry type="library" scope="PROVIDED" name="marcel (v1.0.4, asdf: 3.4.2) [gem]" level="application" />
|
53
|
+
<orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.1.5, asdf: 3.4.2) [gem]" level="application" />
|
54
|
+
<orderEntry type="library" scope="PROVIDED" name="mini_portile2 (v2.8.9, asdf: 3.4.2) [gem]" level="application" />
|
55
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.25.5, asdf: 3.4.2) [gem]" level="application" />
|
56
|
+
<orderEntry type="library" scope="PROVIDED" name="net-imap (v0.5.9, asdf: 3.4.2) [gem]" level="application" />
|
57
|
+
<orderEntry type="library" scope="PROVIDED" name="net-pop (v0.1.2, asdf: 3.4.2) [gem]" level="application" />
|
58
|
+
<orderEntry type="library" scope="PROVIDED" name="net-protocol (v0.2.2, asdf: 3.4.2) [gem]" level="application" />
|
59
|
+
<orderEntry type="library" scope="PROVIDED" name="net-smtp (v0.5.1, asdf: 3.4.2) [gem]" level="application" />
|
60
|
+
<orderEntry type="library" scope="PROVIDED" name="nio4r (v2.7.4, asdf: 3.4.2) [gem]" level="application" />
|
61
|
+
<orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.18.8, asdf: 3.4.2) [gem]" level="application" />
|
62
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, asdf: 3.4.2) [gem]" level="application" />
|
63
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.3.8.0, asdf: 3.4.2) [gem]" level="application" />
|
64
|
+
<orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, asdf: 3.4.2) [gem]" level="application" />
|
65
|
+
<orderEntry type="library" scope="PROVIDED" name="prettyprint (v0.2.0, asdf: 3.4.2) [gem]" level="application" />
|
66
|
+
<orderEntry type="library" scope="PROVIDED" name="prism (v1.4.0, asdf: 3.4.2) [gem]" level="application" />
|
67
|
+
<orderEntry type="library" scope="PROVIDED" name="psych (v5.2.6, asdf: 3.4.2) [gem]" level="application" />
|
68
|
+
<orderEntry type="library" scope="PROVIDED" name="racc (v1.8.1, asdf: 3.4.2) [gem]" level="application" />
|
69
|
+
<orderEntry type="library" scope="PROVIDED" name="rack (v3.1.16, asdf: 3.4.2) [gem]" level="application" />
|
70
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-session (v2.1.1, asdf: 3.4.2) [gem]" level="application" />
|
71
|
+
<orderEntry type="library" scope="PROVIDED" name="rack-test (v2.2.0, asdf: 3.4.2) [gem]" level="application" />
|
72
|
+
<orderEntry type="library" scope="PROVIDED" name="rackup (v2.2.1, asdf: 3.4.2) [gem]" level="application" />
|
73
|
+
<orderEntry type="library" scope="PROVIDED" name="rails (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
74
|
+
<orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.3.0, asdf: 3.4.2) [gem]" level="application" />
|
75
|
+
<orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.6.2, asdf: 3.4.2) [gem]" level="application" />
|
76
|
+
<orderEntry type="library" scope="PROVIDED" name="railties (v8.0.2, asdf: 3.4.2) [gem]" level="application" />
|
77
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, asdf: 3.4.2) [gem]" level="application" />
|
78
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.3.0, asdf: 3.4.2) [gem]" level="application" />
|
79
|
+
<orderEntry type="library" scope="PROVIDED" name="rdoc (v6.14.1, asdf: 3.4.2) [gem]" level="application" />
|
80
|
+
<orderEntry type="library" scope="PROVIDED" name="redcarpet (v3.6.1, asdf: 3.4.2) [gem]" level="application" />
|
81
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.10.0, asdf: 3.4.2) [gem]" level="application" />
|
82
|
+
<orderEntry type="library" scope="PROVIDED" name="reline (v0.6.1, asdf: 3.4.2) [gem]" level="application" />
|
83
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.1, asdf: 3.4.2) [gem]" level="application" />
|
84
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.4, asdf: 3.4.2) [gem]" level="application" />
|
85
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.5, asdf: 3.4.2) [gem]" level="application" />
|
86
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.5, asdf: 3.4.2) [gem]" level="application" />
|
87
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-rails (v8.0.1, asdf: 3.4.2) [gem]" level="application" />
|
88
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.4, asdf: 3.4.2) [gem]" level="application" />
|
89
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.77.0, asdf: 3.4.2) [gem]" level="application" />
|
90
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.45.1, asdf: 3.4.2) [gem]" level="application" />
|
91
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-rails (v2.32.0, asdf: 3.4.2) [gem]" level="application" />
|
92
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v3.6.0, asdf: 3.4.2) [gem]" level="application" />
|
93
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, asdf: 3.4.2) [gem]" level="application" />
|
94
|
+
<orderEntry type="library" scope="PROVIDED" name="securerandom (v0.4.1, asdf: 3.4.2) [gem]" level="application" />
|
95
|
+
<orderEntry type="library" scope="PROVIDED" name="sprockets (v4.2.2, asdf: 3.4.2) [gem]" level="application" />
|
96
|
+
<orderEntry type="library" scope="PROVIDED" name="sprockets-rails (v3.5.2, asdf: 3.4.2) [gem]" level="application" />
|
97
|
+
<orderEntry type="library" scope="PROVIDED" name="sqlite3 (v2.7.0, asdf: 3.4.2) [gem]" level="application" />
|
98
|
+
<orderEntry type="library" scope="PROVIDED" name="stringio (v3.1.7, asdf: 3.4.2) [gem]" level="application" />
|
99
|
+
<orderEntry type="library" scope="PROVIDED" name="thor (v1.3.2, asdf: 3.4.2) [gem]" level="application" />
|
100
|
+
<orderEntry type="library" scope="PROVIDED" name="timeout (v0.4.3, asdf: 3.4.2) [gem]" level="application" />
|
101
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, asdf: 3.4.2) [gem]" level="application" />
|
102
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.1.4, asdf: 3.4.2) [gem]" level="application" />
|
103
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.0.4, asdf: 3.4.2) [gem]" level="application" />
|
104
|
+
<orderEntry type="library" scope="PROVIDED" name="uri (v1.0.3, asdf: 3.4.2) [gem]" level="application" />
|
105
|
+
<orderEntry type="library" scope="PROVIDED" name="useragent (v0.16.11, asdf: 3.4.2) [gem]" level="application" />
|
106
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.8.0, asdf: 3.4.2) [gem]" level="application" />
|
107
|
+
<orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, asdf: 3.4.2) [gem]" level="application" />
|
108
|
+
<orderEntry type="library" scope="PROVIDED" name="yard (v0.9.37, asdf: 3.4.2) [gem]" level="application" />
|
109
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.7.3, asdf: 3.4.2) [gem]" level="application" />
|
110
|
+
</component>
|
111
|
+
</module>
|
data/.idea/vcs.xml
ADDED
data/README.md
ADDED
@@ -0,0 +1,369 @@
|
|
1
|
+
# Rails Active MCP
|
2
|
+
|
3
|
+
A Ruby gem that provides secure Rails console access through Model Context Protocol (MCP) for AI agents and development tools like Warp Terminal. Built with a custom MCP server implementation for full control and flexibility.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- 🔒 **Safe Execution**: Advanced safety checks prevent dangerous operations
|
8
|
+
- 🚀 **Custom MCP Server**: Built-in MCP server with no external dependencies
|
9
|
+
- 📊 **Read-Only Queries**: Safe database querying with automatic result limiting
|
10
|
+
- 🔍 **Code Analysis**: Dry-run capabilities to analyze code before execution
|
11
|
+
- 📝 **Audit Logging**: Complete execution logging for security and debugging
|
12
|
+
- ⚙️ **Configurable**: Flexible configuration for different environments
|
13
|
+
- 🛡️ **Production Ready**: Strict safety modes for production environments
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'rails-active-mcp'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ bundle install
|
27
|
+
```
|
28
|
+
|
29
|
+
Run the installer:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
$ rails generate rails_active_mcp:install
|
33
|
+
```
|
34
|
+
|
35
|
+
This will:
|
36
|
+
|
37
|
+
- Create an initializer with configuration options
|
38
|
+
- Mount the custom MCP server at `/mcp`
|
39
|
+
- Create a `mcp.ru` server file for standalone usage
|
40
|
+
- Set up audit logging
|
41
|
+
|
42
|
+
## Configuration
|
43
|
+
|
44
|
+
The gem is configured in `config/initializers/rails_active_mcp.rb`:
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
RailsActiveMcp.configure do |config|
|
48
|
+
# Basic settings
|
49
|
+
config.enabled = true
|
50
|
+
config.safe_mode = Rails.env.production?
|
51
|
+
config.default_timeout = 30
|
52
|
+
config.max_results = 100
|
53
|
+
|
54
|
+
# Model access control
|
55
|
+
config.allowed_models = %w[User Post Comment] # Empty = all allowed
|
56
|
+
config.blocked_models = %w[AdminUser Secret]
|
57
|
+
|
58
|
+
# Security settings
|
59
|
+
config.enable_mutation_tools = !Rails.env.production?
|
60
|
+
config.log_executions = true
|
61
|
+
config.audit_file = Rails.root.join("log", "rails_active_mcp.log")
|
62
|
+
|
63
|
+
# Environment presets
|
64
|
+
config.production_mode! # Very strict
|
65
|
+
config.strict_mode! # Safe defaults
|
66
|
+
config.permissive_mode! # Development friendly
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
## Running the MCP Server
|
71
|
+
|
72
|
+
You have several options for running the MCP server:
|
73
|
+
|
74
|
+
### Option 1: Rails-mounted (recommended for development)
|
75
|
+
|
76
|
+
```bash
|
77
|
+
$ rails server
|
78
|
+
# MCP server available at http://localhost:3000/mcp
|
79
|
+
```
|
80
|
+
|
81
|
+
### Option 2: Standalone server
|
82
|
+
|
83
|
+
```bash
|
84
|
+
$ bundle exec rails-active-mcp-server
|
85
|
+
# Default: http://localhost:3001
|
86
|
+
|
87
|
+
# Custom host/port
|
88
|
+
$ bundle exec rails-active-mcp-server --host 0.0.0.0 --port 8080
|
89
|
+
```
|
90
|
+
|
91
|
+
### Option 3: Using rackup
|
92
|
+
|
93
|
+
```bash
|
94
|
+
$ rackup mcp.ru -p 3001
|
95
|
+
```
|
96
|
+
|
97
|
+
## Usage
|
98
|
+
|
99
|
+
### With MCP Clients
|
100
|
+
|
101
|
+
#### Warp Terminal Integration
|
102
|
+
|
103
|
+
Add to your Warp MCP configuration:
|
104
|
+
|
105
|
+
```json
|
106
|
+
{
|
107
|
+
"mcpServers": {
|
108
|
+
"rails-console": {
|
109
|
+
"command": "curl",
|
110
|
+
"args": [
|
111
|
+
"-X",
|
112
|
+
"POST",
|
113
|
+
"-H",
|
114
|
+
"Content-Type: application/json",
|
115
|
+
"-d", "@-",
|
116
|
+
"http://localhost:3000/mcp"
|
117
|
+
]
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
```
|
122
|
+
|
123
|
+
Then in Warp, you can use prompts like:
|
124
|
+
|
125
|
+
- "Show me all users created in the last week"
|
126
|
+
- "What's the average order value?"
|
127
|
+
- "Check the User model schema and associations"
|
128
|
+
|
129
|
+
#### Claude Desktop / Cline
|
130
|
+
|
131
|
+
Use the same configuration format as above, pointing to your MCP server.
|
132
|
+
|
133
|
+
#### Custom MCP Clients
|
134
|
+
|
135
|
+
The server implements the MCP protocol (JSONRPC 2.0). Connect any MCP-compatible client to:
|
136
|
+
- **Rails-mounted**: `http://localhost:3000/mcp`
|
137
|
+
- **Standalone**: `http://localhost:3001`
|
138
|
+
|
139
|
+
### Direct Usage
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
# Execute code safely
|
143
|
+
result = RailsActiveMcp.execute("User.count")
|
144
|
+
puts result[:return_value] # => 42
|
145
|
+
|
146
|
+
# Check if code is safe
|
147
|
+
RailsActiveMcp.safe?("User.delete_all") # => false
|
148
|
+
|
149
|
+
# Analyze code without executing
|
150
|
+
executor = RailsActiveMcp::ConsoleExecutor.new(RailsActiveMcp.config)
|
151
|
+
analysis = executor.dry_run("User.delete_all")
|
152
|
+
puts analysis[:estimated_risk] # => :critical
|
153
|
+
```
|
154
|
+
|
155
|
+
### Available MCP Tools
|
156
|
+
|
157
|
+
#### `rails_console_execute`
|
158
|
+
|
159
|
+
Execute Ruby code with safety checks:
|
160
|
+
|
161
|
+
```json
|
162
|
+
{
|
163
|
+
"method": "tools/call",
|
164
|
+
"params": {
|
165
|
+
"name": "rails_console_execute",
|
166
|
+
"arguments": {
|
167
|
+
"code": "User.where(active: true).count",
|
168
|
+
"timeout": 30
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
```
|
173
|
+
|
174
|
+
#### Additional Tools
|
175
|
+
|
176
|
+
The custom server includes built-in support for the main console execute tool. You can extend the server with additional tools by modifying the `McpServer` class in `lib/rails_active_mcp/mcp_server.rb`:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
def register_default_tools
|
180
|
+
# Built-in console execution tool
|
181
|
+
register_tool('rails_console_execute', 'Execute Ruby code safely', {...})
|
182
|
+
|
183
|
+
# Your custom tools
|
184
|
+
register_tool('my_custom_tool', 'Description', {...}) do |args|
|
185
|
+
# Tool implementation
|
186
|
+
end
|
187
|
+
end
|
188
|
+
```
|
189
|
+
|
190
|
+
Common tool implementations can include:
|
191
|
+
- Code safety analysis
|
192
|
+
- Read-only database queries
|
193
|
+
- Model schema inspection
|
194
|
+
- Custom business logic tools
|
195
|
+
|
196
|
+
## Safety Features
|
197
|
+
|
198
|
+
### Automatic Detection of Dangerous Operations
|
199
|
+
|
200
|
+
The gem automatically detects and blocks:
|
201
|
+
|
202
|
+
- Mass deletions (`delete_all`, `destroy_all`)
|
203
|
+
- System commands (`system`, `exec`, backticks)
|
204
|
+
- File operations (`File.delete`, `FileUtils`)
|
205
|
+
- Raw SQL execution
|
206
|
+
- Code evaluation (`eval`, `send`)
|
207
|
+
- Process manipulation (`exit`, `fork`)
|
208
|
+
|
209
|
+
### Safety Levels
|
210
|
+
|
211
|
+
- **Critical**: Never allowed (system commands, file deletion)
|
212
|
+
- **High**: Blocked in safe mode (mass deletions, eval)
|
213
|
+
- **Medium**: Logged but allowed (raw SQL, update_all)
|
214
|
+
- **Low**: Generally safe (environment access, require)
|
215
|
+
|
216
|
+
### Read-Only Mode
|
217
|
+
|
218
|
+
The gem can detect read-only operations and provide additional safety:
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
# These are considered safe read-only operations
|
222
|
+
User.find(1)
|
223
|
+
User.where(active: true).count
|
224
|
+
Post.includes(:comments).limit(10)
|
225
|
+
```
|
226
|
+
|
227
|
+
## Rake Tasks
|
228
|
+
|
229
|
+
```bash
|
230
|
+
# Check code safety
|
231
|
+
rails rails_active_mcp:check_safety['User.count']
|
232
|
+
|
233
|
+
# Execute code
|
234
|
+
rails rails_active_mcp:execute['User.count']
|
235
|
+
|
236
|
+
# Test MCP tools
|
237
|
+
rails rails_active_mcp:test_tools
|
238
|
+
|
239
|
+
# View configuration
|
240
|
+
rails rails_active_mcp:config
|
241
|
+
|
242
|
+
# View audit log
|
243
|
+
rails rails_active_mcp:audit_log[20]
|
244
|
+
|
245
|
+
# Clear audit log
|
246
|
+
rails rails_active_mcp:clear_audit_log
|
247
|
+
```
|
248
|
+
|
249
|
+
## Audit Logging
|
250
|
+
|
251
|
+
All executions are logged to `log/rails_active_mcp.log`:
|
252
|
+
|
253
|
+
```json
|
254
|
+
{
|
255
|
+
"timestamp": "2025-01-15T10:30:00Z",
|
256
|
+
"code": "User.count",
|
257
|
+
"user": {
|
258
|
+
"environment": "development"
|
259
|
+
},
|
260
|
+
"safety_check": {
|
261
|
+
"safe": true,
|
262
|
+
"read_only": true,
|
263
|
+
"violations": []
|
264
|
+
}
|
265
|
+
}
|
266
|
+
```
|
267
|
+
|
268
|
+
## Environment-Specific Configuration
|
269
|
+
|
270
|
+
### Production
|
271
|
+
|
272
|
+
```ruby
|
273
|
+
config.production_mode!
|
274
|
+
# - Very strict safety checks
|
275
|
+
# - Read-only replica execution
|
276
|
+
# - Comprehensive logging
|
277
|
+
# - No mutation tools
|
278
|
+
```
|
279
|
+
|
280
|
+
### Development
|
281
|
+
|
282
|
+
```ruby
|
283
|
+
config.permissive_mode!
|
284
|
+
# - Relaxed safety (but still protected)
|
285
|
+
# - Mutation tools enabled
|
286
|
+
# - Higher timeouts and limits
|
287
|
+
```
|
288
|
+
|
289
|
+
### Testing
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
config.strict_mode!
|
293
|
+
# - Safe defaults
|
294
|
+
# - No mutations
|
295
|
+
# - Fast timeouts
|
296
|
+
```
|
297
|
+
|
298
|
+
## Custom MCP Server Architecture
|
299
|
+
|
300
|
+
Rails Active MCP provides a custom-built MCP server implementation with no external dependencies. The server:
|
301
|
+
|
302
|
+
- Implements the Model Context Protocol (MCP)
|
303
|
+
- Uses JSON-RPC 2.0 over HTTP
|
304
|
+
- Supports essential MCP methods:
|
305
|
+
- `initialize` - Server capabilities
|
306
|
+
- `tools/list` - Available tools
|
307
|
+
- `tools/call` - Execute tools
|
308
|
+
- `resources/list` and `resources/read` - Resource access
|
309
|
+
|
310
|
+
### Server Implementation
|
311
|
+
|
312
|
+
The core server is implemented in `lib/rails_active_mcp/mcp_server.rb` and follows Rack middleware conventions, making it easy to mount in Rails or run standalone.
|
313
|
+
|
314
|
+
### Extending the Server
|
315
|
+
|
316
|
+
You can add custom tools and resources to the server by extending the registration methods:
|
317
|
+
|
318
|
+
```ruby
|
319
|
+
# In an initializer or plugin
|
320
|
+
RailsActiveMcp.server.instance_eval do
|
321
|
+
register_tool('my_custom_tool', 'Description', {...}) do |args|
|
322
|
+
# Tool implementation
|
323
|
+
end
|
324
|
+
end
|
325
|
+
```
|
326
|
+
|
327
|
+
## Error Handling
|
328
|
+
|
329
|
+
The gem provides specific error types:
|
330
|
+
|
331
|
+
- `RailsActiveMcp::SafetyError`: Code failed safety checks
|
332
|
+
- `RailsActiveMcp::TimeoutError`: Execution timed out
|
333
|
+
- `RailsActiveMcp::ExecutionError`: General execution failure
|
334
|
+
|
335
|
+
## Contributing
|
336
|
+
|
337
|
+
1. Fork it
|
338
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
339
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
340
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
341
|
+
5. Create a new Pull Request
|
342
|
+
|
343
|
+
## License
|
344
|
+
|
345
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
346
|
+
|
347
|
+
## Security
|
348
|
+
|
349
|
+
This gem provides multiple layers of security, but always:
|
350
|
+
|
351
|
+
- Review the configuration for your environment
|
352
|
+
- Monitor the audit logs
|
353
|
+
- Use read-only database replicas in production when possible
|
354
|
+
- Restrict model access as needed
|
355
|
+
- Test safety patterns thoroughly
|
356
|
+
|
357
|
+
### Benefits of the Custom MCP Server
|
358
|
+
|
359
|
+
- **No External Dependencies**: Reduced attack surface with minimal dependencies
|
360
|
+
- **Full Control**: Complete visibility into the server implementation
|
361
|
+
- **Customizable Security**: Easily add additional security layers or checks
|
362
|
+
- **Simplified Deployment**: No need to manage external MCP server dependencies
|
363
|
+
- **Protocol Isolation**: MCP protocol implementation is self-contained and auditable
|
364
|
+
|
365
|
+
For security issues, please report using Github Issues.
|
366
|
+
|
367
|
+
## Changelog
|
368
|
+
|
369
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history and changes.
|
data/changelog.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.1.0] - 2025-06-25
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Initial release of Rails Active MCP gem
|
15
|
+
- Core MCP tools for Rails console access:
|
16
|
+
- `console_execute`: Execute Ruby code with safety checks
|
17
|
+
- `safe_query`: Execute read-only database queries
|
18
|
+
- `dry_run`: Analyze code safety without execution
|
19
|
+
- `model_info`: Get model schema and associations
|
20
|
+
- Advanced safety checking system:
|
21
|
+
- Pattern-based dangerous operation detection
|
22
|
+
- Configurable safety levels (critical, high, medium, low)
|
23
|
+
- Read-only operation detection
|
24
|
+
- Custom safety pattern support
|
25
|
+
- Comprehensive configuration system:
|
26
|
+
- Environment-specific presets (production, development, test)
|
27
|
+
- Model access control (allow/block lists)
|
28
|
+
- Timeout and result limiting
|
29
|
+
- Audit logging configuration
|
30
|
+
- Rails integration:
|
31
|
+
- Rails engine for automatic setup
|
32
|
+
- Generator for easy installation
|
33
|
+
- Rake tasks for management and testing
|
34
|
+
- Active MCP integration
|
35
|
+
- Security features:
|
36
|
+
- Execution timeout protection
|
37
|
+
- Result size limiting
|
38
|
+
- Complete audit logging
|
39
|
+
- Environment-based safety modes
|
40
|
+
- Console executor with:
|
41
|
+
- Output capturing
|
42
|
+
- Error handling
|
43
|
+
- Execution timing
|
44
|
+
- Context isolation
|
45
|
+
|
46
|
+
### Security
|
47
|
+
|
48
|
+
- All dangerous operations blocked by default in safe mode
|
49
|
+
- Production mode enables strictest safety settings
|
50
|
+
- Comprehensive audit logging for security monitoring
|
51
|
+
- Model access restrictions to prevent unauthorized data access
|
52
|
+
|
53
|
+
## [0.0.1] - 2025-01-14
|
54
|
+
|
55
|
+
### Added
|
56
|
+
|
57
|
+
- Project initialization
|
58
|
+
- Basic gem structure
|
59
|
+
- Initial safety checker implementation
|