const API = require("../../lib/API") const MCP = require("../../lib/Lepao/Mcp.js").MCP class McpRpc extends API { constructor() { super() this.noEncrypt() this.setPath('/mcp') this.setMethod('POST') } async onRequest(req, res) { const { method, params = {}, id: req_id } = req.body try { let result if (method === 'initialize') { result = { protocolVersion: "2026-03-25", capabilities: { "tools": {} }, serverInfo: { name: "runforge-mcp", version: "1.0" } } } else if (method === 'tools/list') { result = { "tools": [ { "name": "bind_account", "description": "绑定账号", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string" }, "bind_code": { "type": "string" } }, "required": ["sender", "bind_code"] } }, { "name": "get_account_info", "description": "获取账号信息", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string" } }, "required": ["sender"] } }, { "name": "unbind_account", "description": "解绑账号", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string" } }, "required": ["sender"] } }, { "name": "set_notification", "description": "消息通知设置,参数:bot:智能机器人通知,email:邮件通知,none:关闭通知", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string" }, "type": { "type": "string" } }, "required": ["sender", "type"] } } ] } } else if (method === 'tools/call') { const { name, arguments: args = {} } = params let output switch (name) { case "bind_account": output = await MCP.bind_account(args) break case "get_account_info": output = await MCP.get_account_info(args) break case "unbind_account": output = await MCP.unbind_account(args) break case "set_notification": output = await MCP.set_notification(args) break default: output = "未知工具" } result = { content: [{ type: "text", text: output }] } } else { result = { error: `未知方法: ${method}` } } // 返回标准 JSON-RPC 响应 return res.json({ jsonrpc: "2.0", id: req_id, result }) } catch (e) { return res.json({ jsonrpc: "2.0", id: req_id, error: { code: -32000, message: e.message } }) } } } module.exports.McpRpc = McpRpc