const API = require("../../../lib/API.js") const MCP = require("../../../lib/Lepao/WorkOrderMcp.js").WORKORDERMCP class McpRpc extends API { constructor() { super() this.noEncrypt() this.setPath('/workorderMcp') this.setMethod('POST') } async onRequest(req, res) { const { method, params = {}, id: req_id } = req.body try { let result if (method === 'initialize') { result = { protocolVersion: "2024-11-05", capabilities: { "tools": {} }, serverInfo: { name: "runforgeWorkOrder", version: "1.0" } } } else if (method === 'tools/list') { result = { "tools": [ { "name": "need_manual", "description": "提交转人工服务请求", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string", "description": "Unique user identifier from the chat platform" }, "order_id": { "type": "integer", "description": "Order ID of the work order to submit" } }, "required": ["sender", "order_id"] } }, { "name": "unbind_account", "description": "解绑被他人绑定的乐跑账号", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string", "description": "Unique user identifier from the chat platform" }, "student_num": { "type": "integer", "description": "Student number of the account to unbind" } }, "required": ["sender", "student_num"] } }, { "name": "get_account_info", "description": "按学号获取乐跑账号信息", "inputSchema": { "type": "object", "properties": { "sender": { "type": "string", "description": "Unique user identifier from the chat platform" }, "student_num": { "type": "integer", "description": "Student number of the account to get info" } }, "required": ["sender", "student_num"] } } ] } } else if (method === 'tools/call') { const { name, arguments: args = {} } = params let output switch (name) { case "need_manual": output = await MCP.need_manual(args) break case "get_account_info": output = await MCP.get_account_info(args) break case "unbind_account": output = await MCP.unbind_account(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 ?? null, result }) } catch (e) { return res.json({ jsonrpc: "2.0", id: req_id ?? null, error: { code: -32000, message: e.message } }) } } } module.exports.McpRpc = McpRpc