Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYes

Implementation Reference

  • 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
  • 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)

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/DynamicEndpoints/PowerShell-Exec-MCP-Server'

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