🚀 模式 MCP 服務器
這是一個用於管理 Roo 的自定義操作模式的 MCP 服務器,可對模式配置和管理進行編程控制,為用戶提供便捷的模式管理體驗。
🚀 快速開始
本服務器提供了對自定義模式的完整管理功能。你可以通過一系列步驟完成安裝、配置,並使用其提供的工具對模式進行操作。
✨ 主要特性
- 支持對自定義模式進行完整的增刪改查操作。
- 運用 Zod 進行模式驗證,確保數據的準確性。
- 可監控文件系統的變更,及時響應配置文件的修改。
- 處理標準 MCP 錯誤碼,便於問題排查。
- 採用原子文件操作,保證數據的一致性。
📦 安裝指南
git clone https://github.com/mkc909/modes-mcp-server.git
cd modes-mcp-server
npm install
npm run build
📚 詳細文檔
配置步驟
1. 環境變量配置
複製 .env.example
到 .env
並根據需要調整:
cp .env.example .env
可用的環境變量:
MODES_CONFIG_PATH
:自定義模式配置文件路徑(默認:%APPDATA%/Code/User/globalStorage/rooveterinaryinc.roo-cline/settings/cline_custom_modes.json
)
2. 自定義模式配置
創建自定義模式的 JSON 配置文件。參考 examples/modes.example.json
的格式:
{
"customModes": [
{
"slug": "example-mode",
"name": "Example Mode",
"roleDefinition": "Example role definition describing the mode's capabilities and responsibilities.",
"groups": [
"read",
["edit", {
"fileRegex": "\\.md$",
"description": "Can edit markdown files only"
}],
"write"
],
"customInstructions": "These are additional instructions for using this mode."
}
]
}
3. MCP 工具配置
在 config/mcp-tools.json
中添加以下內容:
{
"modeManager": {
"class": "FileModeManager",
"args": {
"configPath": "%MODES_CONFIG_PATH%",
"schema": {
"type": "object",
"required": ["slug", "name", "roleDefinition"],
"properties": {
"slug": {"type": "string"},
"name": {"type": "string"},
"roleDefinition": {"type": "string"},
"groups": {
"type": "array",
"items": [
{"type": "string"},
{
"type": "array",
"minLength": 2,
"items": [
{"type": "string"},
{
"type": "object",
"required": ["fileRegex", "description"],
"properties": {
"fileRegex": {"type": "string"},
"description": {"type": "string"}
}
}
]
}
]
},
"customInstructions": {"type": "string", "nullable": true}
}
}
}
}
}
操作模式框架
標準模式
- 默認模式:
default-mode
- 顯示名稱:Default Mode
- 角色定義:提供通用的文件操作功能,適用於多種任務。
- 工具組:基本文件操作 (
read
, edit
, write
)
自定義模式
開發人員可以創建自定義模式以滿足特定需求。例如:
{
"slug": "my-custom-mode",
"name": "My Custom Mode",
"roleDefinition": "A custom mode for specialized tasks.",
"groups": [
["custom-task", {
"fileRegex": "\\.custom$",
"description": "Handles files with .custom extension"
}]
],
"customInstructions": "Use this mode only for specific operations."
}
可用工具
基礎用法
以下是一些常用的模式操作命令:
創建模式
POST /modes
Content-Type: application/json
{
"mode": {
"slug": "new-mode",
"name": "New Mode",
"roleDefinition": "Description of new mode.",
"groups": ["read", "write"]
}
}
獲取所有模式
GET /modes
更新模式
PUT /modes/<slug>
Content-Type: application/json
{
"mode": {
"name": "Updated Mode",
"roleDefinition": "Updated description.",
"groups": ["read", "write"]
}
}
刪除模式
DELETE /modes/<slug>
開發指南
- 修改源代碼位於
src/
目錄下。
- 構建項目:
npm run build
- 啟動服務器:
npm start
最佳實踐
模式選擇
- 根據任務選擇合適的模式。
- 遵循特定模式的工作流程。
- 使用指定的工具組。
模式轉換
- 按照自然轉換流程操作。
- 完成當前模式的任務。
- 在模式之間保留上下文。
配置管理
- 驗證變更後再保存。
- 保持清晰的角色定義。
- 文檔化模式能力。
錯誤處理
服務器使用標準 MCP 錯誤碼:
InvalidParams
:輸入參數無效或未找到模式。
MethodNotFound
:請求的工具未知。
InternalError
:文件系統錯誤或其他內部問題。
測試指南
參考 TESTING.md 獲取全面的測試用例和驗證步驟。
貢獻指南
- 叉分倉庫。
- 創建功能分支。
- 提交拉取請求。
- 遵循編碼標準。
📄 許可證
本項目採用 MIT 許可證,詳細信息見 LICENSE。