remove_modal_volume_file
Delete files or directories from Modal volumes to manage cloud storage and maintain organized serverless environments.
Instructions
Delete a file or directory from a Modal volume.
Args:
volume_name: Name of the Modal volume to delete from.
remote_path: Path to the file or directory to delete.
recursive: If True, delete directories recursively. Required for deleting directories.
Returns:
A dictionary containing the result of the delete operation.
Raises:
Exception: If the delete operation fails for any reason.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| volume_name | Yes | ||
| remote_path | Yes | ||
| recursive | No |
Implementation Reference
- src/modal_mcp/server.py:180-221 (handler)The handler function decorated with @mcp.tool(), which registers and implements the 'remove_modal_volume_file' tool. It runs the 'modal volume rm' command (with optional -r flag) using the helper run_modal_command and returns a formatted success/error response.@mcp.tool() async def remove_modal_volume_file(volume_name: str, remote_path: str, recursive: bool = False) -> dict[str, Any]: """ Delete a file or directory from a Modal volume. Args: volume_name: Name of the Modal volume to delete from. remote_path: Path to the file or directory to delete. recursive: If True, delete directories recursively. Required for deleting directories. Returns: A dictionary containing the result of the delete operation. Raises: Exception: If the delete operation fails for any reason. """ try: command = ["modal", "volume", "rm"] if recursive: command.append("-r") command.extend([volume_name, remote_path]) result = run_modal_command(command) response = { "success": result["success"], "command": result["command"] } if not result["success"]: response["error"] = f"Failed to delete {remote_path}: {result.get('error', 'Unknown error')}" else: response["message"] = f"Successfully deleted {remote_path} from volume {volume_name}" if result.get("stdout"): response["stdout"] = result["stdout"] if result.get("stderr"): response["stderr"] = result["stderr"] return response except Exception as e: logger.error(f"Failed to delete from Modal volume: {e}") raise