create_directory
Create or verify directory structures in one operation, including nested directories, within predefined paths. Ensures required paths exist silently for project setups.
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 | Path of the directory to create |
Implementation Reference
- src/index.ts:472-488 (handler)The main handler function for the create_directory tool. Validates input using the schema, validates the path against allowed directories, creates the directory recursively using fs.mkdir, logs the action, and returns a success message.case 'create_directory': { const parsed = CreateDirectoryArgsSchema.safeParse(a) if (!parsed.success) { throw new FileSystemError(`Invalid arguments for ${name}`, 'INVALID_ARGS', undefined, { errors: parsed.error.format(), }) } const validPath = await validatePath(parsed.data.path, config) await fs.mkdir(validPath, { recursive: true }) await logger.debug(`Created directory: ${validPath}`) endMetric() return { content: [{ type: 'text', text: `Successfully created directory ${parsed.data.path}` }], } }
- src/index.ts:116-118 (schema)Zod schema defining the input arguments for the create_directory tool: an object with a single 'path' string property.const CreateDirectoryArgsSchema = z.object({ path: z.string().describe('Path of the directory to create'), })
- src/index.ts:270-278 (registration)Tool registration in the ListTools response handler, defining the tool's name, detailed description, and input schema converted to JSON schema format.{ name: '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: zodToJsonSchema(CreateDirectoryArgsSchema) as ToolInput, },