Skip to main content
Glama

list_modal_volumes

Retrieve a list of all Modal volumes with JSON output for managing cloud storage in serverless applications.

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'list_modal_volumes' tool. It executes the Modal CLI command 'modal volume list --json', processes the JSON output using helper functions, and returns a standardized dictionary with volumes list or error details.
    @mcp.tool() 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
  • Core helper function used by list_modal_volumes to execute shell commands via subprocess, capturing stdout/stderr 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) }
  • Helper function called by list_modal_volumes to parse JSON from command stdout and standardize the response format with success/error handling.
    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
  • The @mcp.tool() decorator registers the list_modal_volumes function as an MCP tool.
    @mcp.tool()

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/smehmood/modal-mcp-server'

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