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
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
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
- src/mcp_server_code_assist/server.py:84-88 (registration)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(), ),
- src/mcp_server_code_assist/server.py:165-168 (registration)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)