Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesPath to create
recursiveNoCreate parent directories

Implementation Reference

  • 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}`,
              }),
            },
          ],
        };
      }
    }
  • 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>;
  • 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);
      }
    );

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/mcp-tool-shop-org/mcp-file-forge'

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