Rails Explorer MCP server

Enables AI models to explore and understand Rails projects by providing tools for file browsing, route inspection, model analysis, and database schema retrieval across multiple applications.
Back to servers
Setup instructions
Provider
Mario Alberto Chávez Cárdenas
Release date
Mar 21, 2025
Language
Ruby
Stats
338 stars

Rails MCP Server is a Ruby implementation that enables Large Language Models (LLMs) to interact with Rails projects through the Model Context Protocol. It provides capabilities for code analysis, exploration, and development assistance, allowing AI models to navigate and understand Rails codebases.

Installation

Install the gem using the command:

gem install rails-mcp-server

After installation, the rails-mcp-server and rails-mcp-setup-claude executables will be available in your PATH.

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

  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 is a project name (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:<port>/mcp/messages
  • SSE endpoint: http://localhost:<port>/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, 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

Security Note: Only use --bind-all on trusted networks.

Logging Options

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

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

Claude Desktop Integration

Option 1: Use the setup script (recommended)

Run the setup script to 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 2: Direct Configuration

  1. Create the appropriate config directory for your platform:

    • macOS: $XDG_CONFIG_HOME/rails-mcp or ~/.config/rails-mcp if XDG_CONFIG_HOME is not set
    • Windows: %APPDATA%\rails-mcp
  2. Create a projects.yml file in that directory with your Rails projects.

  3. Find or create the Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  4. 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. If you are using a Ruby version manager such as rbenv, use the Ruby shim path to ensure the correct version:

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

Available Tools

1. switch_project

Description: Change the active Rails project to interact with a different codebase.

Parameters:

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

2. project_info

Description: Retrieve comprehensive information about the current Rails project.

Parameters: None

3. list_files

Description: List files in the Rails project matching specific criteria.

Parameters:

  • directory: (String, optional) Directory path relative to the project root
  • pattern: (String, optional) File pattern using glob syntax

4. get_file

Description: Retrieve the complete content of a specific file with syntax highlighting.

Parameters:

  • path: (String, required) File path relative to the project root

5. get_routes

Description: Retrieve all HTTP routes defined in the Rails application.

Parameters: None

6. analyze_models

Description: Retrieve detailed information about Active Record models in the project.

Parameters:

  • model_name: (String, optional) Class name of a specific model

7. get_schema

Description: Retrieve database schema information for the Rails application.

Parameters:

  • table_name: (String, optional) Database table name

8. analyze_controller_views

Description: Analyze the relationships between controllers, their actions, and corresponding views.

Parameters:

  • controller_name: (String, optional) Name of a specific controller to analyze

9. analyze_environment_config

Description: Analyze environment configurations to identify inconsistencies.

Parameters: None

10. load_guide

Description: Load documentation guides from Rails, Turbo, Stimulus, Kamal, or Custom.

Parameters:

  • guides: (String, required) The guides library to search: 'rails', 'turbo', 'stimulus', 'kamal', or 'custom'
  • guide: (String, optional) Specific guide name to load

Resources and Documentation

The Rails MCP Server provides access to comprehensive documentation through both the load_guide tool and direct MCP resource access.

Before using resources, you need to download them:

# Download Rails guides
rails-mcp-server-download-resources rails

# Download Turbo guides
rails-mcp-server-download-resources turbo

# Import custom markdown files
rails-mcp-server-download-resources --file /path/to/your/docs/

Testing and Debugging

The easiest way to test and debug the Rails MCP Server is by using the MCP Inspector:

# Install and run MCP Inspector with your Rails MCP Server
npm -g install @modelcontextprotocol/inspector

npx @modelcontextprotocol/inspector /path/to/rails-mcp-server

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "railsMcpServer" '{"command":"ruby","args":["/full/path/to/rails-mcp-server/exe/rails-mcp-server"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later