Skip to main content
Glama
safurrier

MCP Filesystem Server

create_directory

Create new directories or ensure existing ones are present, with options to automatically create parent directories and handle existing ones without errors.

Instructions

Create a new directory or ensure a directory exists.

Args:
    path: Path to the directory
    parents: Create parent directories if they don't exist
    exist_ok: Don't raise an error if directory already exists
    ctx: MCP context

Returns:
    Success or error message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
parentsNo
exist_okNo

Implementation Reference

  • MCP tool handler for create_directory, decorated with @mcp.tool(), which registers the tool and defines its schema via args/docstring. Delegates to FileOperations.create_directory.
    @mcp.tool()
    async def create_directory(
        path: str,
        ctx: Context,
        parents: bool = True,
        exist_ok: bool = True,
    ) -> str:
        """Create a new directory or ensure a directory exists.
    
        Args:
            path: Path to the directory
            parents: Create parent directories if they don't exist
            exist_ok: Don't raise an error if directory already exists
            ctx: MCP context
    
        Returns:
            Success or error message
        """
        try:
            components = get_components()
            await components["operations"].create_directory(path, parents, exist_ok)
            return f"Successfully created directory {path}"
        except Exception as e:
            return f"Error creating directory: {str(e)}"
  • Core implementation of directory creation in FileOperations class using pathlib.Path.mkdir with path validation.
    async def create_directory(
        self, path: Union[str, Path], parents: bool = True, exist_ok: bool = True
    ) -> None:
        """Create a directory.
    
        Args:
            path: Path to the directory
            parents: Create parent directories if they don't exist
            exist_ok: Don't raise an error if directory already exists
    
        Raises:
            ValueError: If path is outside allowed directories
            PermissionError: If directory cannot be created
        """
        abs_path, allowed = await self.validator.validate_path(path)
        if not allowed:
            raise ValueError(f"Path outside allowed directories: {path}")
    
        try:
            # Using partial to help mypy understand we're passing args to mkdir, not run_sync
            await anyio.to_thread.run_sync(
                partial(abs_path.mkdir, parents=parents, exist_ok=exist_ok)
            )
        except FileExistsError:
            if not exist_ok:
                raise ValueError(f"Directory already exists: {path}")
        except PermissionError as e:
            raise ValueError(f"Cannot create directory: {e}")
Behavior3/5

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

With no annotations provided, the description carries the full burden. It mentions the tool can 'ensure a directory exists' and describes parameter behaviors (parents creation, error handling with exist_ok), which adds useful context beyond just 'create.' However, it doesn't disclose permissions needed, whether it's idempotent, or what specific error messages might be returned.

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

Conciseness4/5

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

The description is well-structured and appropriately sized. It starts with a clear purpose statement, then lists parameters with helpful explanations, and ends with return information. Every sentence earns its place, though the 'ctx: MCP context' parameter explanation is somewhat redundant since MCP context is typically implicit.

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

Completeness3/5

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

Given 3 parameters with 0% schema coverage and no output schema, the description does a good job explaining parameters but could be more complete. It mentions return is a 'Success or error message' but doesn't specify format or examples. For a mutation tool with no annotations, more behavioral context about permissions, side effects, or error conditions would be helpful.

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

Parameters5/5

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

The description provides excellent parameter semantics beyond the input schema, which has 0% description coverage. It clearly explains what each parameter does: 'path: Path to the directory', 'parents: Create parent directories if they don't exist', 'exist_ok: Don't raise an error if directory already exists'. This fully compensates for the schema's lack of descriptions.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Create a new directory or ensure a directory exists.' This specifies the verb (create/ensure) and resource (directory). However, it doesn't explicitly differentiate from sibling tools like 'list_directory' or 'directory_tree' beyond the obvious creation vs. listing distinction.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, when not to use it, or how it compares to sibling tools like 'move_file' or 'find_empty_directories' that might involve directory operations. Usage is implied by the name but not explicitly stated.

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

Install Server

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

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