{"record":{"id":"748b083f31d14c76","repo":"yamadashy/repomix","slug":"failed-to-create-temporary-directory-message","errorCode":null,"errorMessage":"Failed to create temporary directory: ${message}","messagePattern":"Failed to create temporary directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/mcp/tools/mcpToolRuntime.ts","lineNumber":152,"sourceCode":"  description?: string;\n  errorMessage?: string;\n}\n\n// Structured content for MCP tool responses with proper typing\ntype McpToolStructuredContent = (BaseMcpToolResponse & Record<string, unknown>) | undefined;\n\n/**\n * Creates a temporary directory for MCP tool operations\n */\nexport const createToolWorkspace = async (): Promise<string> => {\n  try {\n    const tmpBaseDir = path.join(getRepomixTmpDir(), 'mcp-outputs');\n    await fs.mkdir(tmpBaseDir, { recursive: true });\n    const tempDir = await fs.mkdtemp(`${tmpBaseDir}/`);\n    return tempDir;\n  } catch (error) {\n    const message = error instanceof Error ? error.message : String(error);\n    throw new Error(`Failed to create temporary directory: ${message}`);\n  }\n};\n\n/**\n * Generate a unique output ID\n */\nexport const generateOutputId = (): string => {\n  return crypto.randomBytes(8).toString('hex');\n};\n\n/**\n * Creates a result object with metrics information for MCP tools\n */\nexport const formatPackToolResponse = async (\n  context: McpToolContext,\n  metrics: McpToolMetrics,\n  outputFilePath: string,\n  topFilesLen = 5,","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/yamadashy/repomix/blob/f465ad909315a22120636baf03fa5e28701a50cb/src/mcp/tools/mcpToolRuntime.ts#L134-L170","documentation":"createToolWorkspace creates a per-invocation temp directory under the repomix tmp dir (getRepomixTmpDir()/mcp-outputs) using fs.mkdtemp. When any filesystem step fails (mkdir or mkdtemp), the error is rethrown with this message plus the OS-level cause text.","triggerScenarios":"The temp base directory cannot be created or written because of permission denial (read-only filesystem, root-owned dir), disk full (ENOSPC), TMPDIR pointing to a nonexistent/unwritable location, or sandboxed environments blocking /tmp writes.","commonSituations":"Containers run with read-only tmpfs or no TMPDIR; CI runners with restricted permissions; disk quota exhausted; corporate security software blocking temp directory creation.","solutions":["Check permissions on the repomix tmp dir location (often under os.tmpdir()); ensure write access","Set a writable TMPDIR environment variable to a location you can write to","Free disk space if the cause mentions ENOSPC","Inspect the appended OS message (e.g. EACCES, ENOSPC, EROFS) to target the root cause"],"exampleFix":"// before\n// TMPDIR=/nonexistent npx repomix-mcp  -> EACCES/ENOENT on mkdtemp\n// after\nexport TMPDIR=/tmp\nmkdir -p \"$TMPDIR/mcp-outputs\"\nnpx repomix-mcp","handlingStrategy":"try-catch","validationCode":"import fs from 'node:fs';\nimport os from 'node:os';\nconst base = process.env.TMPDIR || os.tmpdir();\nfs.accessSync(base, fs.constants.W_OK); // throws early if not writable","typeGuard":null,"tryCatchPattern":"try {\n  await createToolWorkspace();\n} catch (e) {\n  if (String(e.message).startsWith('Failed to create temporary directory')) {\n    process.env.TMPDIR = '/tmp'; // or another writable dir, then retry\n  } else throw e;\n}","preventionTips":["Ensure TMPDIR points to a writable location in containers/CI","Monitor disk space (ENOSPC)","Check the appended OS error code (EACCES/EROFS/ENOSPC) to diagnose"],"tags":["mcp","filesystem","temp-directory"],"backgroundTag":"temp-dir-creation-failed","analyzedSha":"f465ad909315a22120636baf03fa5e28701a50cb","analyzedAt":"2026-08-29T01:27:42.024Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}