| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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": "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 "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
|