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.
An MCP server for the Vercel AI SDK, enabling integrations with Figma and 21st.dev Magic.
Read/write to over 2k blockchains, enabling data querying, contract analysis/deployment, and transaction execution, powered by Thirdweb.
A natural language interface for single-cell RNA sequencing (scRNA-Seq) analysis using the CellRank toolkit.
Provides seamless integration with SonarQube Server or Cloud, and enables analysis of code snippets directly within the agent context
A tool for interacting with Jenkins CI/CD servers, requiring environment variables for configuration.
Image generation and editing using the FLUX.1 Kontext [Max] model via the Replicate API, featuring advanced text rendering and contextual understanding.
An example of a remote MCP server deployable on Cloudflare Workers without authentication.
A comprehensive toolkit for AI-driven development, offering file system operations, code analysis, execution, web searching, and system information retrieval.
Create mock MCP servers instantly for developing and testing agentic AI workflows.
A starter template for building Model Context Protocol (MCP) servers, designed for UI libraries and component registries.