{"record":{"id":"14859884356ed21b","repo":"alibaba/arthas","slug":"tool-with-name-not-found","errorCode":null,"errorMessage":"Tool with name '{}' not found","messagePattern":"Tool with name '(.+?)' not found","errorType":"validation","errorClass":"McpError","httpStatus":null,"severity":"error","filePath":"arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/McpStatelessNettyServer.java","lineNumber":230,"sourceCode":"\n\tpublic CompletableFuture<Void> removeTool(String toolName) {\n\t\tif (toolName == null) {\n\t\t\tCompletableFuture<Void> future = new CompletableFuture<>();\n\t\t\tfuture.completeExceptionally(new McpError(\"Tool name must not be null\"));\n\t\t\treturn future;\n\t\t}\n\t\tif (this.serverCapabilities.getTools() == null) {\n\t\t\tCompletableFuture<Void> future = new CompletableFuture<>();\n\t\t\tfuture.completeExceptionally(new McpError(\"Server must be configured with tool capabilities\"));\n\t\t\treturn future;\n\t\t}\n\n\t\treturn CompletableFuture\n\t\t\t\t.runAsync(() -> {\n\t\t\t\t\tboolean removed = this.tools.removeIf(\n\t\t\t\t\t\t\tspec -> spec.getTool().getName().equals(toolName));\n\t\t\t\t\tif (!removed) {\n\t\t\t\t\t\tthrow new CompletionException(\n\t\t\t\t\t\t\t\tnew McpError(\"Tool with name '\" + toolName + \"' not found\"));\n\t\t\t\t\t}\n\t\t\t\t\tlogger.debug(\"Removed tool handler: {}\", toolName);\n\t\t\t\t})\n\t\t\t\t.exceptionally(ex -> {\n\t\t\t\t\tThrowable cause = (ex instanceof CompletionException) ? ex.getCause() : ex;\n\t\t\t\t\tlogger.error(\"Error while removing tool '{}'\", toolName, cause);\n\t\t\t\t\tthrow new CompletionException(cause);\n\t\t\t\t});\n\t}\n\n\tprivate McpStatelessRequestHandler<McpSchema.ListToolsResult> toolsListRequestHandler() {\n\t\treturn (exchange, commandContext, params) -> {\n\t\t\tList<McpSchema.Tool> tools = new ArrayList<>();\n\t\t\tfor (McpStatelessServerFeatures.ToolSpecification toolSpec : this.tools) {\n\t\t\t\ttools.add(toolSpec.getTool());\n\t\t\t}\n","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/McpStatelessNettyServer.java#L212-L248","documentation":"Thrown by McpStatelessNettyServer.removeTool() when dynamically removing a tool name not present in the stateless server's tools list. The async removal uses removeIf; if no element matched, the future fails with this McpError wrapped in CompletionException.","triggerScenarios":"Calling removeTool(toolName) for a name never added, already removed, or mistyped on a stateless server instance.","commonSituations":"Double teardown; cleanup of a tool that failed to register; operating on the wrong stateless server instance; name mismatch between add and remove.","solutions":["Track added tool names locally and only remove those present.","Make teardown idempotent by swallowing the 'not found' error via exceptionally.","Reuse the exact name string from registration.","Verify you target the same McpStatelessNettyServer that owns the tool."],"exampleFix":"// before\nstatelessServer.removeTool(name).join(); // throws if absent\n\n// after\nstatelessServer.removeTool(name)\n    .exceptionally(ex -> null)\n    .join(); // idempotent cleanup","handlingStrategy":"validation","validationCode":"Set<String> addedTools = ConcurrentHashMap.newKeySet();\n// on add: addedTools.add(name);\nif (addedTools.remove(toolName)) {\n    statelessServer.removeTool(toolName).join();\n}","typeGuard":null,"tryCatchPattern":"statelessServer.removeTool(toolName)\n    .exceptionally(ex -> {\n        Throwable c = ex instanceof CompletionException ? ex.getCause() : ex;\n        if (c instanceof McpError me && me.getMessage().contains(\"not found\")) return null;\n        throw new CompletionException(c);\n    })\n    .join();","preventionTips":["Track added tool names locally.","Make teardown idempotent.","Reuse the exact registered name."],"tags":["mcp","tool","dynamic-registration","stateless-server","java"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}