change_directory
Changes the current working directory to a specified path, enabling navigation to different directories for file operations.
Instructions
Change current working directory
Args:
path: Directory path to switch to
Returns:
Operation result informationInput Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- terminal_controller.py:180-199 (handler)The `change_directory` async function is the tool handler. It changes the current working directory using os.chdir() and returns a result message with error handling for FileNotFoundError, PermissionError, and generic exceptions. It is decorated with @mcp.tool(), which is both the handler and registration.
@mcp.tool() async def change_directory(path: str) -> str: """ Change current working directory Args: path: Directory path to switch to Returns: Operation result information """ try: os.chdir(path) return f"Switched to directory: {os.getcwd()}" except FileNotFoundError: return f"Error: Directory '{path}' does not exist" except PermissionError: return f"Error: No permission to access directory '{path}'" except Exception as e: return f"Error changing directory: {str(e)}"