{"record":{"id":"c48d4f75e33641e3","repo":"CherryHQ/cherry-studio","slug":"errorcode-methodnotfound","errorCode":"ErrorCode.MethodNotFound","errorMessage":"Unknown tool: ${toolName}","messagePattern":"Unknown tool: (.+?)","errorType":"exception","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"src/main/ai/mcp/servers/agentMemory.ts","lineNumber":150,"sourceCode":"          tools: {}\n        }\n      }\n    )\n    this.setupHandlers()\n  }\n\n  private setupHandlers() {\n    this.mcpServer.server.setRequestHandler(ListToolsRequestSchema, async () => ({\n      tools: [MEMORY_TOOL]\n    }))\n\n    this.mcpServer.server.setRequestHandler(CallToolRequestSchema, async (request) => {\n      const toolName = request.params.name\n      const args = (request.params.arguments ?? {}) as Record<string, string | undefined>\n\n      try {\n        if (toolName !== 'memory') {\n          throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${toolName}`)\n        }\n        const action = args.action\n        switch (action) {\n          case 'update':\n            return await this.memoryUpdate(args)\n          case 'append':\n            return await this.memoryAppend(args)\n          case 'search':\n            return await this.memorySearch(args)\n          default:\n            throw new McpError(ErrorCode.InvalidParams, `Unknown action \"${action}\", expected update/append/search`)\n        }\n      } catch (error) {\n        const message = error instanceof Error ? error.message : String(error)\n        logger.error(`Tool error: ${toolName}`, { agentId: this.agentId, error: message })\n        return {\n          content: [{ type: 'text' as const, text: `Error: ${message}` }],\n          isError: true","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/CherryHQ/cherry-studio/blob/726446b54cd69ffe51a276638672f6d95ca0768c/src/main/ai/mcp/servers/agentMemory.ts#L132-L168","documentation":"The AgentMemoryServer registers exactly one tool named 'memory' via ListToolsRequestSchema. The CallToolRequest handler throws McpError with ErrorCode.MethodNotFound for any request whose params.name is not 'memory'. This is the MCP protocol-correct way to reject unknown tools.","triggerScenarios":"An MCP client sends a CallToolRequest with a tool name other than 'memory' to this server (e.g. a stale client that cached an older tool list, or a misrouted request intended for a different server).","commonSituations":"Client and server version mismatch where the client believes different tools exist; a generic MCP client enumerating tools by brute force; a bug in the MCP router dispatching the call to the wrong server instance.","solutions":["Call ListTools first and only invoke tool names that are advertised.","Verify you are connected to the 'agent-memory' server and not another MCP server.","Update the client to match the server's tool surface."],"exampleFix":"// before\nawait server.callTool({ name: 'recall', arguments: {...} })\n\n// after\nconst { tools } = await server.listTools()\nconst name = tools[0].name // 'memory'\nawait server.callTool({ name, arguments: { action: 'search', query: '...' } })","handlingStrategy":"validation","validationCode":"// Client-side: only call tools the server advertises.\nconst { tools } = await client.listTools()\nconst allowed = new Set(tools.map((t) => t.name))\nif (!allowed.has(toolName)) throw new Error(`Tool '${toolName}' not offered by agent-memory server`)\nawait client.callTool({ name: toolName, arguments })","typeGuard":"function isMemoryToolName(name: string): boolean {\n  return name === 'memory'\n}","tryCatchPattern":null,"preventionTips":["Always call ListTools before CallTool to discover the live tool surface.","Pin client and server versions so the tool set matches.","Route tool calls to the correct MCP server, not the first available."],"tags":["mcp","protocol-error","method-not-found"],"backgroundTag":null,"analyzedSha":"726446b54cd69ffe51a276638672f6d95ca0768c","analyzedAt":"2026-08-12T17:30:37.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}