Logo vun Rails Active MCP

Rails Active MCP

Communautéit
GoodPie

Secure Rails console access for AI agents through Model Context Protocol with safety features and read-only modes

EditeurGoodPie
Repositoryrails-active-mcp
SproochRuby
Forks
5
Stären
16
Disponibel Tools
0
Transporttypstreamable-http
Kategorien
LizenzMIT
Linken
  • Tools mat KI-Workflows verbannen

    Rails Active MCP stellt MCP-Funktioune bereit, déi vu kompatibele KI-Clienten a KI-Agente kënne benotzt ginn.

  • 0 disponibel Tools

    Kuckt Iech déi opruffbar Aktiounen hei drënner un, mat Nimm a Beschreiwungen, wa se vum Server geliwwert ginn.

  • Konfiguratioun fir ze kopéieren

    Benotzt d'Installatiounsbeispiller, fir dëse Server an Ärem bevorzugte MCP-Client ze konfiguréieren.

  • Indicateure fir Open Source

    16 Stären an 5 Forks aus dem verlinkte Repository.

Gem Version

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.

Rails Active MCP

A Ruby gem that provides secure Rails console access through Model 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, and many more.

Quick Start

Get up and running in three steps:

1. Install the gem

Add to your Rails application's Gemfile:

ruby
gem 'rails-active-mcp'
bash
bundle install

2. Run the installer

bash
rails generate rails_active_mcp:install

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.

3. Connect your MCP client

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.

Edit your config file:

  • macOS/Linux: ~/.config/claude-desktop/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
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.

From your Rails project directory:

bash
claude mcp add rails-active-mcp -- bundle exec rails-active-mcp-server

Or add it to your project's .mcp.json:

json
{
  "mcpServers": {
    "rails-active-mcp": {
      "command": "bundle",
      "args": ["exec", "rails-active-mcp-server"]
    }
  }
}

Add to your workspace .vscode/mcp.json:

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:

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:

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):

json
{
  "context_servers": {
    "rails-active-mcp": {
      "command": {
        "path": "bundle",
        "args": ["exec", "rails-active-mcp-server"],
        "env": {}
      }
    }
  }
}

In ChatGPT Desktop, go to Settings > Connectors > Advanced > Developer Mode, then add:

json
{
  "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 the full list of MCP clients for more options.

Once connected, four tools will appear automatically: console_execute, model_info, safe_query, and dry_run.

Try asking your AI assistant:

  • "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"

Features

  • 🔒 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

Configuration

The installer creates a default configuration at config/initializers/rails_active_mcp.rb. The defaults work out of the box, but you can customize behavior:

ruby
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

Usage

MCP Client (Recommended)

Once connected (see Quick Start), your MCP client automatically runs the server for you. The server loads your Rails application, initializes models, and provides secure access to your Rails environment via STDIO transport.

Direct Usage

You can also use the gem directly in Ruby:

ruby
# Execute code safely
result = RailsActiveMcp.execute("User.count")

# Check if code is safe
RailsActiveMcp.safe?("User.delete_all") # => false

Running the Server Manually

If you need to run the server directly (e.g., for debugging):

bash
bundle exec rails-active-mcp-server

# With debug logging
RAILS_MCP_DEBUG=1 bundle exec rails-active-mcp-server

Rake Tasks

The gem provides several rake tasks for diagnostics and testing:

bash
# 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

Available MCP Tools

The Rails Active MCP server provides four powerful tools that appear automatically in any connected MCP client:

1. console_execute

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

Example prompt:

"Execute User.where(active: true).count"

2. model_info

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

Example prompt:

"Show me the User model structure"

3. safe_query

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

Example prompt:

"Get the 10 most recent orders" "Count active users"

You can pass an optional where hash to filter records before invoking the method. For example, safe_query(model: "User", method: "count", where: { active: true }) runs User.where(active: true).count. The same applies to sum, average, minimum, maximum, pluck, and exists?.

4. dry_run

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

Example prompt:

"Analyze this code for safety: User.delete_all"

Safety Features

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)

Safety Levels

  • 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)

Read-Only Mode

The gem can detect read-only operations and provide additional safety:

ruby
# These are considered safe read-only operations
User.find(1)
User.where(active: true).count
Post.includes(:comments).limit(10)

Architecture

Built on Official MCP Ruby SDK

Rails Active MCP uses the official MCP Ruby SDK (mcp gem) 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

Server Implementation

The server is implemented in lib/rails_active_mcp/sdk/server.rb and 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

Tool Architecture

Each tool is implemented as a separate class in lib/rails_active_mcp/sdk/tools/:

  • ConsoleExecuteTool: Safe code execution
  • ModelInfoTool: Model introspection
  • SafeQueryTool: Read-only database access
  • DryRunTool: Code safety analysis

Error Handling

The gem provides specific error types:

  • 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.

Development and Testing

bash
# Run tests
bundle exec rspec

# Test MCP server protocol compliance
./bin/test-mcp-output

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

The gem is available as open source under the MIT License.

Installatioun

TypingMind
Viraussetzungen:

Node.js 18+

{
  "mcpServers": {
    "goodpie-rails-active-mcp": {
      "command": "",
      "args": []
    }
  }
}

Rails Active MCP MCP mat verschiddene KI-Modeller benotzen

TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Soubal Rails Active MCP verbonnen ass, kënnt Dir et mat verschiddene KI-Modeller an TypingMind benotzen, amplaz et fir all Modell separat anzeriichten. Dës MCP-Integratioun verbënnt sech an TypingMind iwwer d'URL vun engem gehoste MCP-Server.

Eng MCP-Server-URL derbäisetzen

Benotzt dës Optioun, wann Rails Active MCP scho remote gehost gëtt oder Är Ekipp ee gemeinsame Connector wëllt, op dee méi Benotzer kënnen zougräifen.

1

MCP-Connectoren opmaachen

Gitt an TypingMind op „Plugins“, maacht „MCP-Connectoren“ op a wielt dann „URL derbäisetzen“.

  1. Maacht TypingMind an Ärem Browser op.
  2. Gitt op „Plugins“.
  3. Maacht „MCP-Connectoren“ op.
  4. Klickt op „URL derbäisetzen“.
TypingMind-Formulaire fir eng benotzerdefinéiert MCP-Server-URL derbäizesetzen
2

D'Server-URL apeschen

Gitt Är Server-URL am Feld „Server-URL“ an. Setzt e Verbindungsnumm, eng Beschreiwung, e Symbol, benotzerdefinéiert HTTP-Headeren oder OAuth-Clientastellungen derbäi, wann de Server se erfuerdert.

  1. Pescht Är Server-URL an d'Feld „Server-URL“.
  2. Gitt en Numm fir d'Verbindung mat Rails Active MCP an.
  3. Setzt eng Beschreiwung an e Symbol derbäi, fir d'Verbindung méi einfach erëmzeerkennen.
  4. Setzt benotzerdefinéiert HTTP-Headeren oder OAuth-Clientdetailer derbäi, wann de Server eng Authentifizéierung erfuerdert.
3

D'Verbindung erstellen

Klickt op „Verbindung erstellen“, gitt dann zeréck op d'Plugin-Lëscht a kontrolléiert, ob déi nei MCP-Verbindung aktiv ass.

  1. Klickt op „Verbindung erstellen“.
  2. Gitt zeréck op d'Lëscht vun de MCP-Connectoren.
  3. Kontrolléiert, ob d'Verbindung mat Rails Active MCP als aktiv ugewise gëtt.
  4. Aktualiséiert d'Plugin-Lëscht, wann d'Verbindung net direkt ugewise gëtt.
4

Modeller wiesselen ouni nei ze verbannen

Start e Chat mat Ärem bevorzugte Modell, aktivéiert d'Tools vu Rails Active MCP ënner „Plugins“ a wiesselt bei Bedarf op en anere Modell. D'MCP-Verbindung bleift am TypingMind-Aarbechtsberäich disponibel.

  1. Start en neie Chat an TypingMind.
  2. Wielt de KI-Modell, deen Dir benotze wëllt.
  3. Aktivéiert d'Tools vu Rails Active MCP ënner „Plugins“.
  4. Biet de Modell, den Tool ze benotzen, wann néideg.
  5. Wiesselt op en anere KI-Modell a benotzt déiselwecht MCP-Verbindung weider.
TypingMind-Chat mat aktivéierte MCP-Tools an engem ausgewielte KI-Modell
Hëlleft Dir mir bei dëser Aufgab mat Rails Active MCP?
Rails Active MCP
Jo. Ech hunn et gelies.
Dat hunn ech mat Rails Active MCP fonnt.

Heefeg gestallte Froen

Fir wat gëtt de MCP-Server Rails Active MCP benotzt?

Rails Active MCP ass e MCP-Server, deen et kompatibele KI-Clienten erlaabt, sech mat externen Tools a Kontext ze verbannen. An TypingMind kënnt Dir dëse MCP-Server eemol derbäisetzen a seng Tools an Ärem KI-Aarbechtsberäich zur Verfügung stellen.

Kann ech Rails Active MCP MCP mat méi KI-Modeller an TypingMind benotzen?

Jo. TypingMind verbënnt MCP-Tools um Niveau vum Aarbechtsberäich. Sou kënnt Dir Rails Active MCP mat verschiddene KI-Modeller wéi Claude, ChatGPT, Gemini oder anere Modeller benotzen, déi Dir an TypingMind konfiguréiert hutt, ouni de MCP-Server fir all Modell separat anzeriichten.

Firwat Rails Active MCP MCP mat TypingMind benotzen?

TypingMind ass eng vun de beschte Benotzeruewerfläche fir LLM-Chat, well et méi KI-Modeller, Prompts, Plugins, KI-Agenten, API-Schlësselen a MCP-Tools an engem Aarbechtsberäich zesummebréngt. Wann Rails Active MCP verbonnen ass, kënnt Dir seng MCP-Tools mat Äre bevorzugte Modeller benotzen a gläichzäiteg Är Chataarbecht an TypingMind organiséieren.

Wéi verbannen ech Rails Active MCP MCP mat TypingMind?

Dir kënnt Rails Active MCP mat TypingMind verbannen, andeems Dir d'URL vu sengem gehoste MCP-Server derbäisetzt. Dat ass nëtzlech, wann Dir eng Remote-MCP-Verbindung wëllt, déi aus Ärem TypingMind-Aarbechtsberäich disponibel ass.

Wéi eng Tools stellt Rails Active MCP MCP an TypingMind zur Verfügung?

Rails Active MCP stellt MCP-Funktiounen zur Verfügung, déi Dir op der Plugins-Säit vun TypingMind aktivéiere kënnt, fir se am Chat ze benotzen oder KI-Agenten zouzeweisen.

Muss ech meng API-Schlëssele mat TypingMind deelen, fir Rails Active MCP MCP ze benotzen?

Nee. TypingMind setzt op lokal Veraarbechtung a léisst Iech d'Kontroll iwwer Är Modellubidder, API-Schlësselen, Prompts a MCP-Konfiguratioun. Wann Rails Active MCP eng Authentifizéierung verlaangt, setzt déi néideg Headeren, OAuth-Astellungen oder lokal Konfiguratioun fir dee MCP-Server derbäi, wann Dir d'Verbindung erstallt.

Änlech MCP-Serveren

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇