Skip to main content
Glama
by Wayazi

create_directory

Create a directory at a specified path using the MCP File System server. The tool ensures controlled directory management with input validation and security protocols.

Input Schema

NameRequiredDescriptionDefault
pathYesDirectory path to create

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "path": { "description": "Directory path to create", "type": "string" } }, "required": [ "path" ], "type": "object" }

Implementation Reference

  • The handler function that executes the create_directory tool: validates the path, creates directory recursively with fs.mkdir, and returns appropriate content response.
    async ({ path: dirPath }: { path: string }) => { try { const validPath = validatePath(dirPath); await fs.mkdir(validPath, { recursive: true }); return { content: [{ type: 'text', text: `Directory created: ${dirPath}` }] }; } catch (error: any) { return { content: [{ type: 'text', text: `Error creating directory: ${error.message}` }] }; } }
  • Input schema for create_directory tool using Zod: path as string.
    { path: z.string().describe("Directory path to create") },
  • src/index.ts:93-105 (registration)
    Registration of the create_directory tool on the MCP server.
    server.tool( "create_directory", { path: z.string().describe("Directory path to create") }, async ({ path: dirPath }: { path: string }) => { try { const validPath = validatePath(dirPath); await fs.mkdir(validPath, { recursive: true }); return { content: [{ type: 'text', text: `Directory created: ${dirPath}` }] }; } catch (error: any) { return { content: [{ type: 'text', text: `Error creating directory: ${error.message}` }] }; } } );
  • Shared helper function validatePath used in the handler to ensure the directory path is within allowed directories.
    function validatePath(filePath: string): string { const absolutePath = path.resolve(filePath); if (!allowedDirs.some(dir => absolutePath.startsWith(path.resolve(dir)))) { throw new Error(`Access denied: ${filePath} is not within allowed directories`); } return absolutePath; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Wayazi/mcp_file_system'

If you have feedback or need assistance with the MCP directory API, please join our Discord server