使用说明
Rails引导MCP服务器
A. 模型上下文协议(MCP)服务器 它提供了对RubyonRails文档和指南的访问。该服务器允许像Claude这样的AI助手以编程方式访问、搜索和引用Rails Guides内容,从而更容易获得Rails开发帮助和文档。
🚀 特性
- 完成Rails指南访问 -所有官方Rails文档类别
- 版本支持 -支持多个Rails版本(8.0、7.1、4.2等)
- 分类组织 -按主题(模型、视图、控制器等)组织的指南
- 动态版本切换 -不同Rails版本的环境变量支持
- TypeScript实现 使用Zod模式验证
- 开发工具 包括热装和检验员
- 准备集成Claude 使用简单的设置命令
📋 先决条件
- Node.js 18或更高版本
- npm、yarn或pnpm
- Claude桌面应用程序(用于集成)
🤝 预期使用案例
此MCP服务器非常适合:
- Rails开发人员 寻求快速获取官方文件
- 人工智能辅助Rails开发 使用Claude或其他MCP兼容工具
- 学习Rails 具有上下文文档访问权限
- 代码审查和调试 即时访问Rails约定
- 团队 希望跨项目实现一致的Rails文档访问
🚀 与克劳德快速开始
选项1:添加到Claude项目(推荐)
# Navigate to your Rails project directory
cd your-rails-project
# Add the Rails Guides MCP server to your project
claude mcp add rails-guides npx rails-mcp-server
# For specific Rails version
claude mcp add rails-guides npx rails-mcp-server -e RAILS_VERSION=7.1
选项2:全局添加
# Add globally for all Claude sessions
claude mcp add rails-guides npx rails-mcp-server --scope user
# With specific Rails version
claude mcp add rails-guides npx rails-mcp-server --scope user -e RAILS_VERSION=7.1
选项3:本地添加
# Add for local Claude sessions only
claude mcp add rails-guides npx rails-mcp-server --scope local
🔧 Rails版本支持
服务器默认为 轨道8.0 文档,但支持多个版本:
支持的版本
- 轨道8.0 (默认)-
https://guides.rubyonrails.org - 钢轨7.1 -
https://guides.rubyonrails.org/v7.1 - 轨道4.2 -
https://guides.rubyonrails.org/v4.2 - 其他版本 -遵循模式
v{major}.{minor}
设置Rails版本
使用 RAILS_VERSION 环境变量:
# Default (Rails 8.0)
claude mcp add rails-guides npx rails-mcp-server
# Rails 7.1
claude mcp add rails-guides npx rails-mcp-server -e RAILS_VERSION=7.1
# Rails 4.2
claude mcp add rails-guides npx rails-mcp-server -e RAILS_VERSION=4.2
# Rails 6.0
claude mcp add rails-guides npx rails-mcp-server -e RAILS_VERSION=6.0
替代环境变量
您还可以使用 RAILS_GUIDES_VERSION:
claude mcp add rails-guides npx rails-mcp-server -e RAILS_GUIDES_VERSION=7.1
🛠️ 手动安装(开发)
如果您想修改或贡献此服务器:
- 克隆存储库:
git clone https://github.com/your-username/rails-mcp-server.git
cd rails-mcp-server
- 安装依赖项:
npm install
- 构建项目:
npm run build
- 本地测试:
node dist/server.js
🏃♂️ 发展
启动开发服务器
npm run dev
为生产而建
npm run build
检查MCP服务器
npm run inspect
这将打开MCP检查器,以交互方式测试您的服务器工具。
📚 可用工具
Rails Guides MCP服务器提供以下工具:
核心工具
getRailsGuides-返回包含类别和元数据的所有Rails指南的完整列表getGuideRegistry-完整的注册表,包括所有指南、类别和版本信息getGuideContent-获取特定Rails指南的完整HTML内容
特定类别的工具
为每个Rails Guide类别创建动态工具:
getStartHereGuides-入门指南、安装指南getModelsGuides-活动记录、迁移、验证、关联等。getViewsGuides-动作视图、布局、辅助对象、表单辅助对象getControllersGuides-动作控制器,路由,高级主题getOtherComponentsGuides-主动支持、行动邮件、主动作业等。getDiggingDeeperGuides-I18n,测试、调试、配置等。getGoingToProductionGuides-缓存、安全性、性能getAdvancedActiveRecordGuides-PostgreSQL、多数据库、加密getExtendingRailsGuides-插件、机架、生成器、引擎getContributingGuides-贡献,API文档,开发设置
示例用法
添加到Claude后,您可以提出以下问题:
- “向我展示Rails模型指南”
- “获取入门指南内容”
- “有哪些Rails指南可供测试?”
- “获取活动记录关联指南”
🏗️ 项目结构
rails-mcp-server/
├── src/
│ ├── server.ts # Main Rails Guides MCP server
│ ├── lib/
│ │ ├── config.ts # Configuration with version support
│ │ └── categories.ts # Rails Guides categories
│ └── utils/
│ ├── api.ts # Rails Guides fetching utilities
│ ├── formatters.ts # Data formatting helpers
│ ├── schemas.ts # Zod validation schemas
│ └── index.ts # Utility exports
├── dist/ # Built files
├── package.json
└── README.md
🔧 定制
添加新的Rails指南类别
要添加新的指南类别,请更新 src/lib/categories.ts:
export const guideCategories = {
// Existing categories...
"Custom Category": [
"custom_guide_1",
"custom_guide_2",
],
};
服务器将自动创建特定类别的工具。
支持不同的Rails版本
服务器通过URL模式自动处理不同的Rails版本:
- 轨道8.0+:
https://guides.rubyonrails.org/{guide}.html - 旧版本:
https://guides.rubyonrails.org/v{version}/{guide}.html
自定义指南处理
修改 src/utils/api.ts 要自定义指南的处理方式:
export async function fetchGuideDetails(guideName: string) {
// Add custom processing logic
// Parse HTML sections, extract code examples, etc.
}
🚀 部署
以NPM包形式发布
通过以下方式使此服务器可用 npx,发布到npm:
- 更新
package.json您的详细信息:
{
"name": "rails-mcp-server",
"version": "1.0.0",
"description": "MCP server for Rails Guides documentation",
"bin": {
"rails-mcp-server": "./dist/server.js"
}
}
- 构建和发布:
npm run build
npm publish
- 然后用户可以添加它:
claude mcp add rails-guides npx rails-mcp-server
手动安装
对于开发或自定义部署:
# Clone and build
git clone https://github.com/your-username/rails-mcp-server.git
cd rails-mcp-server
npm install && npm run build
# Add to Claude with local path
claude mcp add rails-guides node /path/to/rails-mcp-server/dist/server.js
🤝 贡献
欢迎投稿!以下是您可以提供帮助的方式:
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改 并在适用的情况下添加测试
- 提交您的更改:
git commit -m 'feat: add amazing feature' - 推到分支:
git push origin feature/amazing-feature - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 内置于 模型上下文协议SDK
- Rails指南内容来自 Ruby on Rails
- 受更好的AI辅助Rails开发需求的启发
- 感谢MCP和Rails社区
📞 支持
✨ 在人工智能的帮助下快乐开发Rails!
