ensure_directory
Create directories automatically to prevent errors in PowerShell automation workflows. Specify a path to verify existence or create missing directories and return the absolute path.
Instructions
Ensure directory exists and return absolute path.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- src/server.py:306-316 (handler)The handler function for the 'ensure_directory' tool. It normalizes the given path, ensures the directory exists by creating it if necessary using os.makedirs, and returns the absolute path.@mcp.tool() def ensure_directory(path: str) -> str: """Ensure directory exists and return absolute path.""" abs_path = normalize_path(path) if os.path.splitext(abs_path)[1]: # If path has an extension dir_path = os.path.dirname(abs_path) else: dir_path = abs_path os.makedirs(dir_path, exist_ok=True) return abs_path
- src/server.py:296-304 (helper)Helper utility function used by ensure_directory to convert relative paths to absolute paths based on the current working directory.def normalize_path(path: str) -> str: """Convert relative paths to absolute using current working directory.""" if not path: raise ValueError("Path cannot be empty") if path.startswith(('./','.\\')): path = path[2:] if not os.path.isabs(path): path = os.path.join(os.getcwd(), path) return os.path.abspath(path)