Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

Get Project Billing Information

gcp-billing-get-project-info

Retrieve billing configuration and status for a Google Cloud project to monitor costs and manage payment settings.

Instructions

Retrieve billing configuration and status for a Google Cloud project

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectIdNoProject ID (defaults to current project from state manager)

Implementation Reference

  • The handler function that executes the tool logic: determines the project ID, fetches billing info using Cloud Billing Client's getProjectBillingInfo method, formats the response with details on billing status and account.
    async ({ projectId }) => {
      try {
        // Use project hierarchy: provided -> state manager -> auth default
        const actualProjectId =
          projectId ||
          stateManager.getCurrentProjectId() ||
          (await getProjectId());
    
        if (!actualProjectId) {
          throw new GcpMcpError(
            "No project ID available. Please provide a project ID or configure a default project.",
            "INVALID_ARGUMENT",
            400,
          );
        }
    
        const billingClient = getBillingClient();
    
        logger.debug(`Getting billing info for project: ${actualProjectId}`);
    
        const [billingInfo] = await billingClient.getProjectBillingInfo({
          name: `projects/${actualProjectId}`,
        });
    
        if (!billingInfo) {
          return {
            content: [
              {
                type: "text",
                text: `# Project Billing Information\n\nNo billing information found for project: ${actualProjectId}\n\nThis could mean:\n- The project doesn't exist\n- You don't have billing permissions\n- The project is not associated with a billing account`,
              },
            ],
          };
        }
    
        const projectBillingInfo: ProjectBillingInfo = {
          name: billingInfo.name || "",
          projectId: actualProjectId,
          billingAccountName: billingInfo.billingAccountName || undefined,
          billingEnabled: billingInfo.billingEnabled || false,
        };
    
        let response = `# Project Billing Information\n\n`;
        response += `**Project ID:** ${projectBillingInfo.projectId}\n`;
        response += `**Project Name:** ${projectBillingInfo.name}\n`;
        response += `**Billing Enabled:** ${projectBillingInfo.billingEnabled ? "✅ Yes" : "❌ No"}\n`;
    
        if (projectBillingInfo.billingAccountName) {
          response += `**Billing Account:** ${projectBillingInfo.billingAccountName}\n`;
        } else {
          response += `**Billing Account:** Not associated\n`;
        }
    
        if (!projectBillingInfo.billingEnabled) {
          response += `\n## Required Permissions\n\n`;
          response += `To manage billing for this project, you need:\n`;
          response += `- \`${BILLING_IAM_PERMISSIONS.BILLING_RESOURCE_ASSOCIATIONS_CREATE}\` - To associate with billing account\n`;
          response += `- \`${BILLING_IAM_PERMISSIONS.BILLING_ACCOUNTS_LIST}\` - To list available billing accounts\n`;
        }
    
        return {
          content: [
            {
              type: "text",
              text: response,
            },
          ],
        };
      } catch (error: any) {
        logger.error(`Error getting project billing info: ${error.message}`);
        throw new GcpMcpError(
          `Failed to get project billing info: ${error.message}`,
          error.code || "UNKNOWN",
          error.status || 500,
        );
      }
    },
  • Input schema for the tool, defining an optional projectId parameter with Zod validation.
    {
      title: "Get Project Billing Information",
      description:
        "Retrieve billing configuration and status for a Google Cloud project",
      inputSchema: {
        projectId: z
          .string()
          .optional()
          .describe(
            "Project ID (defaults to current project from state manager)",
          ),
      },
  • MCP tool registration call including name, metadata, schema, and inline handler function.
    server.registerTool(
      "gcp-billing-get-project-info",
      {
        title: "Get Project Billing Information",
        description:
          "Retrieve billing configuration and status for a Google Cloud project",
        inputSchema: {
          projectId: z
            .string()
            .optional()
            .describe(
              "Project ID (defaults to current project from state manager)",
            ),
        },
      },
      async ({ projectId }) => {
        try {
          // Use project hierarchy: provided -> state manager -> auth default
          const actualProjectId =
            projectId ||
            stateManager.getCurrentProjectId() ||
            (await getProjectId());
    
          if (!actualProjectId) {
            throw new GcpMcpError(
              "No project ID available. Please provide a project ID or configure a default project.",
              "INVALID_ARGUMENT",
              400,
            );
          }
    
          const billingClient = getBillingClient();
    
          logger.debug(`Getting billing info for project: ${actualProjectId}`);
    
          const [billingInfo] = await billingClient.getProjectBillingInfo({
            name: `projects/${actualProjectId}`,
          });
    
          if (!billingInfo) {
            return {
              content: [
                {
                  type: "text",
                  text: `# Project Billing Information\n\nNo billing information found for project: ${actualProjectId}\n\nThis could mean:\n- The project doesn't exist\n- You don't have billing permissions\n- The project is not associated with a billing account`,
                },
              ],
            };
          }
    
          const projectBillingInfo: ProjectBillingInfo = {
            name: billingInfo.name || "",
            projectId: actualProjectId,
            billingAccountName: billingInfo.billingAccountName || undefined,
            billingEnabled: billingInfo.billingEnabled || false,
          };
    
          let response = `# Project Billing Information\n\n`;
          response += `**Project ID:** ${projectBillingInfo.projectId}\n`;
          response += `**Project Name:** ${projectBillingInfo.name}\n`;
          response += `**Billing Enabled:** ${projectBillingInfo.billingEnabled ? "✅ Yes" : "❌ No"}\n`;
    
          if (projectBillingInfo.billingAccountName) {
            response += `**Billing Account:** ${projectBillingInfo.billingAccountName}\n`;
          } else {
            response += `**Billing Account:** Not associated\n`;
          }
    
          if (!projectBillingInfo.billingEnabled) {
            response += `\n## Required Permissions\n\n`;
            response += `To manage billing for this project, you need:\n`;
            response += `- \`${BILLING_IAM_PERMISSIONS.BILLING_RESOURCE_ASSOCIATIONS_CREATE}\` - To associate with billing account\n`;
            response += `- \`${BILLING_IAM_PERMISSIONS.BILLING_ACCOUNTS_LIST}\` - To list available billing accounts\n`;
          }
    
          return {
            content: [
              {
                type: "text",
                text: response,
              },
            ],
          };
        } catch (error: any) {
          logger.error(`Error getting project billing info: ${error.message}`);
          throw new GcpMcpError(
            `Failed to get project billing info: ${error.message}`,
            error.code || "UNKNOWN",
            error.status || 500,
          );
        }
      },
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'Retrieve billing configuration and status,' implying a read-only operation, but does not specify permissions required, rate limits, error handling, or what 'configuration and status' entails (e.g., billing account linkage, budget settings). This leaves significant gaps for a tool with no annotation coverage.

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, clear sentence that directly states the tool's function without unnecessary words. It is front-loaded with the core action and resource, making it efficient and easy to understand at a glance.

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 (1 parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks details on usage guidelines, behavioral traits, and output expectations, which are needed for full contextual understanding despite the simple schema.

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?

The input schema has 100% description coverage, with the 'projectId' parameter well-documented in the schema itself. The description does not add any additional meaning or context beyond what the schema provides, such as examples or default behavior nuances, so it meets the baseline for high schema coverage without extra value.

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 ('Retrieve') and resource ('billing configuration and status for a Google Cloud project'), making the purpose evident. However, it does not explicitly differentiate from siblings like 'gcp-billing-get-account-details' or 'gcp-billing-list-projects', which might also involve billing information, so it lacks sibling distinction for a perfect score.

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, such as when to choose it over 'gcp-billing-get-account-details' for project-specific details or 'gcp-billing-list-projects' for broader listings. There is no mention of prerequisites, exclusions, or contextual cues, leaving usage unclear.

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