
tonksthebear/mcp-rails
Developer toolsЭта страница переведена автоматически. Технические детали смотрите в оригинале. Открыть оригинал
mcp-rails is a Ruby on Rails gem that builds on top of the mcp-rb library to seamlessly integrate MCP (Model Context Protocol) servers into your Rails application.
Обзор
mcp-rails is a Ruby on Rails gem that builds on top of the mcp-rb library to seamlessly integrate MCP (Model Context Protocol) servers into your Rails application. It enhances Rails routes by allowing you to tag them with MCP-specific metadata and generates a valid Ruby MCP server (in tmp/mcp/server.rb) that LLM agents, such as Goose, can connect to. Additionally, it provides a powerful way to define and manage strong parameters in your controllers, which doubles as both MCP server configuration and Rails strong parameter enforcement. This was inspired during the creation of Gaggle. - : Tag Rails routes with mcp: true or specific actions (e.g., mcp: [:index, :create]) to expose them to an MCP server. - : Generates a Ruby MCP server in tmp/mcp/server.rb for LLM agents to interact with your application. - : Define permitted parameters in controllers with rich metadata (e.g., types, examples, required flags) that are used for both MCP server generation and Rails strong parameters.
README
Показан фрагмент оригинального README. Открыть оригинал.
MCP-Rails
Enhance Rails routing and parameter handling for LLM agents with MCP (Model Context Protocol) integration.
mcp-rails is a Ruby on Rails gem that builds on top of the mcp-rb library to seamlessly integrate MCP (Model Context Protocol) servers into your Rails application. It enhances Rails routes by allowing you to tag them with MCP-specific metadata and generates a valid Ruby MCP server (in tmp/mcp/server.rb) that LLM agents, such as Goose, can connect to. Additionally, it provides a powerful way to define and manage strong parameters in your controllers, which doubles as both MCP server configuration and Rails strong parameter enforcement.
This was inspired during the creation of Gaggle.
Features
- Tagged Routes: Tag Rails routes with
mcp: trueor specific actions (e.g.,mcp: [:index, :create]) to expose them to an MCP server. - Automatic MCP Server Generation: Generates a Ruby MCP server in
tmp/mcp/server.rbfor LLM agents to interact with your application. - Parameter Definition: Define permitted parameters in controllers with rich metadata (e.g., types, examples, required flags) that are used for both MCP server generation and Rails strong parameters.
- HTTP Bridge for LLM Agents: Generates a ruby based MCP server to interact with your application through HTTP requests, ensuring LLM agents follow the same paths as human users.
- Environment Variable Integration: Automatically includes specified environment variables in MCP tool calls.
Installation
Add this line to your application’s Gemfile:
gem 'mcp-rails'
Then run:
bundle install
Ensure you also have the mcp-rb gem installed, as mcp-rails depends on it:
gem 'mcp-rb'
Configuration
MCP-Rails can be configured in an initializer file. Create config/initializers/mcp_rails.rb:
MCP::Rails.configure do |config|
# Server Configuration
config.server_name = "my-app-server" # Default: 'mcp-server'
config.server_version = "2.0.0" # Default: '1.0.0'
# Output Configuration
config.output_directory = Rails.root.join("tmp/mcp") # Default: Rails.root.join('tmp', 'mcp')
config.bypass_key_path = Rails.root.join("tmp/mcp/bypass_key.txt") # Default: Rails.root.join('tmp', 'mcp', 'bypass_key.txt')
# Environment Variables
config.env_vars = ["API_KEY", "ORGANIZATION_ID"] # Default: ['API_KEY', 'ORGANIZATION_ID']
# Base URL Configuration
config.base_url = "http://localhost:3000" # Default: Uses action_mailer.default_url_options
end
If you are an engine developer, you can register your engine’s configuration with MCP-Rails:
MCP::Rails.configure do |config|
config.register_engine(YourEngine, env_vars: ["YOUR_ENGINE_KEY"])
end
Environment Variables
Установка
This server does not publish a one-line install command.
Open the repository installation guide Новичок в MCP? Начните с руководства на mcpskill.org →