Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-billing-get-account-details

Retrieve detailed information about a specific Google Cloud billing account to view costs, payment methods, and account settings.

Instructions

Retrieve detailed information about a specific Google Cloud billing account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
billingAccountNameYesBilling account name (e.g., 'billingAccounts/123456-789ABC-DEF012')

Implementation Reference

  • Registers the 'gcp-billing-get-account-details' tool with the MCP server instance.
    server.registerTool(
      "gcp-billing-get-account-details",
  • Input schema using Zod validation for the required 'billingAccountName' parameter.
    inputSchema: {
      billingAccountName: z
        .string()
        .describe(
          "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')",
        ),
    },
  • Handler function that executes the tool logic: initializes GCP Billing client, calls getBillingAccount API with the provided billingAccountName, maps response to BillingAccount interface, formats using formatBillingAccount helper, and returns markdown-formatted text response. Handles errors with GcpMcpError.
    async ({ billingAccountName }) => {
      try {
        const billingClient = getBillingClient();
    
        logger.debug(
          `Getting billing account details for: ${billingAccountName}`,
        );
    
        const [account] = await billingClient.getBillingAccount({
          name: billingAccountName,
        });
    
        if (!account) {
          return {
            content: [
              {
                type: "text",
                text: `Billing account not found: ${billingAccountName}`,
              },
            ],
          };
        }
    
        const billingAccount: BillingAccount = {
          name: account.name || "",
          displayName: account.displayName || "Unknown",
          open: account.open || false,
          masterBillingAccount: account.masterBillingAccount,
          parent: account.parent,
        };
    
        const response = formatBillingAccount(billingAccount);
    
        return {
          content: [
            {
              type: "text",
              text: response,
            },
          ],
        };
      } catch (error: any) {
        logger.error(`Error getting billing account details: ${error.message}`);
        throw new GcpMcpError(
          `Failed to get billing account details: ${error.message}`,
          error.code || "UNKNOWN",
          error.status || 500,
        );
      }
    },
  • Helper function to create and return a configured CloudBillingClient instance used by the tool handler.
    export function getBillingClient(): CloudBillingClient {
      return new CloudBillingClient({
        projectId: process.env.GOOGLE_CLOUD_PROJECT,
      });
    }
  • Helper function to format the retrieved BillingAccount object into a human-readable markdown string for the tool response.
    export function formatBillingAccount(account: BillingAccount): string {
      let result = `## ${account.displayName}\n\n`;
      result += `**Account Name:** ${account.name}\n`;
      result += `**Status:** ${account.open ? "✅ Active" : "❌ Closed"}\n`;
    
      if (account.masterBillingAccount) {
        result += `**Master Account:** ${account.masterBillingAccount}\n`;
      }
    
      if (account.parent) {
        result += `**Parent:** ${account.parent}\n`;
      }
    
      return result;

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/krzko/google-cloud-mcp'

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