list_modal_volumes
Retrieve all Modal volumes in JSON format using the Modal CLI. This tool helps manage and interact with serverless cloud storage efficiently.
Instructions
List all Modal volumes using the Modal CLI with JSON output.
Returns:
A dictionary containing the parsed JSON output of the Modal volumes list.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/modal_mcp/server.py:96-111 (handler)The handler function for the 'list_modal_volumes' tool. It executes 'modal volume list --json' using the run_modal_command helper and processes the response with handle_json_response.async def list_modal_volumes() -> dict[str, Any]: """ List all Modal volumes using the Modal CLI with JSON output. Returns: A dictionary containing the parsed JSON output of the Modal volumes list. """ try: result = run_modal_command(["modal", "volume", "list", "--json"]) response = handle_json_response(result, "Failed to list volumes") if response["success"]: return {"success": True, "volumes": response["data"]} return response except Exception as e: logger.error(f"Failed to list Modal volumes: {e}") raise
- src/modal_mcp/server.py:15-40 (helper)Helper function to execute Modal CLI commands via subprocess, capturing output and handling errors.def run_modal_command(command: list[str], uv_directory: str = None) -> dict[str, Any]: """Run a Modal CLI command and return the result""" try: # uv_directory is necessary for modal deploy, since deploying the app requires the app to use the uv venv command = (["uv", "run", f"--directory={uv_directory}"] if uv_directory else []) + command logger.info(f"Running command: {' '.join(command)}") result = subprocess.run( command, capture_output=True, text=True, check=True ) return { "success": True, "stdout": result.stdout, "stderr": result.stderr, "command": ' '.join(command) } except subprocess.CalledProcessError as e: return { "success": False, "error": str(e), "stdout": e.stdout, "stderr": e.stderr, "command": ' '.join(command) }
- src/modal_mcp/server.py:42-70 (helper)Helper function to standardize responses from Modal commands by parsing JSON output from stdout and handling errors.def handle_json_response(result: Dict[str, Any], error_prefix: str) -> Dict[str, Any]: """ Handle JSON parsing of command output and return a standardized response. Args: result: The result from run_modal_command error_prefix: Prefix to use in error messages Returns: A dictionary with standardized success/error format """ if not result["success"]: response = {"success": False, "error": f"{error_prefix}: {result.get('error', 'Unknown error')}"} if result.get("stdout"): response["stdout"] = result["stdout"] if result.get("stderr"): response["stderr"] = result["stderr"] return response try: data = json.loads(result["stdout"]) return {"success": True, "data": data} except json.JSONDecodeError as e: response = {"success": False, "error": f"Failed to parse JSON output: {str(e)}"} if result.get("stdout"): response["stdout"] = result["stdout"] if result.get("stderr"): response["stderr"] = result["stderr"] return response