create_directory
Set up or validate directory structures by creating new directories or ensuring existing paths. Supports nested directories in a single operation, ideal for project setups or required paths within allowed spaces.
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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"path": {
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- src/filesystem/index.ts:390-398 (handler)Handler function for the create_directory tool. Validates the 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 path string.const CreateDirectoryArgsSchema = z.object({ path: z.string(), });
- src/filesystem/index.ts:375-399 (registration)Registers the create_directory tool with the MCP server, including title, description, input/output schemas, annotations, and the inline 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 } }; } );