The Rails MCP Server is a Ruby gem implementation of a Model Context Protocol (MCP) server designed for Rails projects. It enables Large Language Models (LLMs) to interact with Rails applications through the Model Context Protocol, facilitating code analysis, exploration, and assistance.
The Model Context Protocol (MCP) is a standardized method for AI models to interact with their environment. It allows models to request tools, access resources, and maintain context during interactions. This Rails MCP Server implements the MCP specification to provide AI models with access to Rails projects.
Install the gem using the following 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:
- macOS: $XDG_CONFIG_HOME/rails-mcp
or ~/.config/rails-mcp
if XDG_CONFIG_HOME
is not set
- Windows: %APPDATA%\rails-mcp
To configure your projects, edit the projects.yml
file in your config directory:
store: "~/projects/store"
blog: "~/projects/rails-blog"
The Rails MCP Server can be integrated with Claude Desktop. There are two setup options:
Run the setup script to automatically configure Claude Desktop:
rails-mcp-setup-claude
projects.yml
file.{
"mcpServers": {
"railsMcpServer": {
"command": "ruby",
"args": ["/full/path/to/rails-mcp-server/exe/rails-mcp-server"]
}
}
}
For users of Ruby version managers like rbenv or RVM, create a symbolic link to ensure the correct Ruby version is used:
sudo ln -s /home/your_user/.rbenv/shims/ruby /usr/local/bin/ruby
Start the server with:
rails-mcp-server
Customize logging with the following options:
rails-mcp-server --log-level debug
The Rails MCP Server implements the Model Context Protocol over standard input/output (stdio). It reads JSON-RPC 2.0 requests, processes them using the appropriate tools, and returns JSON-RPC 2.0 responses.
The server provides the following tools for interacting with Rails projects:
switch_project
Switch the active Rails project.
{
"jsonrpc": "2.0",
"id": "123",
"method": "tools/call",
"params": {
"name": "switch_project",
"arguments": {
"project_name": "blog"
}
}
}
get_project_info
Get information about the current Rails project.
{
"jsonrpc": "2.0",
"id": "124",
"method": "tools/call",
"params": {
"name": "get_project_info",
"arguments": {}
}
}
list_files
List files in the Rails project.
{
"jsonrpc": "2.0",
"id": "125",
"method": "tools/call",
"params": {
"name": "list_files",
"arguments": {
"directory": "app/models",
"pattern": "*.rb"
}
}
}
get_file
Get the content of a file in the Rails project.
{
"jsonrpc": "2.0",
"id": "126",
"method": "tools/call",
"params": {
"name": "get_file",
"arguments": {
"path": "app/models/user.rb"
}
}
}
get_routes
Get the routes defined in the Rails project.
{
"jsonrpc": "2.0",
"id": "127",
"method": "tools/call",
"params": {
"name": "get_routes",
"arguments": {}
}
}
get_models
Get information about the models in the Rails project.
{
"jsonrpc": "2.0",
"id": "128",
"method": "tools/call",
"params": {
"name": "get_models",
"arguments": {
"model_name": "User"
}
}
}
get_schema
Get the database schema for the Rails project.
{
"jsonrpc": "2.0",
"id": "129",
"method": "tools/call",
"params": {
"name": "get_schema",
"arguments": {
"table_name": "users"
}
}
}
The Rails MCP Server is designed to integrate with LLM clients that support the Model Context Protocol, such as Claude Desktop or other MCP-compatible applications.
You can manually test the server by sending JSON-RPC requests to its standard input:
echo '0 {"jsonrpc":"2.0","id":"test-123","method":"ping"}' | rails-mcp-server
This Rails MCP Server is released under the MIT License.
Bug reports and pull requests are welcome on GitHub.
A Ruby gem implementation of a Model Context Protocol (MCP) server for Rails projects. This server allows LLMs to interact with Rails projects through the Model Context Protocol.