Skip to main content
Glama

create_directory

Create new directories to organize files and code projects. Specify the path where the directory should be created to structure your workspace.

Instructions

Creates a new directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • The core handler function in DirTools that validates the path, creates the directory using pathlib.mkdir with parents and exist_ok, returns success message or handles errors.
    async def create_directory(self, path: str) -> str: """Create a new directory. Args: path: Directory path to create Returns: Success message """ path = await self.validate_path(path) try: path.mkdir(parents=True, exist_ok=True) return f"Created directory: {path}" except Exception as e: self.handle_error(e, {"operation": "create_directory", "path": str(path)})
  • Pydantic model defining the input schema for the create_directory tool, with a single 'path' field accepting str or Path.
    class CreateDirectory(BaseModel): path: str | Path
  • Registration of the create_directory tool in the MCP server's list_tools() method, specifying name, description, and input schema.
    Tool( name=CodeAssistTools.CREATE_DIRECTORY, description="Creates a new directory", inputSchema=CreateDirectory.model_json_schema(), ),
  • Dispatch handler in the MCP server's call_tool() method that parses arguments into the model and invokes the DirTools.create_directory implementation.
    case CodeAssistTools.CREATE_DIRECTORY: model = CreateDirectory(path=arguments["path"]) result = await dir_tools.create_directory(model.path) return [TextContent(type="text", text=result)]
  • Helper method used by create_directory to validate and resolve the path, ensuring it's within allowed directories.
    async def validate_path(self, path: str) -> Path: """Validate and resolve path. Args: path: Path to validate Returns: Resolved Path object Raises: ValueError: If path is outside allowed directories """ abs_path = os.path.abspath(path) if not any(abs_path.startswith(p) for p in self.allowed_paths): raise ValueError(f"Path {path} is outside allowed directories") return Path(abs_path)

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/abhishekbhakat/mcp_server_code_assist'

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