create_directory
Create directories at specified paths with optional parent directory creation for organizing files in MCP File Forge's secure environment.
Instructions
Create a directory
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to create | |
| recursive | No | Create parent directories |
Implementation Reference
- src/tools/write.ts:124-187 (handler)The core logic for creating a directory, implemented in `createDirectoryImpl` within `src/tools/write.ts`.
async function createDirectoryImpl(input: CreateDirectoryInput): Promise<ToolResult> { try { const absolutePath = path.resolve(input.path); await fs.mkdir(absolutePath, { recursive: input.recursive }); return { content: [ { type: 'text', text: JSON.stringify({ success: true, path: absolutePath, }), }, ], }; } catch (error) { const err = error as NodeJS.ErrnoException; if (err.code === 'EEXIST') { return { content: [ { type: 'text', text: JSON.stringify({ success: true, path: path.resolve(input.path), note: 'Directory already exists', }), }, ], }; } if (err.code === 'EACCES') { return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'PERMISSION_DENIED', message: `Permission denied: ${input.path}`, }), }, ], }; } return { isError: true, content: [ { type: 'text', text: JSON.stringify({ code: 'UNKNOWN_ERROR', message: `Error creating directory: ${err.message}`, }), }, ], }; } } - src/types.ts:184-190 (schema)Zod schema definition and TypeScript type for `create_directory` tool inputs.
// Create directory input export const CreateDirectoryInputSchema = z.object({ path: z.string().describe('Path to create'), recursive: z.boolean().default(true).describe('Create parent directories'), }); export type CreateDirectoryInput = z.infer<typeof CreateDirectoryInputSchema>; - src/tools/write.ts:562-574 (registration)Registration of the `create_directory` tool in the MCP server within `registerWriteTools`.
// create_directory tool server.tool( 'create_directory', 'Create a directory', { path: z.string().describe('Path to create'), recursive: z.boolean().optional().describe('Create parent directories'), }, async (args) => { const input = CreateDirectoryInputSchema.parse(args); return await createDirectoryImpl(input); } );