mkdir
Create directories at specified paths, including nested structures, to organize filesystem content.
Instructions
Create a new directory at the specified path (recursive).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Absolute path to file or directory. | |
| paths | No | Absolute paths to directories to create |
Implementation Reference
- src/tools/create-directory.ts:41-71 (handler)The handler function that executes directory creation using fs.mkdir.
async function handleCreateDirectory( args: z.infer<typeof CreateDirectoryInputSchema>, signal?: AbortSignal ): Promise<ToolResponse<z.infer<typeof CreateDirectoryOutputSchema>>> { const allPaths: string[] = []; if (args.path) allPaths.push(args.path); if (args.paths) allPaths.push(...args.paths); if (allPaths.length === 0) { throw new McpError( ErrorCode.E_INVALID_INPUT, 'No paths provided to create.' ); } const validPaths = await Promise.all( allPaths.map((p) => validatePathForWrite(p, signal)) ); await Promise.all( validPaths.map((p) => withAbort(fs.mkdir(p, { recursive: true }), signal)) ); return buildToolResponse( `Successfully created ${validPaths.length} director${validPaths.length === 1 ? 'y' : 'ies'}`, { ok: true, paths: validPaths, } ); } - src/tools/create-directory.ts:133-137 (registration)Registration of the mkdir tool with the MCP server.
server.registerTool( 'mkdir', withDefaultIcons({ ...CREATE_DIRECTORY_TOOL }, options.iconInfo), validatedHandler );