Skip to main content
Glama
brevdev

Brev

Official
by brevdev

get_instance_types

Retrieve available instance types for cloud providers to optimize resource selection for ML model deployment. Supports AWS, GCP, Azure, and more.

Instructions

Get available instances types for a cloud provider

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cloud_providerYesThe cloud provider to get instance types for

Implementation Reference

  • MCP tool handler function that validates the cloud_provider argument, fetches instance types using get_provider_instance_types, and formats the response as TextContent.
    async def get_instance_types_tool(args: dict[str, str]) -> TextContent:
        if "cloud_provider" not in args:
            raise ValueError("cloud_provider argument is required for get_instance_types tool")
    
        cloud_provider = CloudProvider(args["cloud_provider"])
        instance_types = await get_provider_instance_types(cloud_provider)
        return [
            TextContent(
                type="text", 
                text=instance_types
            )
        ]
  • Input schema definition for the get_instance_types tool, specifying the required cloud_provider parameter with enum values from CloudProvider.
    inputSchema={
        "type": "object",
        "properties": {
            "cloud_provider": {
                "description": "The cloud provider to get instance types for",
                "enum": [provider.value for provider in CloudProvider]
            }
        },
        "required": ["cloud_provider"]
    }
  • Registration of the get_instance_types tool in the tool_models dictionary, linking the tool schema, description, and handler function.
    "get_instance_types": ToolModel(
        tool=Tool(
            name="get_instance_types",
            description="Get available instances types for a cloud provider",
            inputSchema={
                "type": "object",
                "properties": {
                    "cloud_provider": {
                        "description": "The cloud provider to get instance types for",
                        "enum": [provider.value for provider in CloudProvider]
                    }
                },
                "required": ["cloud_provider"]
            }
        ),
        call_tool=get_instance_types_tool
    ),
  • Helper function that retrieves all instance types from the API, filters and selects those for the given provider, and returns a formatted JSON string.
    async def get_provider_instance_types(provider: CloudProvider)-> str:
        try:
            all_instance_types_obj = await get_instance_types()
            instance_types = filter_instance_types(all_instance_types_obj)
            for cloud_provider, instance_type_list in instance_types.items():
                logger.info(f"Number of instance types for {cloud_provider.value}: {len(instance_type_list)}")
            if provider not in instance_types:
                raise ValueError(f"Provider {provider.value} not found in instance types")
            instance_type_dicts = [
                instance_type.model_dump(exclude_none=True) 
                for instance_type in instance_types[provider]
            ] 
            return json.dumps(instance_type_dicts, indent=2)
        except Exception as e:
            logger.error(f"Error getting instance types: {str(e)}")
            raise RuntimeError(f"Failed to get instance types: {str(e)}")
  • Core helper function that performs the HTTP API call to Brev's endpoint to fetch all available instance types, validates the response, and returns the parsed object.
    async def get_instance_types() -> AllInstanceTypeObj:
        access_token = get_acess_token() 
        org_id = get_active_org_id()
        try:
            async with httpx.AsyncClient(timeout=httpx.Timeout(25.0)) as client:
                response = await client.get(
                    f"{BASE_API_URL}/instances/alltypesavailable/{org_id}",
                    headers={
                        "Authorization": f"Bearer {access_token}",
                        "Content-Type": "application/json"
                    },
                )
                response.raise_for_status()
                data = response.json()
                all_instance_types_obj = AllInstanceTypeObj.model_validate(data)
                return all_instance_types_obj
        except ValidationError as e:    
            raise RuntimeError(f"Failed to validate instance types: {str(e)}")
        except Exception as e:
            raise RuntimeError(f"Failed to get instance types: {str(e)}")
Install Server

Other Tools

Related Tools

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/brevdev/brev-mcp'

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