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.
📌Overview
Purpose: To provide a Ruby implementation of a Model Context Protocol (MCP) server that enables Large Language Models (LLMs) to interact with Rails projects effectively.
Overview: The Rails MCP Server is designed to facilitate seamless communication between AI models and Rails applications by implementing the Model Context Protocol. This standardized protocol allows AI models to perform tasks such as code analysis and exploration within Rails projects.
Key Features:
-
Manage Multiple Projects: Supports interaction with multiple Rails projects, allowing users to switch between them seamlessly.
-
Project File Exploration: Users can browse, list, and inspect files within a Rails project to analyze its structure and content.
-
Access to Rails Routes and Models: Retrieve detailed information about defined routes and Active Record models, including schema, associations, and definitions.
-
Database Schema Retrieval: Fetch schema information for the entire database or specific tables, enhancing understanding of the project’s database design.
-
MCP Compliance: Adheres to the Model Context Protocol standard, ensuring compatibility with various LLM clients.
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.
What is MCP?
The Model Context Protocol (MCP) is a standardized method for AI models to interact with their environment. It defines a way for models to request and use tools, access resources, and maintain context during interactions.
Features
- Manage multiple Rails projects
- Browse project files and structures
- View Rails routes
- Inspect model information
- Get database schema information
- Follow the Model Context Protocol standard
Installation
Install the gem:
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:
- macOS:
$XDG_CONFIG_HOME/rails-mcp
or~/.config/rails-mcp
- Windows:
%APPDATA%\rails-mcp
To configure your projects, edit the projects.yml
file:
store: "~/projects/store"
blog: "~/projects/rails-blog"
Claude Desktop Integration
The Rails MCP Server can be configured with Claude Desktop using one of the following options:
Option 1: Setup Script
Run the setup script:
rails-mcp-setup-claude
Option 2: Manual Configuration
- Create the appropriate config directory.
- Create a
projects.yml
file in that directory. - Update the Claude Desktop configuration file.
Ruby Version Manager Users
Ensure the MCP server uses the same Ruby version as it was installed by creating a symbolic link to your Ruby shim.
Usage
Start the server:
rails-mcp-server
Logging Options
Customize logging with these options:
rails-mcp-server --log-level debug
How the Server Works
The Rails MCP Server implements the Model Context Protocol over standard input/output (stdio), processing JSON-RPC 2.0 requests and returning responses.
Available Tools
1. switch_project
Description: Change the active Rails project.
2. get_project_info
Description: Retrieve information about the current Rails project.
3. list_files
Description: List files in the Rails project.
4. get_file
Description: Get the content of a file in the Rails project.
5. get_routes
Description: Get the routes defined in the Rails project.
6. get_models
Description: Get information about the models in the Rails project.
7. get_schema
Description: Get the database schema for the Rails project.
Integration with LLM Clients
To integrate with LLM clients:
- Start the Rails MCP Server.
- Connect your MCP-compatible client to the server.
Manual Testing
You can manually test the server by sending JSON-RPC requests. For example:
echo '0 {"jsonrpc":"2.0","id":"test-123","method":"ping"}' | rails-mcp-server
License
This Rails MCP server is released under the MIT License, allowing free use, modification, and distribution.
Contributing
Bug reports and pull requests are welcome on GitHub at rails-mcp-server.