AgentStack
MCP verified MIT Self-run

Rails Mcp Server

mcp-maquina-app-rails-mcp-server · by maquina-app

A Ruby gem implementation of a Model Context Protocol (MCP) server for Rails projects. This server allows LLMs (Large Language Models) to interact with Rails projects through the Model Context Protocol.

No reviews yet
0 installs
10 views
0.0% view→install

Install

$ agentstack add mcp-maquina-app-rails-mcp-server

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets Used
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Rails Mcp Server? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Rails MCP Server

A Ruby implementation of a Model Context Protocol (MCP) server for Rails projects. This server allows LLMs (Large Language Models) to interact with Rails projects through the Model Context Protocol, providing capabilities for code analysis, exploration, and development assistance.

What is MCP?

The Model Context Protocol (MCP) is a standardized way for AI models to interact with their environment. It defines a structured method for models to request and use tools, access resources, and maintain context during interactions.

This Rails MCP Server implements the MCP specification to give AI models access to Rails projects for code analysis, exploration, and assistance.

Features

  • Manage multiple Rails projects
  • Browse project files and structures
  • View Rails routes with filtering options
  • Inspect model information and relationships (with Prism static analysis)
  • Get database schema information
  • Analyze controller-view relationships
  • Analyze environment configurations
  • Execute sandboxed Ruby code for custom queries
  • Access comprehensive Rails, Turbo, Stimulus, and Kamal documentation
  • Context-efficient architecture with progressive tool discovery
  • Seamless integration with LLM clients

Installation

Install the gem:

gem install rails-mcp-server

After installation, the following executables will be available in your PATH:

  • rails-mcp-server - The MCP server itself
  • rails-mcp-config - Interactive configuration tool (recommended)
  • rails-mcp-setup-claude - Legacy Claude Desktop setup script
  • rails-mcp-server-download-resources - Legacy resource download script

Configuration

Using the Configuration Tool (Recommended)

The easiest way to configure the Rails MCP Server is using the interactive configuration tool:

rails-mcp-config

This provides a user-friendly TUI (Terminal User Interface) for:

  • Managing Projects: Add, edit, remove, and validate Rails projects
  • Downloading Guides: Download Rails, Turbo, Stimulus, and Kamal documentation
  • Importing Custom Guides: Add your own markdown documentation
  • Claude Desktop Integration: Automatically configure Claude Desktop

The tool uses Gum for an enhanced experience if installed, but works with a basic terminal fallback.

# Install Gum for best experience (optional)
brew install gum        # macOS
sudo apt install gum    # Debian/Ubuntu
yay -S gum              # Arch Linux

Manual Configuration

The Rails MCP Server follows the XDG Base Directory Specification for configuration files:

  • On macOS: $XDG_CONFIG_HOME/rails-mcp or ~/.config/rails-mcp if XDGCONFIGHOME is not set
  • On Windows: %APPDATA%\rails-mcp

The server will automatically create these directories and an empty projects.yml file the first time it runs.

To configure your projects manually:

  1. Edit the projects.yml file in your config directory to include your Rails projects:
store: "~/projects/store"
blog: "~/projects/rails-blog"
ecommerce: "/full/path/to/ecommerce-app"

Each key in the YAML file is a project name (which will be used with the switch_project tool), and each value is the path to the project directory.

Usage

Starting the server

The Rails MCP Server can run in two modes:

  1. STDIO mode (default): Communicates over standard input/output for direct integration with clients like Claude Desktop.
  2. HTTP mode: Runs as an HTTP server with JSON-RPC and Server-Sent Events (SSE) endpoints.
# Start in default STDIO mode
rails-mcp-server

# Start in HTTP mode on the default port (6029)
rails-mcp-server --mode http

# Start in HTTP mode on a custom port
rails-mcp-server --mode http -p 8080

# Start in HTTP mode binding to all interfaces (for local network access)
rails-mcp-server --mode http --bind-all

When running in HTTP mode, the server provides two endpoints:

  • JSON-RPC endpoint: http://localhost:/mcp/messages
  • SSE endpoint: http://localhost:/mcp/sse

Network Access (HTTP Mode)

By default, the HTTP server only binds to localhost for security. If you need to access the server from other machines on your local network (e.g., for testing with multiple devices), you can use the --bind-all flag:

# Allow access from any machine on your local network
rails-mcp-server --mode http --bind-all

# With a custom port
rails-mcp-server --mode http --bind-all -p 8080

When using --bind-all:

  • The server binds to 0.0.0.0 instead of localhost
  • Access is allowed from local network IP ranges (192.168.x.x, 10.x.x.x)
  • The server accepts connections from .local domain names (e.g., my-computer.local)
  • Security features remain active to prevent unauthorized access

Security Note: Only use --bind-all on trusted networks. The server includes built-in security features to validate origins and IP addresses, but exposing any service to your network increases the attack surface.

Logging Options

The server logs to a file in the ./log directory by default. You can customize logging with these options:

# Set the log level (debug, info, error)
rails-mcp-server --log-level debug

Claude Desktop Integration

The Rails MCP Server can be used with Claude Desktop. There are multiple options to set this up:

Option 1: Use the configuration tool (recommended)

Run the interactive configuration tool and select "Claude Desktop integration":

rails-mcp-config

The tool will:

  • Detect your current Claude Desktop configuration
  • Let you choose between STDIO or HTTP mode
  • Automatically find the correct Ruby and server paths
  • Create a backup before making changes
  • Update the Claude Desktop configuration

Option 2: Use the setup script (legacy)

Run the setup script which will automatically configure Claude Desktop:

rails-mcp-setup-claude

The script will:

  • Create the appropriate config directory for your platform
  • Create an empty projects.yml file if it doesn't exist
  • Update the Claude Desktop configuration

After running the script, restart Claude Desktop to apply the changes.

Option 3: Direct Configuration

  1. Create the appropriate config directory for your platform:
  • macOS: $XDG_CONFIG_HOME/rails-mcp or ~/.config/rails-mcp if XDGCONFIGHOME is not set
  • Windows: %APPDATA%\rails-mcp
  1. Create a projects.yml file in that directory with your Rails projects.
  1. Find or create the Claude Desktop configuration file:
  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  1. Add or update the MCP server configuration:
{
  "mcpServers": {
    "railsMcpServer": {
      "command": "ruby",
      "args": ["/full/path/to/rails-mcp-server/exe/rails-mcp-server"] 
    }
  }
}
  1. Restart Claude Desktop to apply the changes.

Ruby Version Manager Users

Claude Desktop launches the MCP server using your system's default Ruby environment, bypassing version manager initialization (e.g., rbenv, RVM). The MCP server needs to use the same Ruby version where it was installed, as MCP server startup failures can occur when using an incompatible Ruby version.

If you are using a Ruby version manager such as rbenv, you can use the Ruby shim path to ensure the correct version is used:

{
  "mcpServers": {
    "railsMcpServer": {
      "command": "/home/your_user/.rbenv/shims/ruby",
      "args": ["/full/path/to/rails-mcp-server/exe/rails-mcp-server"] 
    }
  }
}

Replace "/home/your_user/.rbenv/shims/ruby" with your actual path for the Ruby shim.

Tip: The rails-mcp-config tool automatically detects your Ruby path and uses the correct shim path when configuring Claude Desktop.

Using an MCP Proxy (Advanced)

Claude Desktop and many other LLM clients only support STDIO mode communication, but you might want to use the HTTP/SSE capabilities of the server. An MCP proxy can bridge this gap:

  1. Start the Rails MCP Server in HTTP mode:
rails-mcp-server --mode http
  1. Install and run an MCP proxy. There are several implementations available in different languages. An MCP proxy allows a client that only supports STDIO communication to communicate via HTTP SSE. Here's an example using a JavaScript-based MCP proxy:
# Install the Node.js based MCP proxy
npm install -g mcp-remote

# Run the proxy, pointing to your running Rails MCP Server
npx mcp-remote http://localhost:6029/mcp/sse
  1. Configure Claude Desktop (or other LLM client) to use the proxy instead of connecting directly to the server:
{
  "mcpServers": {
    "railsMcpServer": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:6029/mcp/sse"]
    }
  }
}

This setup allows STDIO-only clients to communicate with the Rails MCP Server through the proxy, benefiting from the HTTP/SSE capabilities while maintaining client compatibility.

Tip: The rails-mcp-config tool can configure HTTP mode with mcp-remote automatically.

GitHub Copilot Agent Integration

Rails MCP Server works with GitHub Copilot coding agent out of the box. The server auto-detects Rails projects when started from a Rails directory or when configured with environment variables.

Quick Setup

  1. Configure MCP - Create .github/copilot/mcp.json in your repository:
{
  "mcpServers": {
    "rails": {
      "type": "local",
      "command": "rails-mcp-server",
      "args": ["--single-project"],
      "tools": ["switch_project", "search_tools", "execute_tool", "execute_ruby"]
    }
  }
}
  1. Setup Steps - Create .github/workflows/copilot-setup-steps.yml:
name: "Copilot Setup Steps"

on: workflow_dispatch

jobs:
  copilot-setup-steps:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: '3.3'
          bundler-cache: true

      - name: Install Rails MCP Server
        run: gem install rails-mcp-server

Alternative: Environment Variable

You can also use the RAILS_MCP_PROJECT_PATH environment variable:

{
  "mcpServers": {
    "rails": {
      "type": "local",
      "command": "rails-mcp-server",
      "env": {
        "RAILS_MCP_PROJECT_PATH": "."
      },
      "tools": ["switch_project", "search_tools", "execute_tool", "execute_ruby"]
    }
  }
}

Limitations

  • GitHub Copilot Agent only supports MCP tools, not resources or prompts
  • The load_guide analyzer works via execute_tool, but requires guides to be downloaded during setup

For detailed instructions, see [docs/COPILOTAGENT.md](docs/COPILOTAGENT.md).

How the Server Works

The Rails MCP Server implements the Model Context Protocol using either:

  • STDIO mode: Reads JSON-RPC 2.0 requests from standard input and returns responses to standard output.
  • HTTP mode: Provides HTTP endpoints for JSON-RPC 2.0 requests and Server-Sent Events.

Each request includes a sequence number to match requests with responses, as defined in the MCP specification. The server maintains project context and provides Rails-specific analysis capabilities across multiple codebases.

Context-Efficient Architecture

The server uses a progressive tool discovery architecture to minimize context usage. Instead of exposing all tools upfront, it provides 4 bootstrap tools that allow LLMs to discover and invoke additional analyzers on-demand:

  • switch_project - Select the active Rails project
  • search_tools - Discover available tools by category or keyword
  • execute_tool - Invoke internal analyzers with parameters
  • execute_ruby - Run sandboxed Ruby code for custom queries

This design reduces initial context from ~2,400 tokens to ~800 tokens while maintaining full functionality.

AI Agent Guide

For AI agents (Claude, GPT, etc.) using this server, see the comprehensive [AI Agent Guide](docs/AGENT.md) which covers:

  • Quick start workflow
  • Tool selection guide for common tasks
  • Helper methods available in execute_ruby
  • Common pitfalls and how to avoid them
  • Error handling and fallback strategies
  • Integration with other MCP servers (e.g., Neovim MCP)

Available Tools

The server provides 4 registered tools plus internal analyzers accessible via execute_tool.

Registered Tools

1. switch_project

Description: Change the active Rails project. Must be called before using other tools.

Parameters:

  • project_name: (String, required) Name of the project as defined in projects.yml

After switching, you'll see a Quick Start guide with common commands.

2. search_tools

Description: Discover available tools by category or keyword.

Parameters:

  • query: (String, optional) Search term (e.g., 'routes', 'model', 'schema')
  • category: (String, optional) Filter by category: models, database, routing, controllers, files, project, guides
  • detail_level: (String, optional) Output detail: 'names', 'summary', or 'full' (default: 'summary')
3. execute_tool

Description: Invoke internal analyzers by name.

Parameters:

  • tool_name: (String, required) Name of the analyzer (e.g., 'getroutes', 'analyzemodels')
  • params: (Hash, optional) Parameters for the analyzer
4. execute_ruby

Description: Execute sandboxed Ruby code in the Rails project context.

Parameters:

  • code: (String, required) Ruby code to execute
  • timeout: (Integer, optional) Timeout in seconds (default: 30, max: 60)

Available helper methods:

  • read_file(path) - Read a file safely
  • file_exists?(path) - Check if a file exists
  • list_files(pattern) - Glob files (e.g., 'app/models/**/*.rb')
  • project_root - Get the project root path

Note: Use puts to see output from your code.

Security: The sandbox prevents file writes, system calls, network access, and reading sensitive files (.env, credentials, etc.).

Internal Analyzers (via execute_tool)

project_info

Retrieve comprehensive project information including Rails version, directory structure, and organization.

execute_tool(tool_name: "project_info")
list_files

List files matching a pattern in a directory.

execute_tool(tool_name: "list_files", params: { directory: "app/models", pattern: "*.rb" })
get_file

Retrieve the content of a specific file.

execute_tool(tool_name: "get_file", params: { path: "app/models/user.rb" })
get_routes

Retrieve Rails routes with optional filtering.

execute_tool(tool_name: "get_routes")
execute_tool(tool_name: "get_routes", params: { controller: "users" })
execute_tool(tool_name: "get_routes", params: { verb: "POST" })
execute_tool(tool_name: "get_routes", params: { path_contains: "api" })
analyze_models

Analyze Active Record models with associations, validations, and optional Prism static analysis.

execute_tool(tool_name: "analyze_models")
execute_tool(tool_name: "analyze_models", params: { model_name: "User" })
execute_tool(tool_name: "analyze_models", params: { model_name: "User", analysis_type: "full" })
execute_tool(tool_name: "analyze_models", params: { detail_level: "names" })

Parameters:

  • model_name: Specific model to analyze
  • model_names: Array of models to analyze
  • detail_level: 'names', 'summary', or 'full'
  • analysis_type: 'introspection', 'static', or 'full' (includes Prism AST analysis)
get_schema

Retrieve database schema information.

execute_tool(tool_name: "get_schema")
execute_tool(tool_name: "get_schema", params: { table_name: "users" })
execute_tool(tool_name: "get_schema", params: { detail_level: "tables" })
analyze_controller_views

Analyze controller-view relationships with optional Prism static analysis

Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.