create_directory
Create a new directory at a specified path to organize files within a development workspace.
Instructions
Create a new directory
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path for the new directory |
Implementation Reference
- src/services/FileService.ts:350-387 (handler)The createDirectory method in FileService that creates a new directory. It resolves the path, checks if the directory already exists (returns error if so), creates it with fs.mkdir({ recursive: true }), and returns a success or error ToolResult.
async createDirectory(dirPath: string): Promise<ToolResult> { try { const fullPath = this.workspaceService.resolvePath(dirPath); // Check if directory already exists try { const stats = await fs.stat(fullPath); if (stats.isDirectory()) { return { isError: true, content: [{ type: 'text', text: `Directory already exists: ${fullPath}` }] }; } } catch { // Directory doesn't exist, which is what we want } await fs.mkdir(fullPath, { recursive: true }); return { content: [{ type: 'text', text: `Directory successfully created: ${fullPath}`, }], }; } catch (error: any) { return { isError: true, content: [{ type: 'text', text: error.message || 'Failed to create directory' }] }; } } - src/toolDefinitions.ts:108-118 (schema)The input schema definition for the 'create_directory' tool. Defines a 'path' string property as required input and provides the description 'Create a new directory'.
{ name: 'create_directory', description: 'Create a new directory', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path for the new directory' }, }, required: ['path'], }, }, - src/index.ts:163-164 (handler)The routing in executeToolCommand where the 'create_directory' case dispatches to this.fileService.createDirectory(args.path).
case 'create_directory': return await this.fileService.createDirectory(args.path); - src/index.ts:112-114 (registration)Tool registration using ListToolsRequestSchema - this server's setRequestHandler returns TOOL_DEFINITIONS which includes the create_directory definition.
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOL_DEFINITIONS, })); - tests/utils.ts:272-272 (helper)Mock createDirectory function used in tests for the FileService mock.
createDirectory: jest.fn()