Skip to main content
Glama

mkdir

Create directories at specified paths, including nested structures, to organize filesystem content.

Instructions

Create a new directory at the specified path (recursive).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoAbsolute path to file or directory.
pathsNoAbsolute paths to directories to create

Implementation Reference

  • The handler function that executes directory creation using fs.mkdir.
    async function handleCreateDirectory(
      args: z.infer<typeof CreateDirectoryInputSchema>,
      signal?: AbortSignal
    ): Promise<ToolResponse<z.infer<typeof CreateDirectoryOutputSchema>>> {
      const allPaths: string[] = [];
      if (args.path) allPaths.push(args.path);
      if (args.paths) allPaths.push(...args.paths);
    
      if (allPaths.length === 0) {
        throw new McpError(
          ErrorCode.E_INVALID_INPUT,
          'No paths provided to create.'
        );
      }
    
      const validPaths = await Promise.all(
        allPaths.map((p) => validatePathForWrite(p, signal))
      );
    
      await Promise.all(
        validPaths.map((p) => withAbort(fs.mkdir(p, { recursive: true }), signal))
      );
    
      return buildToolResponse(
        `Successfully created ${validPaths.length} director${validPaths.length === 1 ? 'y' : 'ies'}`,
        {
          ok: true,
          paths: validPaths,
        }
      );
    }
  • Registration of the mkdir tool with the MCP server.
    server.registerTool(
      'mkdir',
      withDefaultIcons({ ...CREATE_DIRECTORY_TOOL }, options.iconInfo),
      validatedHandler
    );

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/j0hanz/filesystem-mcp'

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