{"record":{"id":"96278e146418542c","repo":"xpipe-io/xpipe","slug":"directory-path-does-already-exist","errorCode":null,"errorMessage":"Directory ${path} does already exist","messagePattern":"Directory (.+?) does already exist","errorType":"exception","errorClass":"BeaconClientException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/io/xpipe/app/beacon/mcp/McpTools.java","lineNumber":403,"sourceCode":"                            .addTextContent(\"File written successfully\")\n                            .build();\n                }))\n                .build();\n    }\n\n    public static McpServerFeatures.SyncToolSpecification createDirectory() throws IOException {\n        var tool = McpSchemaFiles.loadTool(\"create_directory.json\");\n        return McpServerFeatures.SyncToolSpecification.builder()\n                .tool(tool)\n                .callHandler(McpToolHandler.of((req) -> {\n                    var system = req.getStringArgument(\"system\");\n                    var shellStore = req.getShellStoreRef(system, true);\n                    var shellSession = AppBeaconServer.get().getCache().getOrStart(shellStore);\n                    var path = req.getFilePath(shellSession.getControl(), \"path\");\n                    var fs = new ShellFileSystem(shellSession.getControl());\n\n                    if (fs.fileExists(path)) {\n                        throw new BeaconClientException(\"Directory \" + path + \" does already exist\");\n                    }\n\n                    fs.mkdirs(path);\n\n                    return McpSchema.CallToolResult.builder()\n                            .addTextContent(\"Directory created successfully\")\n                            .build();\n                }))\n                .build();\n    }\n\n    public static McpServerFeatures.SyncToolSpecification runCommand() throws IOException {\n        var tool = McpSchemaFiles.loadTool(\"run_command.json\");\n        return McpServerFeatures.SyncToolSpecification.builder()\n                .tool(tool)\n                .callHandler(McpToolHandler.of((req) -> {\n                    var command = req.getStringArgument(\"command\");\n                    var system = req.getStringArgument(\"system\");","sourceCodeStart":385,"sourceCodeEnd":421,"githubUrl":"https://github.com/xpipe-io/xpipe/blob/d85ca821baa46092a320ebb13546d7240adb74f8/app/src/main/java/io/xpipe/app/beacon/mcp/McpTools.java#L385-L421","documentation":"Thrown by the createDirectory MCP tool when the given path already exists (the code checks fs.fileExists(path) then aborts). mkdirs() is only executed on a non-existing path. Note the pre-check does not treat an existing directory as acceptable — any existing entry blocks creation.","triggerScenarios":"Calling createDirectory with a 'path' that already exists as a file or directory on the target system.","commonSituations":"Idempotency mistakes in automation re-running setup scripts, or assuming the tool behaves like mkdir -p (it does not — it fails if the target exists).","solutions":["Skip the call when the directory already exists (check first)","Use a different directory name","Remove the existing entry first if replacement is intended","Do not use createDirectory as mkdir -p; guard the call in automation"],"exampleFix":"// before\ncreateDirectory(system: \"host\", path: \"/opt/app\") // exists\n// after\nif (!directoryExists(system: \"host\", path: \"/opt/app\")) {\n  createDirectory(system: \"host\", path: \"/opt/app\")\n}","handlingStrategy":"validation","validationCode":"async function ensureDirectory(mcp, system, path) {\n  const exists = await mcp.call('directoryExists', {system, path}); // or shell test -d\n  if (exists) return;\n  return mcp.call('createDirectory', {system, path});\n}","typeGuard":null,"tryCatchPattern":"try {\n  await mcp.call('createDirectory', {system, path});\n} catch (e) {\n  if (String(e.message).includes('does already exist')) return; // idempotent success\n  throw e;\n}","preventionTips":["Remember createDirectory is not mkdir -p","Guard setup scripts with existence checks","Use unique paths per run in automation"],"tags":["mcp","filesystem","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"d85ca821baa46092a320ebb13546d7240adb74f8","analyzedAt":"2026-09-06T14:30:08.251Z","contentChangedAt":"2026-09-06T14:30:08.251Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}