Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

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);

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