rails-active-mcp 2.0.7 → 2.0.12

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +141 -0
  3. data/README.md +3 -3
  4. data/examples/rails_app_integration.md +405 -0
  5. data/exe/rails-active-mcp-server +8 -8
  6. data/gemfiles/rails_6.0.gemfile +34 -0
  7. data/gemfiles/rails_6.1.gemfile +34 -0
  8. data/gemfiles/rails_7.0.gemfile +34 -0
  9. data/gemfiles/rails_7.1.gemfile +34 -0
  10. data/gemfiles/rails_7.2.gemfile +34 -0
  11. data/lib/generators/rails_active_mcp/install/install_generator.rb +44 -94
  12. data/lib/generators/rails_active_mcp/install/templates/README.md +134 -54
  13. data/lib/generators/rails_active_mcp/install/templates/initializer.rb +44 -6
  14. data/lib/generators/rails_active_mcp/install/templates/rails-active-mcp-server +104 -0
  15. data/lib/generators/rails_active_mcp/install/templates/rails-active-mcp-wrapper +94 -0
  16. data/lib/rails_active_mcp/configuration.rb +44 -4
  17. data/lib/rails_active_mcp/console_executor.rb +185 -83
  18. data/lib/rails_active_mcp/engine.rb +2 -2
  19. data/lib/rails_active_mcp/garbage_collection_utils.rb +13 -0
  20. data/lib/rails_active_mcp/safety_checker.rb +17 -7
  21. data/lib/rails_active_mcp/sdk/server.rb +1 -1
  22. data/lib/rails_active_mcp/sdk/tools/console_execute_tool.rb +0 -2
  23. data/lib/rails_active_mcp/sdk/tools/dry_run_tool.rb +0 -2
  24. data/lib/rails_active_mcp/sdk/tools/model_info_tool.rb +1 -3
  25. data/lib/rails_active_mcp/sdk/tools/safe_query_tool.rb +0 -2
  26. data/lib/rails_active_mcp/tasks.rake +238 -82
  27. data/lib/rails_active_mcp/version.rb +1 -1
  28. data/lib/rails_active_mcp.rb +4 -3
  29. data/mcp.ru +2 -2
  30. data/rails_active_mcp.gemspec +62 -14
  31. metadata +72 -16
@@ -0,0 +1,34 @@
1
+ # Rails 7.0 Gemfile for CI testing
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify the Rails version
5
+ gem 'rails', '~> 7.0.0'
6
+
7
+ # Include the main gemspec
8
+ gemspec path: '../'
9
+
10
+ group :development, :test do
11
+ gem 'byebug'
12
+ gem 'database_cleaner-active_record', '~> 2.1'
13
+ gem 'factory_bot_rails', '~> 6.0'
14
+ gem 'rspec', '~> 3.1'
15
+ gem 'rspec-rails'
16
+ gem 'sqlite3', '~> 2.7'
17
+ gem 'timecop', '~> 0.9.8'
18
+ gem 'webmock', '~> 3.19'
19
+ end
20
+
21
+ group :development do
22
+ gem 'redcarpet' # For YARD markdown support
23
+ gem 'rubocop', '~> 1.77'
24
+ gem 'rubocop-rails', '~> 2.32'
25
+ gem 'rubocop-rspec'
26
+ gem 'simplecov', '~> 0.22'
27
+ gem 'yard'
28
+ end
29
+
30
+ # For testing the gem in a Rails app
31
+ gem 'sprockets-rails' # Required for Rails 7+
32
+
33
+ # Official MCP Ruby SDK for migration
34
+ gem 'mcp', '~> 0.1.0'
@@ -0,0 +1,34 @@
1
+ # Rails 7.1 Gemfile for CI testing
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify the Rails version
5
+ gem 'rails', '~> 7.1.0'
6
+
7
+ # Include the main gemspec
8
+ gemspec path: '../'
9
+
10
+ group :development, :test do
11
+ gem 'byebug'
12
+ gem 'database_cleaner-active_record', '~> 2.1'
13
+ gem 'factory_bot_rails', '~> 6.0'
14
+ gem 'rspec', '~> 3.1'
15
+ gem 'rspec-rails'
16
+ gem 'sqlite3', '~> 2.7'
17
+ gem 'timecop', '~> 0.9.8'
18
+ gem 'webmock', '~> 3.19'
19
+ end
20
+
21
+ group :development do
22
+ gem 'redcarpet' # For YARD markdown support
23
+ gem 'rubocop', '~> 1.77'
24
+ gem 'rubocop-rails', '~> 2.32'
25
+ gem 'rubocop-rspec'
26
+ gem 'simplecov', '~> 0.22'
27
+ gem 'yard'
28
+ end
29
+
30
+ # For testing the gem in a Rails app
31
+ gem 'sprockets-rails' # Required for Rails 7+
32
+
33
+ # Official MCP Ruby SDK for migration
34
+ gem 'mcp', '~> 0.1.0'
@@ -0,0 +1,34 @@
1
+ # Rails 7.2 Gemfile for CI testing
2
+ source 'https://rubygems.org'
3
+
4
+ # Specify the Rails version
5
+ gem 'rails', '~> 7.2.0'
6
+
7
+ # Include the main gemspec
8
+ gemspec path: '../'
9
+
10
+ group :development, :test do
11
+ gem 'byebug'
12
+ gem 'database_cleaner-active_record', '~> 2.1'
13
+ gem 'factory_bot_rails', '~> 6.0'
14
+ gem 'rspec', '~> 3.1'
15
+ gem 'rspec-rails'
16
+ gem 'sqlite3', '~> 2.7'
17
+ gem 'timecop', '~> 0.9.8'
18
+ gem 'webmock', '~> 3.19'
19
+ end
20
+
21
+ group :development do
22
+ gem 'redcarpet' # For YARD markdown support
23
+ gem 'rubocop', '~> 1.77'
24
+ gem 'rubocop-rails', '~> 2.32'
25
+ gem 'rubocop-rspec'
26
+ gem 'simplecov', '~> 0.22'
27
+ gem 'yard'
28
+ end
29
+
30
+ # For testing the gem in a Rails app
31
+ gem 'sprockets-rails' # Required for Rails 7+
32
+
33
+ # Official MCP Ruby SDK for migration
34
+ gem 'mcp', '~> 0.1.0'
@@ -3,7 +3,7 @@
3
3
  module RailsActiveMcp
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
- source_root File.expand_path('templates', __dir__)
6
+ source_root File.expand_path('templates', __dir__ || File.dirname(__FILE__))
7
7
 
8
8
  desc 'Install Rails Active MCP'
9
9
 
@@ -11,81 +11,14 @@ module RailsActiveMcp
11
11
  template 'initializer.rb', 'config/initializers/rails_active_mcp.rb'
12
12
  end
13
13
 
14
- def create_binstub
15
- # Create binstub for easy server execution
16
- create_file 'bin/rails-active-mcp-server', <<~RUBY
17
- #!/usr/bin/env ruby
18
-
19
- # Binstub for Rails Active MCP Server
20
- # This ensures the server runs within the Rails project context
21
-
22
- require 'bundler/setup'
23
-
24
- # Set Rails environment
25
- ENV['RAILS_ENV'] ||= 'development'
26
-
27
- # Load Rails application first
28
- require_relative '../config/environment'
29
-
30
- # Now start the MCP server using the SDK implementation
31
- require 'rails_active_mcp/sdk/server'
32
-
33
- begin
34
- server = RailsActiveMcp::SDK::Server.new
35
- server.run
36
- rescue StandardError => e
37
- warn "Error starting Rails Active MCP server: \#{e.message}"
38
- warn e.backtrace if ENV['RAILS_MCP_DEBUG'] == '1'
39
- exit 1
40
- end
41
- RUBY
14
+ def create_wrapper_script
15
+ template 'rails-active-mcp-wrapper', 'bin/rails-active-mcp-wrapper'
16
+ chmod 'bin/rails-active-mcp-wrapper', 0o755
17
+ end
42
18
 
19
+ def create_server_script
20
+ template 'rails-active-mcp-server', 'bin/rails-active-mcp-server'
43
21
  chmod 'bin/rails-active-mcp-server', 0o755
44
- say 'Created Rails binstub at bin/rails-active-mcp-server', :green
45
-
46
- # Create environment-aware wrapper for Claude Desktop compatibility
47
- ruby_path = `which ruby`.strip
48
-
49
- create_file 'bin/rails-active-mcp-wrapper', <<~BASH
50
- #!/usr/bin/env bash
51
-
52
- # Rails Active MCP Wrapper Script
53
- # Ensures correct Ruby environment for Claude Desktop execution
54
-
55
- # Fix Claude Desktop environment isolation issues
56
- export HOME="${HOME:-#{ENV['HOME']}}"
57
- export USER="${USER:-$(whoami)}"
58
-
59
- # Strategy 1: Use absolute Ruby path (most reliable)
60
- RUBY_PATH="#{ruby_path}"
61
-
62
- # Strategy 2: Try /usr/local/bin/ruby symlink as fallback
63
- if [ ! -x "$RUBY_PATH" ]; then
64
- RUBY_PATH="/usr/local/bin/ruby"
65
- fi
66
-
67
- # Strategy 3: Setup environment and use PATH resolution as last resort
68
- if [ ! -x "$RUBY_PATH" ]; then
69
- # Set up asdf environment if available
70
- export ASDF_DIR="$HOME/.asdf"
71
- if [ -f "$ASDF_DIR/asdf.sh" ]; then
72
- source "$ASDF_DIR/asdf.sh"
73
- fi
74
- #{' '}
75
- # Add version manager paths
76
- export PATH="$HOME/.asdf/shims:$HOME/.rbenv/shims:$HOME/.rvm/bin:$PATH"
77
- RUBY_PATH="ruby"
78
- fi
79
-
80
- # Change to the Rails project directory
81
- cd "$(dirname "$0")/.."
82
-
83
- # Execute with the determined Ruby path
84
- exec "$RUBY_PATH" bin/rails-active-mcp-server "$@"
85
- BASH
86
-
87
- chmod 'bin/rails-active-mcp-wrapper', 0o755
88
- say 'Created environment wrapper at bin/rails-active-mcp-wrapper', :green
89
22
  end
90
23
 
91
24
  def create_mcp_config
@@ -96,59 +29,76 @@ module RailsActiveMcp
96
29
  readme 'README.md' if behavior == :invoke
97
30
  end
98
31
 
32
+ # rubocop:disable Metrics/AbcSize
99
33
  def show_post_install_instructions
100
34
  return unless behavior == :invoke
101
35
 
102
- say "\n" + '=' * 50, :green
36
+ say "\n#{'=' * 50}", :green
103
37
  say 'Rails Active MCP Installation Complete!', :green
104
38
  say '=' * 50, :green
39
+ say "\nFiles created:", :green
40
+ say '✅ config/initializers/rails_active_mcp.rb', :yellow
41
+ say '✅ bin/rails-active-mcp-wrapper', :yellow
42
+ say '✅ bin/rails-active-mcp-server', :yellow
43
+ say '✅ mcp.ru', :yellow
44
+ say '', :green
45
+ say "\nQuick Test:", :green
46
+ say '1. Test the server: bin/rails-active-mcp-wrapper', :yellow
47
+ say '2. Should show JSON responses (not plain text)', :yellow
48
+ say '3. Exit with Ctrl+C', :yellow
49
+ say '', :green
105
50
  say "\nFor Claude Desktop configuration:", :green
106
51
  say 'Add this to your claude_desktop_config.json:', :yellow
107
52
  say '', :green
108
53
  say '{', :cyan
109
54
  say ' "mcpServers": {', :cyan
110
55
  say ' "rails-active-mcp": {', :cyan
111
- say " \"command\": \"#{Rails.root}/bin/rails-active-mcp-wrapper\",", :cyan
56
+ say " \"command\": \"#{Rails.root.join('bin/rails-active-mcp-wrapper')}\",", :cyan
112
57
  say " \"cwd\": \"#{Rails.root}\",", :cyan
113
58
  say ' "env": {', :cyan
114
- say ' "RAILS_ENV": "development",', :cyan
115
- say " \"HOME\": \"#{ENV['HOME']}\"", :cyan
59
+ say ' "RAILS_ENV": "development"', :cyan
116
60
  say ' }', :cyan
117
61
  say ' }', :cyan
118
62
  say ' }', :cyan
119
63
  say '}', :cyan
120
64
  say '', :green
65
+ say 'Config file locations:', :green
66
+ say ' macOS: ~/.config/claude-desktop/claude_desktop_config.json', :yellow
67
+ say ' Windows: %APPDATA%\\Claude\\claude_desktop_config.json', :yellow
68
+ say '', :green
121
69
  say "\nAvailable Tools in Claude Desktop:", :green
122
70
  say '- console_execute: Execute Ruby code with safety checks', :yellow
123
71
  say '- model_info: Get detailed information about Rails models', :yellow
124
72
  say '- safe_query: Execute safe read-only database queries', :yellow
125
73
  say '- dry_run: Analyze Ruby code for safety without execution', :yellow
126
74
  say '', :green
127
- say "\nWhy use the wrapper?", :green
128
- say '- Handles Ruby version manager environments (asdf, rbenv, etc.)', :yellow
129
- say '- Prevents "bundler version" and "Ruby version" conflicts', :yellow
130
- say '- Works reliably across different development setups', :yellow
131
- say "\nAlternative (if wrapper doesn't work):", :green
132
- say 'Use bin/rails-active-mcp-server instead of the wrapper', :yellow
133
- say "\nTesting:", :green
134
- say '1. Test manually: bin/rails-active-mcp-wrapper', :yellow
135
- say '2. Should output JSON responses (not plain text)', :yellow
136
- say '3. Restart Claude Desktop after config changes', :yellow
75
+ say "\nExample Claude Desktop prompts:", :green
76
+ say '- "Show me the User model structure"', :yellow
77
+ say '- "How many users were created in the last week?"', :yellow
78
+ say '- "What are the most recent orders?"', :yellow
79
+ say '- "Check if this code is safe: User.delete_all"', :yellow
80
+ say '', :green
137
81
  say "\nTroubleshooting:", :green
138
- say '- Set RAILS_MCP_DEBUG=1 for verbose logging', :yellow
139
- say '- Check README.md for more configuration options', :yellow
140
- say "\nFor Ruby version manager users (asdf/rbenv/RVM):", :green
141
- say 'If you encounter "bundler version" errors, create a system symlink:', :yellow
142
- say "sudo ln -sf #{`which ruby`.strip} /usr/local/bin/ruby", :cyan
82
+ say '- Debug mode: RAILS_MCP_DEBUG=1 bin/rails-active-mcp-wrapper', :yellow
83
+ say '- Check status: rails rails_active_mcp:status', :yellow
84
+ say '- Restart Claude Desktop after config changes', :yellow
85
+ say '- If wrapper fails, try: bin/rails-active-mcp-server', :yellow
86
+ say '', :green
87
+ say "\nNext steps:", :green
88
+ say '1. Test installation: rails rails_active_mcp:test_tools', :yellow
89
+ say '2. Configure Claude Desktop (see above)', :yellow
90
+ say '3. Restart Claude Desktop', :yellow
91
+ say '4. Start chatting with your Rails app!', :yellow
143
92
  say '=' * 50, :green
144
93
  end
94
+ # rubocop:enable Metrics/AbcSize
145
95
 
146
96
  private
147
97
 
148
98
  def readme(path)
149
99
  readme_path = File.join(self.class.source_root, path)
150
100
  if File.exist?(readme_path)
151
- say IO.read(readme_path), :green
101
+ say File.read(readme_path), :green
152
102
  else
153
103
  say "README file not found at #{readme_path}", :green
154
104
  end
@@ -1,54 +1,134 @@
1
- ================================================================================
2
- Rails Active MCP Installation Complete!
3
- ================================================================================
4
-
5
- 🎉 Rails Active MCP v2.0 with Official MCP Ruby SDK has been installed!
6
-
7
- 📁 Files Created:
8
- - config/initializers/rails_active_mcp.rb (Configuration)
9
- - bin/rails-active-mcp-server (Main server executable)
10
- - bin/rails-active-mcp-wrapper (Environment wrapper for Claude Desktop)
11
- - mcp.ru (Rack configuration file)
12
-
13
- 🛠️ Available MCP Tools:
14
- - console_execute: Execute Ruby code with safety checks
15
- - model_info: Get detailed information about Rails models
16
- - safe_query: Execute safe read-only database queries
17
- - dry_run: Analyze Ruby code for safety without execution
18
-
19
- 🚀 Quick Start:
20
-
21
- 1. Test the server:
22
- $ ./bin/rails-active-mcp-server
23
-
24
- 2. For Claude Desktop, add to claude_desktop_config.json:
25
- {
26
- "mcpServers": {
27
- "rails-active-mcp": {
28
- "command": "/path/to/your/project/bin/rails-active-mcp-wrapper",
29
- "cwd": "/path/to/your/project",
30
- "env": {
31
- "RAILS_ENV": "development",
32
- "HOME": "/Users/your-username"
33
- }
34
- }
35
- }
36
- }
37
-
38
- 3. Restart Claude Desktop and start using the tools!
39
-
40
- ⚙️ Configuration:
41
- Edit config/initializers/rails_active_mcp.rb to customize:
42
- - allowed_commands: Shell commands that can be executed
43
- - command_timeout: Execution timeout in seconds
44
- - enable_logging: Enable/disable logging
45
- - log_level: Logging verbosity (:debug, :info, :warn, :error)
46
-
47
- 🔧 Troubleshooting:
48
- - Use the wrapper script to avoid Ruby version manager conflicts
49
- - Set RAILS_MCP_DEBUG=1 for verbose logging
50
- - Ensure Claude Desktop has correct paths and environment variables
51
-
52
- 📚 Documentation: https://github.com/goodpie/rails-active-mcp
53
-
54
- ================================================================================
1
+ # Rails Active MCP Integration
2
+
3
+ This Rails application is configured with Rails Active MCP for secure AI-powered database querying and model inspection.
4
+
5
+ ## What is Rails Active MCP?
6
+
7
+ Rails Active MCP enables secure Rails console access through Model Context Protocol (MCP) for AI agents and development tools like Claude Desktop. It provides four main tools:
8
+
9
+ - **console_execute**: Execute Ruby/Rails code with safety checks
10
+ - **model_info**: Inspect Rails models (schema, associations, validations)
11
+ - **safe_query**: Run read-only database queries
12
+ - **dry_run**: Analyze code safety without execution
13
+
14
+ ## Quick Start
15
+
16
+ ### 1. Test the Installation
17
+
18
+ ```bash
19
+ # Test the server starts correctly
20
+ bin/rails-active-mcp-wrapper
21
+
22
+ # Enable debug mode for troubleshooting
23
+ RAILS_MCP_DEBUG=1 bin/rails-active-mcp-server
24
+ ```
25
+
26
+ ### 2. Configure Claude Desktop
27
+
28
+ Add this to your Claude Desktop configuration:
29
+
30
+ **macOS/Linux**: `~/.config/claude-desktop/claude_desktop_config.json`
31
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
32
+
33
+ ```json
34
+ {
35
+ "mcpServers": {
36
+ "rails-active-mcp": {
37
+ "command": "/path/to/your/rails/app/bin/rails-active-mcp-wrapper",
38
+ "cwd": "/path/to/your/rails/app",
39
+ "env": {
40
+ "RAILS_ENV": "development"
41
+ }
42
+ }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### 3. Try These Commands in Claude Desktop
48
+
49
+ - "Show me the User model structure"
50
+ - "How many users were created in the last week?"
51
+ - "What are the most recent orders?"
52
+ - "Check if this code is safe: `User.delete_all`"
53
+
54
+ ## Configuration
55
+
56
+ Your MCP integration is configured in `config/initializers/rails_active_mcp.rb`.
57
+
58
+ ### Environment-Specific Settings
59
+
60
+ - **Development**: More permissive, verbose logging
61
+ - **Production**: Strict safety, limited results, audit logging
62
+ - **Test**: Minimal logging, safety enabled
63
+
64
+ ### Customizing Safety Rules
65
+
66
+ ```ruby
67
+ # Add custom safety patterns
68
+ config.custom_safety_patterns = [
69
+ { pattern: /YourDangerousMethod/, description: "Custom dangerous operation" }
70
+ ]
71
+
72
+ # Restrict model access (empty = allow all)
73
+ config.allowed_models = %w[User Post Comment]
74
+ ```
75
+
76
+ ## Available Rake Tasks
77
+
78
+ ```bash
79
+ # Check code safety
80
+ rails rails_active_mcp:check_safety['User.count']
81
+
82
+ # Execute code with safety checks
83
+ rails rails_active_mcp:execute['User.count']
84
+
85
+ # Test MCP tools
86
+ rails rails_active_mcp:test_tools
87
+ ```
88
+
89
+ ## Troubleshooting
90
+
91
+ ### Server Won't Start
92
+ - Ensure your Rails app starts without errors: `rails console`
93
+ - Check Ruby version compatibility
94
+ - Verify all gems are installed: `bundle install`
95
+
96
+ ### Claude Desktop Connection Issues
97
+ - Restart Claude Desktop after configuration changes
98
+ - Check logs: `~/Library/Logs/Claude/mcp*.log` (macOS)
99
+ - Test server manually: `bin/rails-active-mcp-wrapper`
100
+
101
+ ### Permission Errors
102
+ - Ensure wrapper script is executable: `chmod +x bin/rails-active-mcp-wrapper`
103
+ - Check Ruby path in wrapper script matches your setup
104
+
105
+ ## Security Notes
106
+
107
+ - All dangerous operations are blocked by default in safe mode
108
+ - Production mode enables the strictest safety settings
109
+ - All executions can be logged for audit purposes
110
+ - Model access can be restricted via configuration
111
+
112
+ ## Examples
113
+
114
+ ### Safe Operations (Always Allowed)
115
+ ```ruby
116
+ User.count
117
+ Post.where(published: true).limit(10)
118
+ User.find(1).posts.includes(:comments)
119
+ Rails.env
120
+ ```
121
+
122
+ ### Risky Operations (Blocked in Safe Mode)
123
+ ```ruby
124
+ User.delete_all # Mass deletion
125
+ system('rm -rf /') # System commands
126
+ eval(user_input) # Code evaluation
127
+ File.delete('file') # File operations
128
+ ```
129
+
130
+ ## Getting Help
131
+
132
+ - **Documentation**: https://github.com/goodpie/rails-active-mcp
133
+ - **Issues**: https://github.com/goodpie/rails-active-mcp/issues
134
+ - **MCP Protocol**: https://modelcontextprotocol.io
@@ -16,15 +16,45 @@ RailsActiveMcp.configure do |config|
16
16
  config.enable_logging = true
17
17
  config.log_level = :info # :debug, :info, :warn, :error
18
18
 
19
+ # Safety configuration
20
+ config.safe_mode = true # Enable safety checks by default
21
+ config.max_results = 100 # Limit query results to prevent large dumps
22
+ config.log_executions = true # Log all executions for audit trail
23
+
24
+ # Model access control (empty arrays allow all)
25
+ config.allowed_models = [] # Whitelist specific models if needed
26
+ # config.allowed_models = %w[User Post Comment] # Example: restrict to specific models
27
+
28
+ # Custom safety patterns for your application
29
+ # config.custom_safety_patterns = [
30
+ # { pattern: /YourDangerousMethod/, description: "Your custom dangerous operation" }
31
+ # ]
32
+
19
33
  # Environment-specific adjustments
20
- if Rails.env.production?
21
- # More restrictive settings for production
34
+ case Rails.env
35
+ when 'production'
36
+ # Strict settings for production
37
+ config.safe_mode = true
22
38
  config.log_level = :warn
23
39
  config.command_timeout = 15
24
- elsif Rails.env.development?
40
+ config.max_results = 50
41
+ config.log_executions = true
42
+ config.allowed_models = [] # Consider restricting models in production
43
+
44
+ when 'development'
25
45
  # More permissive settings for development
46
+ config.safe_mode = false # Allow more operations during development
26
47
  config.log_level = :debug
27
48
  config.command_timeout = 60
49
+ config.max_results = 200
50
+ config.log_executions = false
51
+
52
+ when 'test'
53
+ # Test-friendly settings
54
+ config.safe_mode = true
55
+ config.log_level = :error
56
+ config.command_timeout = 30
57
+ config.log_executions = false
28
58
  end
29
59
  end
30
60
 
@@ -36,7 +66,15 @@ end
36
66
  # - safe_query: Execute safe read-only database queries
37
67
  # - dry_run: Analyze Ruby code for safety without execution
38
68
  #
39
- # To start the server:
40
- # bin/rails-active-mcp-server
69
+ # Quick Start:
70
+ # 1. Start the server: bin/rails-active-mcp-server
71
+ # 2. Configure Claude Desktop (see post-install instructions)
72
+ # 3. Try asking Claude: "Show me all users created in the last week"
73
+ #
74
+ # Testing the installation:
75
+ # - Run: bin/rails-active-mcp-wrapper (should output JSON responses)
76
+ # - Test with: RAILS_MCP_DEBUG=1 bin/rails-active-mcp-server
77
+ # - Check rake tasks: rails -T rails_active_mcp
41
78
  #
42
- # For Claude Desktop integration, see the post-install instructions.
79
+ # Documentation: https://github.com/goodpie/rails-active-mcp
80
+ # Need help? Create an issue or check the troubleshooting guide.
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Rails Active MCP Server Script
5
+ # This script starts the Rails Active MCP server for your Rails application
6
+
7
+ # Ensure we're in the Rails application directory
8
+ unless File.exist?('config/environment.rb') && File.exist?('Gemfile')
9
+ puts 'Error: This script must be run from the root of a Rails application'
10
+ puts "Current directory: #{Dir.pwd}"
11
+ puts 'Please ensure you have both config/environment.rb and Gemfile in your project root'
12
+ exit(1)
13
+ end
14
+
15
+ # Load bundler and ensure the gem is available
16
+ begin
17
+ require 'bundler/setup'
18
+ rescue LoadError => e
19
+ puts "Error: Bundler not available: #{e.message}"
20
+ puts 'Please run: gem install bundler'
21
+ exit(1)
22
+ end
23
+
24
+ # Check if rails-active-mcp is in the bundle
25
+ begin
26
+ gem 'rails-active-mcp'
27
+ rescue Gem::LoadError
28
+ puts 'Error: rails-active-mcp gem not found in bundle'
29
+ puts "Please add to your Gemfile: gem 'rails-active-mcp'"
30
+ puts 'Then run: bundle install'
31
+ exit(1)
32
+ end
33
+
34
+ # Load Rails environment
35
+ begin
36
+ require_relative '../config/environment'
37
+ rescue LoadError => e
38
+ puts "Error: Failed to load Rails environment: #{e.message}"
39
+ puts 'Please ensure your Rails application is properly configured'
40
+ exit(1)
41
+ end
42
+
43
+ # Load Rails Active MCP
44
+ begin
45
+ require 'rails_active_mcp'
46
+ rescue LoadError => e
47
+ puts "Error: Failed to load Rails Active MCP: #{e.message}"
48
+ puts 'Please ensure the gem is properly installed'
49
+ exit(1)
50
+ end
51
+
52
+ # Ensure configuration is loaded
53
+ unless RailsActiveMcp.configuration
54
+ puts 'Warning: Rails Active MCP configuration not found'
55
+ puts 'Please run: rails generate rails_active_mcp:install'
56
+ puts 'Using default configuration...'
57
+ RailsActiveMcp.configure
58
+ end
59
+
60
+ # Start the server
61
+ begin
62
+ require 'rails_active_mcp/sdk/server'
63
+
64
+ # Parse command line arguments
65
+ transport = ARGV[0] || 'stdio'
66
+
67
+ case transport
68
+ when 'stdio', nil
69
+ puts 'Starting Rails Active MCP Server in stdio mode...' if ENV['RAILS_MCP_DEBUG']
70
+ server = RailsActiveMcp::Sdk::Server.new
71
+ server.run_stdio
72
+ when '--help', '-h'
73
+ puts <<~HELP
74
+ Rails Active MCP Server
75
+
76
+ Usage: #{File.basename($PROGRAM_NAME)} [mode] [options]
77
+
78
+ Modes:
79
+ stdio Start in stdio mode for MCP integration (default)
80
+ --help Show this help message
81
+
82
+ Environment Variables:
83
+ RAILS_MCP_DEBUG=1 Enable debug logging
84
+ RAILS_ENV=env Set Rails environment (default: development)
85
+
86
+ Examples:
87
+ #{File.basename($PROGRAM_NAME)} # Start in stdio mode
88
+ #{File.basename($PROGRAM_NAME)} stdio # Start in stdio mode explicitly
89
+ RAILS_MCP_DEBUG=1 #{File.basename($PROGRAM_NAME)} # Start with debug logging
90
+ HELP
91
+ else
92
+ puts "Error: Unknown transport mode '#{transport}'"
93
+ puts 'Use --help for usage information'
94
+ exit(1)
95
+ end
96
+ rescue Interrupt
97
+ puts "\nServer stopped by user"
98
+ exit(0)
99
+ rescue StandardError => e
100
+ puts "Error: Failed to start server: #{e.message}"
101
+ puts 'Backtrace:' if ENV['RAILS_MCP_DEBUG']
102
+ puts e.backtrace if ENV['RAILS_MCP_DEBUG']
103
+ exit(1)
104
+ end