Skip to main content
Glama
MrGNSS

Desktop Commander MCP

by MrGNSS

create_directory

Create new directories or ensure existing ones are available, including nested structures, within permitted locations on your computer.

Instructions

Create a new directory or ensure a directory exists. Can create multiple nested directories in one operation. Only works within allowed directories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The core handler function that performs the directory creation after path validation. Uses fs.mkdir with recursive option to create nested directories.
    export async function createDirectory(dirPath: string): Promise<void> {
        const validPath = await validatePath(dirPath);
        await fs.mkdir(validPath, { recursive: true });
    }
  • Zod schema defining the input arguments for the create_directory tool: a single 'path' string.
    export const CreateDirectoryArgsSchema = z.object({
      path: z.string(),
    });
  • src/server.ts:149-155 (registration)
    Tool registration in the listTools handler, specifying name, description, and input schema.
    {
      name: "create_directory",
      description:
        "Create a new directory or ensure a directory exists. Can create multiple " +
        "nested directories in one operation. Only works within allowed directories.",
      inputSchema: zodToJsonSchema(CreateDirectoryArgsSchema),
    },
  • src/server.ts:287-293 (registration)
    Dispatch handler in CallToolRequest that parses args, calls the createDirectory function, and formats the response.
    case "create_directory": {
      const parsed = CreateDirectoryArgsSchema.parse(args);
      await createDirectory(parsed.path);
      return {
        content: [{ type: "text", text: `Successfully created directory ${parsed.path}` }],
      };
    }
  • Security helper function used by createDirectory to validate and resolve the path, ensuring it's within allowed directories and handling symlinks.
    export async function validatePath(requestedPath: string): Promise<string> {
        const expandedPath = expandHome(requestedPath);
        const absolute = path.isAbsolute(expandedPath)
            ? path.resolve(expandedPath)
            : path.resolve(process.cwd(), expandedPath);
            
        const normalizedRequested = normalizePath(absolute);
    
        // Check if path is within allowed directories
        const isAllowed = allowedDirectories.some(dir => normalizedRequested.startsWith(normalizePath(dir)));
        if (!isAllowed) {
            throw new Error(`Access denied - path outside allowed directories: ${absolute}`);
        }
    
        // Handle symlinks by checking their real path
        try {
            const realPath = await fs.realpath(absolute);
            const normalizedReal = normalizePath(realPath);
            const isRealPathAllowed = allowedDirectories.some(dir => normalizedReal.startsWith(normalizePath(dir)));
            if (!isRealPathAllowed) {
                throw new Error("Access denied - symlink target outside allowed directories");
            }
            return realPath;
        } catch (error) {
            // For new files that don't exist yet, verify parent directory
            const parentDir = path.dirname(absolute);
            try {
                const realParentPath = await fs.realpath(parentDir);
                const normalizedParent = normalizePath(realParentPath);
                const isParentAllowed = allowedDirectories.some(dir => normalizedParent.startsWith(normalizePath(dir)));
                if (!isParentAllowed) {
                    throw new Error("Access denied - parent directory outside allowed directories");
                }
                return absolute;
            } catch {
                throw new Error(`Parent directory does not exist: ${parentDir}`);
            }
        }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.6/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'Only works within allowed directories' (a constraint) and 'Can create multiple nested directories' (a capability), but doesn't disclose critical behavioral traits like permissions needed, whether it overwrites existing directories, error handling, or response format. For a mutation tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three sentences, each adding value: first states purpose, second adds capability (nested directories), third adds constraint (allowed directories). No wasted words, front-loaded with core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given complexity (mutation tool creating directories), no annotations, no output schema, and low schema coverage (0%), the description is incomplete. It lacks details on permissions, error cases, return values, or how 'ensure exists' differs from 'create'. Should provide more context for safe usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It implies the 'path' parameter is used for creating directories, including nested ones, but doesn't specify format (e.g., absolute/relative paths), constraints, or examples. The description adds some meaning but doesn't fully compensate for the coverage gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('create' or 'ensure exists') and resource ('directory'), with specific details about creating nested directories in one operation. It distinguishes from siblings like 'list_directory' (read-only) and 'move_file' (different operation).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context with 'Only works within allowed directories', which implies a constraint but doesn't explicitly state when to use alternatives (e.g., no comparison to 'list_allowed_directories' for checking permissions). It lacks explicit exclusions or named alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.