{"record":{"id":"9b3a5a4b86778e24","repo":"alibaba/arthas","slug":"resource-with-uri-not-found","errorCode":null,"errorMessage":"Resource with URI '{}' not found","messagePattern":"Resource with URI '(.+?)' 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":320,"sourceCode":"\t}\n\n\tpublic CompletableFuture<Void> removeResource(String resourceUri) {\n\t\tif (resourceUri == null) {\n\t\t\tCompletableFuture<Void> future = new CompletableFuture<>();\n\t\t\tfuture.completeExceptionally(new McpError(\"Resource URI must not be null\"));\n\t\t\treturn future;\n\t\t}\n\t\tif (this.serverCapabilities.getResources() == null) {\n\t\t\tCompletableFuture<Void> future = new CompletableFuture<>();\n\t\t\tfuture.completeExceptionally(new McpError(\"Server must be configured with resource 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\tMcpStatelessServerFeatures.ResourceSpecification removed = this.resources.remove(resourceUri);\n\t\t\t\t\tif (removed == null) {\n\t\t\t\t\t\tthrow new CompletionException(new McpError(\"Resource with URI '\" + resourceUri + \"' not found\"));\n\t\t\t\t\t}\n\t\t\t\t\tlogger.debug(\"Removed resource handler: {}\", resourceUri);\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 resource '{}'\", resourceUri, cause);\n\t\t\t\t\tthrow new CompletionException(cause);\n\t\t\t\t});\n\t}\n\n\tprivate McpStatelessRequestHandler<McpSchema.ListResourcesResult> resourcesListRequestHandler() {\n\t\treturn (exchange, commandContext,  params) -> {\n\t\t\tList<McpSchema.Resource> resourceList = new ArrayList<>();\n\t\t\tfor (McpStatelessServerFeatures.ResourceSpecification spec : this.resources.values()) {\n\t\t\t\tresourceList.add(spec.getResource());\n\t\t\t}\n\t\t\treturn CompletableFuture.completedFuture(new McpSchema.ListResourcesResult(resourceList, null));\n\t\t};","sourceCodeStart":302,"sourceCodeEnd":338,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/arthas-mcp-server/src/main/java/com/taobao/arthas/mcp/server/protocol/server/McpStatelessNettyServer.java#L302-L338","documentation":"Thrown by McpStatelessNettyServer.removeResource() when dynamically unregistering a resource URI not present in the stateless server's resources map. The async removal returns null from map.remove and fails the returned CompletableFuture with this McpError wrapped in CompletionException.","triggerScenarios":"Calling removeResource(uri) for a URI never added, already removed, or not byte-identical to the registered key on a stateless server.","commonSituations":"Idempotent teardown that runs twice; cleanup of a resource that was never registered; URI normalization differences; operating on the wrong server instance.","solutions":["Maintain your own registry of added URIs and only remove those present.","Make removal idempotent with exceptionally(ex -> null).","Reuse the exact URI from registration without normalization.","Confirm the same McpStatelessNettyServer instance owns the resource."],"exampleFix":"// before\nstatelessServer.removeResource(uri).join(); // throws if absent\n\n// after\nstatelessServer.removeResource(uri)\n    .exceptionally(ex -> null)\n    .join(); // idempotent","handlingStrategy":"validation","validationCode":"Set<String> addedUris = ConcurrentHashMap.newKeySet();\n// on add: addedUris.add(uri);\nif (addedUris.remove(resourceUri)) {\n    statelessServer.removeResource(resourceUri).join();\n}","typeGuard":null,"tryCatchPattern":"statelessServer.removeResource(resourceUri)\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 URIs locally.","Make removal idempotent with exceptionally.","Reuse the exact registered URI."],"tags":["mcp","resource","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"}