* 路由 MCP 方法。 * 当前仅实现 initialize、ping、tools/list、tools/call 等基础能力。
(request: JsonRpcRequest)
| 325 | * 当前仅实现 initialize、ping、tools/list、tools/call 等基础能力。 |
| 326 | */ |
| 327 | private async routeMcpRequest(request: JsonRpcRequest): Promise<unknown> { |
| 328 | switch (request.method) { |
| 329 | case 'initialize': |
| 330 | return { |
| 331 | protocolVersion: MCP_PROTOCOL_VERSION, |
| 332 | capabilities: { |
| 333 | tools: {} |
| 334 | }, |
| 335 | serverInfo: { |
| 336 | name: 'ztools-mcp', |
| 337 | version: app.getVersion() |
| 338 | } |
| 339 | } |
| 340 | case 'notifications/initialized': |
| 341 | return {} |
| 342 | case 'ping': |
| 343 | return {} |
| 344 | case 'tools/list': |
| 345 | return { |
| 346 | tools: pluginToolsAPI |
| 347 | .getAllDeclaredToolEntries({ includeDisabled: false }) |
| 348 | .map((tool) => ({ |
| 349 | name: tool.mcpName, |
| 350 | title: `${tool.pluginName} / ${tool.toolName}`, |
| 351 | description: tool.description, |
| 352 | inputSchema: tool.inputSchema |
| 353 | })) |
| 354 | } |
| 355 | case 'tools/call': |
| 356 | return await this.handleToolCall(request.params) |
| 357 | default: |
| 358 | throw new McpProtocolError(-32601, `Method not found: ${request.method}`) |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | /** |
| 363 | * 执行 tools/call: |
no test coverage detected