remove_modal_volume_file
Delete files or directories from a Modal volume. Specify the volume name, remote path, and optional recursive flag for directory removal. Returns the outcome of the operation.
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 |
|---|---|---|---|
| recursive | No | ||
| remote_path | Yes | ||
| volume_name | Yes |
Implementation Reference
- src/modal_mcp/server.py:180-221 (handler)The handler function for the 'remove_modal_volume_file' tool, including the @mcp.tool() decorator for automatic registration and schema generation from type hints and docstring. It builds and executes a 'modal volume rm' command (with optional -r flag) using the shared run_modal_command helper, formats the response with success/error details.@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