Rails Active MCP
About
A Ruby gem providing secure Rails console access through MCP for AI agents and development tools.
Details
- Author
- goodpie
- Categories
- Developer Tools, Database, Infrastructure
Jump to
Setup
Install Rails Active MCP in your MCP client (Claude Desktop, Cursor, Windsurf, and others).
Repository: https://github.com/goodpie/rails-active-mcp
Follow the installation instructions in the repository README, then restart your MCP client.
Note: This is just a personal project and while it works for the most part, I am still developing it and actively trying to make it a bit more useful for my uses.
A Ruby gem that provides secure Rails console access throughModel Context Protocol (MCP)for AI agents and development tools. Built using the official MCP Ruby SDK for professional protocol handling and future-proof compatibility.
Works with any MCP-compatible client, including Claude Desktop, Claude Code, VS Code (GitHub Copilot), Cursor, Windsurf, ChatGPT, Gemini CLI, Amazon Q Developer, JetBrains IDEs, Zed, Warp, Cline, andmany more.
Add to your Rails application'sGemfile:
This creates an initializer, server scripts, and prompts you to select which MCP clients you use. It will automatically generate the correct project-level config files (.mcp.json,.cursor/mcp.json,.vscode/mcp.json, etc.) so your MCP client detects the server when you open the project.
If you selected your MCP client during installation, you're done β just open the project and the server will be detected automatically.
For manual configuration or additional clients, the server uses STDIO transport. Below are configuration examples for popular tools.
- macOS/Linux:~/.config/claude-desktop/claude_desktop_config.json
- Windows:%APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"], "cwd": "/path/to/your/rails/project" } } }
Restart Claude Desktop and the tools will appear automatically.
claude mcp add rails-active-mcp -- bundle exec rails-active-mcp-server
Or add it to your project's.mcp.json:
{ "mcpServers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"] } } }
Add to your workspace.vscode/mcp.json:
{ "servers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"], "cwd": "${workspaceFolder}" } } }
Tools are available in Copilot's Agent mode.
Add to your project's.cursor/mcp.json:
{ "mcpServers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"], "cwd": "/path/to/your/rails/project" } } }
Add to your global Windsurf config at~/.codeium/windsurf/mcp_config.json:
{ "mcpServers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"], "cwd": "/path/to/your/rails/project" } } }
Add to your Zed settings (settings.json):
{ "context_servers": { "rails-active-mcp": { "command": { "path": "bundle", "args": ["exec", "rails-active-mcp-server"], "env": {} } } } }
In ChatGPT Desktop, go toSettings > Connectors > Advanced > Developer Mode, then add:
{ "mcpServers": { "rails-active-mcp": { "command": "bundle", "args": ["exec", "rails-active-mcp-server"], "cwd": "/path/to/your/rails/project" } } }
Any MCP client that supports STDIO transport can connect to this server. The key details:
- Command:bundle exec rails-active-mcp-server
- Working directory:Your Rails project root
- Transport:STDIO (stdin/stdout)
See thefull list of MCP clientsfor more options.
Once connected, four tools will appear automatically:console_execute,model_info,safe_query, anddry_run.
- "Show me all users created in the last week"
- "What's the average order value?"
- "Check the User model schema and associations"
- "Analyze this code for safety: User.delete_all"
- πSafe Execution: Advanced safety checks prevent dangerous operations
- πOfficial MCP SDK: Built with the official MCP Ruby SDK for robust protocol handling
- πRead-Only Queries: Safe database querying with automatic result limiting
- πCode Analysis: Dry-run capabilities to analyze code before execution
- πAudit Logging: Complete execution logging for security and debugging
- βοΈConfigurable: Flexible configuration for different environments
- π‘οΈProduction Ready: Strict safety modes for production environments
- β‘Professional Implementation: Built-in instrumentation, timing, and error handling
The installer creates a default configuration atconfig/initializers/rails_active_mcp.rb. The defaults work out of the box, but you can customize behavior:
RailsActiveMcp.configure do |config| # Safety and execution config.safe_mode = true # Block dangerous operations config.command_timeout = 30 # Seconds before timeout config.max_results = 100 # Limit query results config.allowed_models = [] # Empty = all models allowed config.custom_safety_patterns = [] # Additional patterns to block # Logging config.enable_logging = true config.log_level = :info # :debug, :info, :warn, :error config.log_executions = false # Log all code executions config.audit_file = nil # Path to audit log file # Environment presets (call instead of setting individually) # config.production_mode! # config.development_mode! # config.test_mode! end
You can also use the gem directly in Ruby:
# Execute code safely result = RailsActiveMcp.execute("User.count") # Check if code is safe RailsActiveMcp.safe?("User.delete_all") # => false
If you need to run the server directly (e.g., for debugging):
bundle exec rails-active-mcp-server # With debug logging RAILS_MCP_DEBUG=1 bundle exec rails-active-mcp-server
The gem provides several rake tasks for diagnostics and testing:
# Show status and diagnostics rails rails_active_mcp:status # Validate configuration rails rails_active_mcp:validate_config # Test MCP tools are working rails rails_active_mcp:test_tools # Check if code is safe rails rails_active_mcp:check_safety['User.delete_all'] # Execute code with safety checks rails rails_active_mcp:execute['User.count'] # Print Claude Desktop configuration rails rails_active_mcp:install_claude_config # Run performance benchmarks rails rails_active_mcp:benchmark
The Rails Active MCP server provides four powerful tools that appear automatically in any connected MCP client:
Execute Ruby code with safety checks and timeout protection:
- Purpose: Run Rails console commands safely
- Safety: Built-in dangerous operation detection
- Timeout: Configurable execution timeout
- Logging: All executions are logged for audit
"ExecuteUser.where(active: true).count"
Get detailed information about Rails models:
- Schema Information: Column types, constraints, indexes
- Associations: Has_many, belongs_to, has_one relationships
- Validations: All model validations and rules
- Methods: Available instance and class methods
"Show me the User model structure"
Execute safe, read-only database queries:
- Read-Only: Only SELECT operations allowed
- Safe Execution: Automatic query analysis
- Result Limiting: Prevents large data dumps
- Model Context: Works within your model definitions
"Get the 10 most recent orders" "Count active users"
You can pass an optionalwherehash to filter records before invoking the method. For example,safe_query(model: "User", method: "count", where: { active: true })runsUser.where(active: true).count. The same applies tosum,average,minimum,maximum,pluck, andexists?.
Analyze Ruby code for safety without executing:
- Risk Assessment: Categorizes code by danger level
- Safety Analysis: Identifies potential issues
- Recommendations: Suggests safer alternatives
- Zero Execution: Never runs the actual code
"Analyze this code for safety:User.delete_all"
Automatic Detection of Dangerous Operations
The gem automatically detects and blocks:
- Mass deletions (delete_all,destroy_all)
- System commands (system,exec, backticks)
- File operations (File.delete,FileUtils)
- Raw SQL execution
- Code evaluation (eval,send)
- Process manipulation (exit,fork)
- Critical: Never allowed (system commands, file deletion)
- High: Blocked in safe mode (mass deletions, eval)
- Medium: Logged but allowed (raw SQL, update_all)
- Low: Generally safe (environment access, require)
The gem can detect read-only operations and provide additional safety:
# These are considered safe read-only operations User.find(1) User.where(active: true).count Post.includes(:comments).limit(10)
Rails Active MCP uses the official MCP Ruby SDK (mcpgem) for:
- Professional Protocol Handling: Robust JSON-RPC 2.0 implementation
- Built-in Instrumentation: Automatic timing and error reporting
- Future-Proof: Automatic updates as MCP specification evolves
- Standards Compliance: Full MCP protocol compatibility
The server is implemented inlib/rails_active_mcp/sdk/server.rband provides:
- STDIO Transport: Compatible with all major MCP clients
- Tool Registration: Automatic discovery of available tools
- Error Handling: Comprehensive error reporting and recovery
- Rails Integration: Deep integration with Rails applications
Each tool is implemented as a separate class inlib/rails_active_mcp/sdk/tools/:
- ConsoleExecuteTool: Safe code execution
- ModelInfoTool: Model introspection
- SafeQueryTool: Read-only database access
- DryRunTool: Code safety analysis
- RailsActiveMcp::SafetyError: Code failed safety checks
- RailsActiveMcp::TimeoutError: Execution timed out
- RailsActiveMcp::ExecutionError: General execution failure
All errors are properly reported through the MCP protocol with detailed messages.
# Run tests bundle exec rspec # Test MCP server protocol compliance ./bin/test-mcp-output
- Fork it
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
The gem is available as open source under theMIT License.
This is a web browser that enables your coding agent, such as Claude Code, to visit websites on your behalf and assist you in identifying bugs or creating UI test cases.
An MCP server for interacting with SAP systems using ABAP Development Tools (ADT).
Paid remote MCP for schema drift checks, tool-schema approvals, compatibility receipts, breaking-change explanations, and release audit logs.
The official developer experience MCP Server for Amazon DynamoDB. This server provides DynamoDB expert design guidance and data modeling assistance.
All Azure MCP tools in a single server. The Azure MCP Server implements the MCP specification to create a seamless connection between AI agents and Azure services. Azure MCP Server can be used alone or with the GitHub Copilot for Azure extension in VS Code.
Flag features, manage company data, and control feature access using Bucket.
Enable AI Agents to fix build failures from CircleCI.
interacts with ConfigCat feature flag platform. Supports managing feature flags, configs, environments, products and organizations. Helps to integrate ConfigCat SDK, implement feature flags or remove zombie (stale) flags.
Boost security in your dev lifecycle via SAST, SCA, Secrets & IaC scanning with Cycode.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





