Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

List Billing Accounts

gcp-billing-list-accounts

Retrieve all accessible Google Cloud billing accounts with pagination and filtering options to manage cloud spending.

Instructions

List all Google Cloud billing accounts accessible to the user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageSizeNoMaximum number of billing accounts to return (1-50)
pageTokenNoToken for pagination to get next page of results
filterNoOptional filter for billing accounts (e.g., 'open=true')

Implementation Reference

  • Handler function that lists GCP billing accounts using the Cloud Billing Client, handles pagination with pageSize/pageToken/filter, formats response with billing account details using formatBillingAccount helper, and returns markdown-formatted text content or error.
    async ({ pageSize, pageToken, filter }) => {
      try {
        const billingClient = getBillingClient();
    
        logger.debug(`Listing billing accounts with pageSize: ${pageSize}`);
    
        const request: any = {
          pageSize,
        };
    
        if (pageToken) {
          request.pageToken = pageToken;
        }
    
        if (filter) {
          request.filter = filter;
        }
    
        const [accounts, nextPageToken] =
          await billingClient.listBillingAccounts(request);
    
        if (!accounts || accounts.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: "No billing accounts found. You may need billing account access permissions.",
              },
            ],
          };
        }
    
        let response = `# Billing Accounts\n\n`;
        response += `Found ${accounts.length} billing account(s):\n\n`;
    
        for (const account of accounts) {
          const billingAccount: BillingAccount = {
            name: account.name || "",
            displayName: account.displayName || "Unknown",
            open: account.open || false,
            masterBillingAccount: account.masterBillingAccount,
            parent: account.parent,
          };
    
          response += formatBillingAccount(billingAccount) + "\n";
        }
    
        if (nextPageToken) {
          response += `\n**Next Page Token:** ${nextPageToken}\n`;
          response += `Use this token with the same tool to get the next page of results.\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: response,
            },
          ],
        };
      } catch (error: any) {
        logger.error(`Error listing billing accounts: ${error.message}`);
        throw new GcpMcpError(
          `Failed to list billing accounts: ${error.message}`,
          error.code || "UNKNOWN",
          error.status || 500,
        );
      }
    },
  • Input schema definition using Zod for the tool parameters: pageSize (1-50, default 20), optional pageToken for pagination, optional filter string.
    {
      title: "List Billing Accounts",
      description:
        "List all Google Cloud billing accounts accessible to the user",
      inputSchema: {
        pageSize: z
          .number()
          .min(1)
          .max(50)
          .default(20)
          .describe("Maximum number of billing accounts to return (1-50)"),
        pageToken: z
          .string()
          .optional()
          .describe("Token for pagination to get next page of results"),
        filter: z
          .string()
          .optional()
          .describe("Optional filter for billing accounts (e.g., 'open=true')"),
      },
  • MCP server tool registration call including name, schema, and handler reference. This is called from registerBillingTools function.
      "gcp-billing-list-accounts",
      {
        title: "List Billing Accounts",
        description:
          "List all Google Cloud billing accounts accessible to the user",
        inputSchema: {
          pageSize: z
            .number()
            .min(1)
            .max(50)
            .default(20)
            .describe("Maximum number of billing accounts to return (1-50)"),
          pageToken: z
            .string()
            .optional()
            .describe("Token for pagination to get next page of results"),
          filter: z
            .string()
            .optional()
            .describe("Optional filter for billing accounts (e.g., 'open=true')"),
        },
      },
      async ({ pageSize, pageToken, filter }) => {
        try {
          const billingClient = getBillingClient();
    
          logger.debug(`Listing billing accounts with pageSize: ${pageSize}`);
    
          const request: any = {
            pageSize,
          };
    
          if (pageToken) {
            request.pageToken = pageToken;
          }
    
          if (filter) {
            request.filter = filter;
          }
    
          const [accounts, nextPageToken] =
            await billingClient.listBillingAccounts(request);
    
          if (!accounts || accounts.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: "No billing accounts found. You may need billing account access permissions.",
                },
              ],
            };
          }
    
          let response = `# Billing Accounts\n\n`;
          response += `Found ${accounts.length} billing account(s):\n\n`;
    
          for (const account of accounts) {
            const billingAccount: BillingAccount = {
              name: account.name || "",
              displayName: account.displayName || "Unknown",
              open: account.open || false,
              masterBillingAccount: account.masterBillingAccount,
              parent: account.parent,
            };
    
            response += formatBillingAccount(billingAccount) + "\n";
          }
    
          if (nextPageToken) {
            response += `\n**Next Page Token:** ${nextPageToken}\n`;
            response += `Use this token with the same tool to get the next page of results.\n`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: response,
              },
            ],
          };
        } catch (error: any) {
          logger.error(`Error listing billing accounts: ${error.message}`);
          throw new GcpMcpError(
            `Failed to list billing accounts: ${error.message}`,
            error.code || "UNKNOWN",
            error.status || 500,
          );
        }
      },
    );
  • Intermediate registration function for billing service that calls registerBillingTools(server).
    export function registerBillingService(server: McpServer): void {
      registerBillingTools(server);
      registerBillingResources(server);
    }
  • src/index.ts:234-234 (registration)
    Top-level call to register the billing service (including gcp-billing-list-accounts tool) in the main MCP server setup.
    registerBillingService(server);
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions listing 'all' accounts accessible to the user, which implies a read-only operation, but doesn't disclose behavioral traits like pagination handling (implied by parameters), rate limits, authentication needs, or what 'accessible' entails (e.g., permissions).

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 a single, efficient sentence that is front-loaded with the core purpose. There is no wasted text, and it directly communicates the tool's function without unnecessary elaboration.

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?

Given the tool's low complexity (a list operation) and high schema coverage, the description is minimally adequate. However, with no annotations and no output schema, it lacks details on behavioral aspects (e.g., pagination behavior, error handling) and return values, leaving gaps for an AI agent.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all three parameters. The description adds no additional meaning beyond what's in the schema, such as explaining how 'filter' works in practice or typical use cases for pagination.

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

Purpose4/5

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

The description clearly states the action ('List all') and resource ('Google Cloud billing accounts'), and specifies the scope ('accessible to the user'). It distinguishes from siblings like 'gcp-billing-get-account-details' by focusing on listing rather than retrieving details, though it doesn't explicitly mention sibling differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention siblings like 'gcp-billing-list-projects' or 'gcp-billing-get-account-details', nor does it specify prerequisites or contexts for usage.

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

Install Server

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

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