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.
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.
The Rails MCP Server follows the XDG Base Directory Specification for configuration files:
$XDG_CONFIG_HOME/rails-mcp
or ~/.config/rails-mcp
if XDG_CONFIG_HOME is not set%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:
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.
The Rails MCP Server can run in two modes:
# 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:
http://localhost:<port>/mcp/messages
http://localhost:<port>/mcp/sse
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.
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
Run the setup script to automatically configure Claude Desktop:
rails-mcp-setup-claude
The script will:
projects.yml
file if it doesn't existAfter running the script, restart Claude Desktop to apply the changes.
Create the appropriate config directory for your platform:
$XDG_CONFIG_HOME/rails-mcp
or ~/.config/rails-mcp
if XDG_CONFIG_HOME is not set%APPDATA%\rails-mcp
Create a projects.yml
file in that directory with your Rails projects.
Find or create the Claude Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add or update the MCP server configuration:
{
"mcpServers": {
"railsMcpServer": {
"command": "ruby",
"args": ["/full/path/to/rails-mcp-server/exe/rails-mcp-server"]
}
}
}
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"]
}
}
}
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 fileproject_info
Description: Retrieve comprehensive information about the current Rails project.
Parameters: None
list_files
Description: List files in the Rails project matching specific criteria.
Parameters:
directory
: (String, optional) Directory path relative to the project rootpattern
: (String, optional) File pattern using glob syntaxget_file
Description: Retrieve the complete content of a specific file with syntax highlighting.
Parameters:
path
: (String, required) File path relative to the project rootget_routes
Description: Retrieve all HTTP routes defined in the Rails application.
Parameters: None
analyze_models
Description: Retrieve detailed information about Active Record models in the project.
Parameters:
model_name
: (String, optional) Class name of a specific modelget_schema
Description: Retrieve database schema information for the Rails application.
Parameters:
table_name
: (String, optional) Database table nameanalyze_controller_views
Description: Analyze the relationships between controllers, their actions, and corresponding views.
Parameters:
controller_name
: (String, optional) Name of a specific controller to analyzeanalyze_environment_config
Description: Analyze environment configurations to identify inconsistencies.
Parameters: None
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 loadThe 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/
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
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.
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.
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"
]
}
}
}
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.
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.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.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