人生就是不斷學習,調整與更新持續前進。

Rails mcp-server應用 v1

MCP (Model Context Protocol) 是 Anthropic 推出的開放標準協議,讓 AI 助手能夠安全地連接各種資料源和工具。它就像是 AI 與外部系統之間的統一接口。

 

Rails MCP 是專門為 Ruby on Rails 開發設計的 MCP 服務器,它能讓 AI 助手(如 Claude)理解和操作 Rails 專案的各種元素。

主要功能

1. 專案結構理解

2. 程式碼導航

3. 資料庫操作

4. 測試支援

 

# 透過 npm 安裝
npm install -g @modelcontextprotocol/server-rails

{
  "mcpServers": {
    "rails": {
      "command": "mcp-server-rails",
      "args": ["--project-path", "/path/to/your/rails/project"],
      "env": {}
    }
  }
}
```

### 步驟 3: 重啟 Cursor

配置完成後重啟 Cursor,讓設定生效。

## 實際使用場景

**場景 1: 新功能開發**
```
你: "我想在 User 模型中添加一個 full_name 方法"
AI: 會先檢查 User 模型現有結構,然後建議實作方式
```

**場景 2: Bug 修復**
```
你: "users#show 頁面出現 N+1 查詢問題"
AI: 會分析控制器、路由和視圖,找出問題並提供優化建議
```

**場景 3: 重構**
```
你: "幫我重構 OrdersController,使其更符合 RESTful 設計"
AI: 會理解現有結構,提供重構方案

 

還有其他安裝方式。

 

參考文件:

https://mariochavez.io/desarrollo/rails/ai-tools/development-workflow/2025/06/03/rails-mcp-server-enhanced-documentation-access/

https://www.bnext.com.tw/article/82706/what-is-mcp