Skip to main content
Glama

get_billing_info

Retrieve billing details for a specific Google Cloud Platform project by providing its project ID. Simplifies cost management and transparency for GCP resources.

Instructions

    Get billing information for a GCP project.
    
    Args:
        project_id: The ID of the GCP project to get billing information for
    
    Returns:
        Billing information for the specified GCP project
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • The get_billing_info tool handler: fetches GCP project billing info using CloudBillingClient, formats and returns details or errors.
        @mcp.tool()
        def get_billing_info(project_id: str) -> str:
            """
            Get billing information for a GCP project.
            
            Args:
                project_id: The ID of the GCP project to get billing information for
            
            Returns:
                Billing information for the specified GCP project
            """
            try:
                try:
                    from google.cloud import billing_v1
                except ImportError:
                    return "Error: The Google Cloud billing library is not installed. Please install it with 'pip install google-cloud-billing'."
                
                # Initialize the Cloud Billing client
                billing_client = billing_v1.CloudBillingClient()
                
                # Get the billing account for the project
                project_name = f"projects/{project_id}"
                billing_info = billing_client.get_project_billing_info(name=project_name)
                
                # If billing is enabled, get more details about the billing account
                if billing_info.billing_account_name:
                    billing_account = billing_client.get_billing_account(
                        name=billing_info.billing_account_name
                    )
                    
                    # Initialize the Cloud Catalog client to get pricing information
                    catalog_client = billing_v1.CloudCatalogClient()
                    
                    # Format the response
                    return f"""
    Billing Information for GCP Project {project_id}:
    
    Billing Enabled: {billing_info.billing_enabled}
    Billing Account: {billing_info.billing_account_name}
    Display Name: {billing_account.display_name}
    Open: {billing_account.open}
    """
                else:
                    return f"Billing is not enabled for project {project_id}."
            except Exception as e:
                return f"Error getting billing information: {str(e)}"
  • Input schema: project_id (str); Output: str (formatted billing info). Defined via type hints and docstring.
    def get_billing_info(project_id: str) -> str:
        """
        Get billing information for a GCP project.
        
        Args:
            project_id: The ID of the GCP project to get billing information for
        
        Returns:
            Billing information for the specified GCP project
        """
  • Module-level register_tools(mcp) defines and registers the get_billing_info tool via @mcp.tool() decorator.
    def register_tools(mcp):
        """Register all billing tools with the MCP server."""
        
        @mcp.tool()
        def get_billing_info(project_id: str) -> str:
            """
            Get billing information for a GCP project.
            
            Args:
                project_id: The ID of the GCP project to get billing information for
            
            Returns:
                Billing information for the specified GCP project
            """
            try:
                try:
                    from google.cloud import billing_v1
                except ImportError:
                    return "Error: The Google Cloud billing library is not installed. Please install it with 'pip install google-cloud-billing'."
                
                # Initialize the Cloud Billing client
                billing_client = billing_v1.CloudBillingClient()
                
                # Get the billing account for the project
                project_name = f"projects/{project_id}"
                billing_info = billing_client.get_project_billing_info(name=project_name)
                
                # If billing is enabled, get more details about the billing account
                if billing_info.billing_account_name:
                    billing_account = billing_client.get_billing_account(
                        name=billing_info.billing_account_name
                    )
                    
                    # Initialize the Cloud Catalog client to get pricing information
                    catalog_client = billing_v1.CloudCatalogClient()
                    
                    # Format the response
                    return f"""
    Billing Information for GCP Project {project_id}:
    
    Billing Enabled: {billing_info.billing_enabled}
    Billing Account: {billing_info.billing_account_name}
    Display Name: {billing_account.display_name}
    Open: {billing_account.open}
    """
                else:
                    return f"Billing is not enabled for project {project_id}."
            except Exception as e:
                return f"Error getting billing information: {str(e)}"
  • Imports the billing tools module (containing get_billing_info) for registration.
    from .gcp_modules.billing import tools as billing_tools
  • Calls register_tools on billing_tools module to register get_billing_info with the MCP server.
    billing_tools.register_tools(mcp)

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A3.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the burden of behavioral disclosure. It only states that it 'gets' and 'returns' billing information, without describing side effects, required permissions, error behavior, or output shape. The verb 'Get' implies a read-only operation, but this is not made explicit.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact: one purpose sentence plus minimal Args/Returns docstring. No filler or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple parameter getter, the description is moderately complete, but the return value is only described as 'Billing information', which is ambiguous. With no output schema or annotations, a slightly fuller description of what fields are returned would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The only parameter, project_id, is described as 'The ID of the GCP project', adding semantic clarity beyond the bare schema field. However, it does not specify expected format or related requirements, and schema coverage is 0%.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses a specific verb ('Get') and resource ('billing information for a GCP project'), making the tool's purpose unmistakable. No sibling tool covers billing, so it is well differentiated.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It clearly scopes use to a GCP project via project_id, which is sufficient context for when to call it. It does not explicitly name alternatives or exclusions, so it falls short of a 5.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.