create_directory
Create a new directory at the specified path to organize files and folders.
Instructions
Create directory
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/filesystem_tools.js:251-275 (handler)The actual implementation of create_directory: resolves the path, checks if it's allowed via isPathAllowed, then calls fs.mkdirSync with {recursive:true} to create the directory.
function createDirectory(dirPath, allowedDirs) { try { if (!dirPath) { return { success: false, message: 'No directory path provided' }; } if (!isPathAllowed(dirPath, allowedDirs)) { return { success: false, message: `Access to path "${dirPath}" is not allowed` }; } const resolvedPath = path.resolve(dirPath); // Create the directory fs.mkdirSync(resolvedPath, { recursive: true }); return { success: true, message: `Directory created successfully: ${dirPath}`, path: dirPath }; } catch (error) { logger.error(`Error creating directory: ${error.message}`); return { success: false, message: `Error creating directory: ${error.message}` }; } } - src/mcp/server.js:88-89 (registration)Registration of the 'create_directory' tool in the MCP tools/list response with inputSchema requiring 'path'.
{ name:'create_directory', description:'Create directory'+(readonlyMode?' (RO)':''), inputSchema:{ type:'object', properties:{ path:{type:'string'} }, required:['path'] } }, { name:'tree', description:'Directory tree', inputSchema:{ type:'object', properties:{ path:{type:'string'}, depth:{type:'number'}, follow_symlinks:{type:'boolean'} }, required:['path'] } }, - src/mcp/server.js:231-234 (handler)Dispatch in the tools/call handler: checks readonly mode, then calls filesystemTools.createDirectory(args.path, allowedDirectories).
case 'create_directory': if (!checkReadOnly('create_directory')) { data = { success:false, message:'Operation not allowed: read-only mode' }; break; } data = filesystemTools.createDirectory(args.path, allowedDirectories); break; - src/filesystem_tools.js:21-35 (helper)The isPathAllowed helper function used by createDirectory to validate the path is within allowed directories.
function isPathAllowed(filePath, allowedDirs) { if (!allowedDirs || !Array.isArray(allowedDirs) || allowedDirs.length === 0) { logger.error('No allowed directories configured'); return false; } // Resolve to absolute path const resolvedPath = path.resolve(filePath); // Check if the path is within any of the allowed directories return allowedDirs.some(dir => { const resolvedDir = path.resolve(dir); return resolvedPath === resolvedDir || resolvedPath.startsWith(resolvedDir + path.sep); }); } - src/mcp/server.js:88-88 (schema)Input schema for create_directory: type 'object' with a required 'path' property of type 'string'.
{ name:'create_directory', description:'Create directory'+(readonlyMode?' (RO)':''), inputSchema:{ type:'object', properties:{ path:{type:'string'} }, required:['path'] } },