Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-billing-list-projects

Retrieve all Google Cloud projects linked to a specific billing account to manage costs and track resource usage across your organization.

Instructions

List all projects associated with a specific Google Cloud billing account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
billingAccountNameYesBilling account name (e.g., 'billingAccounts/123456-789ABC-DEF012')
pageSizeNoMaximum number of projects to return (1-200)
pageTokenNoToken for pagination to get next page of results

Implementation Reference

  • The handler function for the 'gcp-billing-list-projects' tool. It uses the Cloud Billing API to list projects associated with a billing account, formats results as a Markdown table with project ID, billing status, and name, supports pagination, and handles errors.
    async ({ billingAccountName, pageSize, pageToken }) => {
      try {
        const billingClient = getBillingClient();
    
        logger.debug(
          `Listing projects for billing account: ${billingAccountName}`,
        );
    
        const request: any = {
          name: billingAccountName,
          pageSize,
        };
    
        if (pageToken) {
          request.pageToken = pageToken;
        }
    
        const [projects, nextPageToken] =
          await billingClient.listProjectBillingInfo(request);
    
        if (!projects || projects.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No projects found for billing account: ${billingAccountName}`,
              },
            ],
          };
        }
    
        let response = `# Projects for Billing Account\n\n`;
        response += `**Billing Account:** ${billingAccountName}\n`;
        response += `**Projects Found:** ${projects.length}\n\n`;
    
        response += "| Project ID | Billing Enabled | Project Name |\n";
        response += "|------------|-----------------|-------------|\n";
    
        for (const project of projects) {
          const projectId = project.name?.replace("projects/", "") || "Unknown";
          const billingEnabled = project.billingEnabled ? "✅ Yes" : "❌ No";
          const projectName = project.name || "Unknown";
    
          response += `| ${projectId} | ${billingEnabled} | ${projectName} |\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 projects for billing account: ${error.message}`,
        );
        throw new GcpMcpError(
          `Failed to list projects for billing account: ${error.message}`,
          error.code || "UNKNOWN",
          error.status || 500,
        );
      }
    },
  • Input schema definition for the tool, using Zod for validation of billingAccountName (required), pageSize (1-200, default 50), and optional pageToken.
    {
      title: "List Billing Account Projects",
      description:
        "List all projects associated with a specific Google Cloud billing account",
      inputSchema: {
        billingAccountName: z
          .string()
          .describe(
            "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')",
          ),
        pageSize: z
          .number()
          .min(1)
          .max(200)
          .default(50)
          .describe("Maximum number of projects to return (1-200)"),
        pageToken: z
          .string()
          .optional()
          .describe("Token for pagination to get next page of results"),
      },
  • Registration of the tool with the MCP server using server.registerTool.
    server.registerTool(

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