A Ruby gem providing secure Rails console access through MCP for AI agents and development tools.
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 through Model Context Protocol (MCP) for AI agents and development tools like Claude Desktop. Built using the official MCP Ruby SDK for professional protocol handling and future-proof compatibility.
Add this line to your application's Gemfile:
gem 'rails-active-mcp'
And then execute:
bundle install
Run the installer:
rails generate rails_active_mcp:install
This will:
mcp.ru
server file for standalone usageThe gem is configured in config/initializers/rails_active_mcp.rb
:
RailsActiveMcp.configure do |config|
# Core configuration options
config.allowed_commands = %w[
ls pwd cat head tail grep find wc
rails console rails runner
bundle exec rspec bundle exec test
git status git log git diff
]
config.command_timeout = 30
config.enable_logging = true
config.log_level = :info
end
The server runs in STDIO mode, perfect for Claude Desktop integration:
$ bundle exec rails-active-mcp-server
The server automatically:
Add to your Claude Desktop configuration file:
Location:
~/.config/claude-desktop/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"rails-active-mcp": {
"command": "bundle",
"args": ["exec", "rails-active-mcp-server"],
"cwd": "/path/to/your/rails/project"
}
}
}
Or if installed globally:
{
"mcpServers": {
"rails-active-mcp": {
"command": "rails-active-mcp-server",
"cwd": "/path/to/your/rails/project"
}
}
}
Then in Claude Desktop, you can use prompts like:
# Execute code safely
result = RailsActiveMcp.execute("User.count")
# Check if code is safe
RailsActiveMcp.safe?("User.delete_all") # => false
The Rails Active MCP server provides four powerful tools that appear automatically in Claude Desktop:
console_execute
Execute Ruby code with safety checks and timeout protection:
Example Usage in Claude:
"Execute
User.where(active: true).count
"
model_info
Get detailed information about Rails models:
Example Usage in Claude:
"Show me the User model structure"
safe_query
Execute safe, read-only database queries:
Example Usage in Claude:
"Get the 10 most recent orders"
dry_run
Analyze Ruby code for safety without executing:
Example Usage in Claude:
"Analyze this code for safety:
User.delete_all
"
The gem automatically detects and blocks:
delete_all
, destroy_all
)system
, exec
, backticks)File.delete
, FileUtils
)eval
, send
)exit
, fork
)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 (mcp
gem) for:
The server is implemented in lib/rails_active_mcp/sdk/server.rb
and provides:
Each tool is implemented as a separate class in lib/rails_active_mcp/sdk/tools/
:
ConsoleExecuteTool
: Safe code executionModelInfoTool
: Model introspectionSafeQueryTool
: Read-only database accessDryRunTool
: Code safety analysisThe gem provides specific error types:
RailsActiveMcp::SafetyError
: Code failed safety checksRailsActiveMcp::TimeoutError
: Execution timed outRailsActiveMcp::ExecutionError
: General execution failureAll errors are properly reported through the MCP protocol with detailed messages.
$ bundle exec rspec
$ ./bin/test-mcp-output
This tests the MCP server output redirection and JSON protocol compliance.
Set the debug environment variable for detailed logging:
$ RAILS_MCP_DEBUG=1 bundle exec rails-active-mcp-server
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)The gem is available as open source under the MIT License.
See CHANGELOG.md for detailed version history.
Execute developer-defined bash scripts in a Dockerized environment for coding agents.
An example of a remote MCP server for Odoo, deployable on Cloudflare Workers without authentication.
Work on your code with JetBrains IDEs
ALAPI MCP Tools,Call hundreds of API interfaces via MCP
APIMatic MCP Server is used to validate OpenAPI specifications using APIMatic. The server processes OpenAPI files and returns validation summaries by leveraging APIMaticβs API.
A WordPress plugin that transforms a WordPress site into an MCP server, allowing direct access to its content.
Answers Swift and SwiftUI questions based on the '100 Days of SwiftUI' course using a local SQLite database.
A server for CodeFuse-CGM, a graph-integrated large language model designed for repository-level software engineering tasks.
Interact with your crash reporting and real using monitoring data on your Raygun account
Provides remote machine control capabilities, eliminating SSH overhead for token-efficient system operations.