
nagstler/mcp_on_ruby 是一个从 https://github.com/nagstler/mcp_on_ruby. 导入的 MCP 服务器候选
概览
nagstler/mcp_on_ruby 是一个从 https://github.com/nagstler/mcp_on_ruby. 导入的 MCP 服务器候选
概述(AI 翻译)
用于Rails应用的模型上下文协议(MCP)服务器
将你的Rails应用展示为AI无障碍界面——按照Rails的方式定义工具和资源。
特色
🚀 生产准备 - 认证、速率限制、错误处理、安全性 🔧 轨道集成 - 发电机、自动加载、中间件、轨道连接 🛠️ 工具系统 - 可调用函数,支持 JSON 模式验证 📊 资源系统 - 使用URI模板处理的数据暴露 🔒 安全性 - DNS重绑定保护、CORS、令牌认证 ⚡ 实时 - 服务器事件(SSE)基础(完整实现即将上线) 🎯 开发者友好 - 干净的DSL、生成器、测试支持。
安装
在你的Gemfile中添加:
然后运行:
快速启动
1.安装与配置
2.配置MCP服务器
3.创建工具
4.创建资源
5.启动你的服务器
建筑
示例
将你的Rails MCP服务器与不同的AI客户端连接起来:
👉 Claude Desktop - 完整设置指南含桥接脚本
👉 MCP注册和控制平面 - 注册Rails MCP端点
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
class OrdersController < ApplicationController
before_action :authenticate_user!
mcp_tool :index, description: "Search the current user's orders",
params: { status: { type: :string, enum: %w[pending paid shipped] } }
mcp_tool :show, description: "Fetch one order by id"
def index
render json: current_user.orders.where(params.permit(:status))
end
def show
render json: current_user.orders.find(params[:id])
end
end
That’s the whole integration. Claude, Cursor, or any MCP client can now search and read orders as the signed-in user. Your before_action authenticates the agent, your scopes and policies decide what it can see, and your existing JSON comes back to it. You don’t write new tool classes or a second permission system.
Why MCP on Ruby
Most MCP libraries ask you to build a parallel API for agents: new tool classes, new argument parsing, new authorization checks. Over time that second API drifts from the real one, and every rule has to be secured twice.
MCP on Ruby takes the opposite approach. Your app already has an API: your controllers. MCP on Ruby makes it callable by agents.
- One source of truth. Agents go through the same routes, filters, policies, validations, and serializers as your users.
- Real identity. Every tool call runs as a real user, using the auth you already have: API tokens, Devise, or Warden.
- Safe by default. Actions that change data must be marked
write: true, and every tool tells the client whether it is read-only or destructive. - Local and remote. Serve Streamable HTTP in production, and stdio for Claude Code, Claude Desktop, and Cursor on your machine.
安装
npx @modelcontextprotocol/inspector bin/rails mcp:stdio配置
{
"mcpServers": {
"my-app": {
"command": "/Users/you/.rbenv/versions/3.4.7/bin/ruby",
"args": ["-C", "/path/to/my-app", "bin/rails", "mcp:stdio"],
"env": { "MCP_USER": "[email protected]" }
}
}
}