create_directory
Create new directories or ensure existing ones are present, including nested structures, to set up project paths and required filesystem locations.
Instructions
Create a new directory or ensure a directory exists. Can create multiple nested directories in one operation. If the directory already exists, this operation will succeed silently. Perfect for setting up directory structures for projects or ensuring required paths exist. Only works within allowed directories.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/filesystem/index.ts:390-398 (handler)The handler function that executes the create_directory tool logic. It validates the provided path, creates the directory recursively using fs.mkdir, and returns a success message.async (args: z.infer<typeof CreateDirectoryArgsSchema>) => { const validPath = await validatePath(args.path); await fs.mkdir(validPath, { recursive: true }); const text = `Successfully created directory ${args.path}`; return { content: [{ type: "text" as const, text }], structuredContent: { content: text } }; }
- src/filesystem/index.ts:110-112 (schema)Zod schema defining the input arguments for the create_directory tool: a single 'path' string parameter.const CreateDirectoryArgsSchema = z.object({ path: z.string(), });
- src/filesystem/index.ts:375-399 (registration)Registration of the create_directory tool with the MCP server, specifying title, description, input schema, output schema, annotations, and the handler function.server.registerTool( "create_directory", { title: "Create Directory", description: "Create a new directory or ensure a directory exists. Can create multiple " + "nested directories in one operation. If the directory already exists, " + "this operation will succeed silently. Perfect for setting up directory " + "structures for projects or ensuring required paths exist. Only works within allowed directories.", inputSchema: { path: z.string() }, outputSchema: { content: z.string() }, annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: false } }, async (args: z.infer<typeof CreateDirectoryArgsSchema>) => { const validPath = await validatePath(args.path); await fs.mkdir(validPath, { recursive: true }); const text = `Successfully created directory ${args.path}`; return { content: [{ type: "text" as const, text }], structuredContent: { content: text } }; } );