Skip to main content
Glama
krzko

Google Cloud MCP Server

by krzko

gcp-billing-cost-recommendations

Analyze Google Cloud billing to identify cost-saving opportunities by generating tailored recommendations based on account, project, savings priority, and minimum savings threshold.

Instructions

Generate cost optimisation recommendations with potential savings for Google Cloud billing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
billingAccountNameYesBilling account name (e.g., 'billingAccounts/123456-789ABC-DEF012')
minSavingsAmountNoMinimum savings amount to include in recommendations
priorityNoFilter recommendations by priority levelall
projectIdNoOptional project ID to filter recommendations

Implementation Reference

  • The main handler function for the 'gcp-billing-cost-recommendations' tool. It generates mock cost optimization recommendations based on input parameters, filters them, formats the response, and returns markdown content with potential savings.
    async ({ billingAccountName, projectId, minSavingsAmount, priority }) => { try { // Use project hierarchy: provided -> state manager -> auth default const actualProjectId = projectId || stateManager.getCurrentProjectId() || (await getProjectId()); logger.debug( `Generating cost recommendations for billing account: ${billingAccountName}, project: ${actualProjectId || "all"}`, ); // Mock recommendations for demonstration const mockRecommendations: CostRecommendation[] = [ { type: "rightsizing", projectId: actualProjectId || "example-project-1", serviceId: "compute.googleapis.com", resourceName: "instance-group-1", description: "Compute Engine instances are underutilised and can be right-sized", potentialSavings: { amount: 450, currency: "USD", percentage: 30 }, effort: "medium", priority: "high", actionRequired: "Resize instances from n1-standard-4 to n1-standard-2", implementationSteps: [ "Stop the affected instances during maintenance window", "Change machine type from n1-standard-4 to n1-standard-2", "Restart instances and monitor performance", "Validate application performance meets requirements", ], }, { type: "idle_resources", projectId: actualProjectId || "example-project-2", serviceId: "storage.googleapis.com", resourceName: "unused-disk-volumes", description: "Several persistent disks are not attached to any instances", potentialSavings: { amount: 125, currency: "USD", percentage: 100 }, effort: "low", priority: "medium", actionRequired: "Delete unattached persistent disks", implementationSteps: [ "Verify disks are not needed for backups or future use", "Create snapshots if data retention is required", "Delete unattached persistent disks", "Set up alerts to monitor for future unattached disks", ], }, ]; // Filter by minimum savings amount const filteredRecommendations = mockRecommendations.filter( (rec) => rec.potentialSavings.amount >= minSavingsAmount, ); // Filter by priority if specified const finalRecommendations = priority === "all" ? filteredRecommendations : filteredRecommendations.filter( (rec) => rec.priority === priority, ); let response = `# Cost Optimisation Recommendations\n\n`; response += `**Billing Account:** ${billingAccountName}\n`; response += `**Minimum Savings:** ${formatCurrency(minSavingsAmount)}\n`; response += `**Priority Filter:** ${priority}\n\n`; response += `⚠️ **Note:** This is a demonstration with mock recommendations. `; response += `For actual recommendations, integrate with Google Cloud Recommender API.\n\n`; response += formatCostRecommendations(finalRecommendations); if (finalRecommendations.length > 0) { const totalSavings = finalRecommendations.reduce( (sum, rec) => sum + rec.potentialSavings.amount, 0, ); response += `\n**Total Potential Savings:** ${formatCurrency(totalSavings)}\n`; } return { content: [ { type: "text", text: response, }, ], }; } catch (error: any) { logger.error(`Error generating cost recommendations: ${error.message}`); throw new GcpMcpError( `Failed to generate cost recommendations: ${error.message}`, error.code || "UNKNOWN", error.status || 500, ); } },
  • The input schema definition for the tool, using Zod schemas for validation of billingAccountName, optional projectId, minSavingsAmount, and priority parameters.
    { title: "Generate Cost Recommendations", description: "Generate cost optimisation recommendations with potential savings for Google Cloud billing", inputSchema: { billingAccountName: z .string() .describe( "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')", ), projectId: z .string() .optional() .describe("Optional project ID to filter recommendations"), minSavingsAmount: z .number() .min(0) .default(10) .describe("Minimum savings amount to include in recommendations"), priority: z .enum(["low", "medium", "high", "all"]) .default("all") .describe("Filter recommendations by priority level"), }, },
  • The server.registerTool call that registers the 'gcp-billing-cost-recommendations' tool with the MCP server, providing schema and handler.
    "gcp-billing-cost-recommendations", { title: "Generate Cost Recommendations", description: "Generate cost optimisation recommendations with potential savings for Google Cloud billing", inputSchema: { billingAccountName: z .string() .describe( "Billing account name (e.g., 'billingAccounts/123456-789ABC-DEF012')", ), projectId: z .string() .optional() .describe("Optional project ID to filter recommendations"), minSavingsAmount: z .number() .min(0) .default(10) .describe("Minimum savings amount to include in recommendations"), priority: z .enum(["low", "medium", "high", "all"]) .default("all") .describe("Filter recommendations by priority level"), }, }, async ({ billingAccountName, projectId, minSavingsAmount, priority }) => { try { // Use project hierarchy: provided -> state manager -> auth default const actualProjectId = projectId || stateManager.getCurrentProjectId() || (await getProjectId()); logger.debug( `Generating cost recommendations for billing account: ${billingAccountName}, project: ${actualProjectId || "all"}`, ); // Mock recommendations for demonstration const mockRecommendations: CostRecommendation[] = [ { type: "rightsizing", projectId: actualProjectId || "example-project-1", serviceId: "compute.googleapis.com", resourceName: "instance-group-1", description: "Compute Engine instances are underutilised and can be right-sized", potentialSavings: { amount: 450, currency: "USD", percentage: 30 }, effort: "medium", priority: "high", actionRequired: "Resize instances from n1-standard-4 to n1-standard-2", implementationSteps: [ "Stop the affected instances during maintenance window", "Change machine type from n1-standard-4 to n1-standard-2", "Restart instances and monitor performance", "Validate application performance meets requirements", ], }, { type: "idle_resources", projectId: actualProjectId || "example-project-2", serviceId: "storage.googleapis.com", resourceName: "unused-disk-volumes", description: "Several persistent disks are not attached to any instances", potentialSavings: { amount: 125, currency: "USD", percentage: 100 }, effort: "low", priority: "medium", actionRequired: "Delete unattached persistent disks", implementationSteps: [ "Verify disks are not needed for backups or future use", "Create snapshots if data retention is required", "Delete unattached persistent disks", "Set up alerts to monitor for future unattached disks", ], }, ]; // Filter by minimum savings amount const filteredRecommendations = mockRecommendations.filter( (rec) => rec.potentialSavings.amount >= minSavingsAmount, ); // Filter by priority if specified const finalRecommendations = priority === "all" ? filteredRecommendations : filteredRecommendations.filter( (rec) => rec.priority === priority, ); let response = `# Cost Optimisation Recommendations\n\n`; response += `**Billing Account:** ${billingAccountName}\n`; response += `**Minimum Savings:** ${formatCurrency(minSavingsAmount)}\n`; response += `**Priority Filter:** ${priority}\n\n`; response += `⚠️ **Note:** This is a demonstration with mock recommendations. `; response += `For actual recommendations, integrate with Google Cloud Recommender API.\n\n`; response += formatCostRecommendations(finalRecommendations); if (finalRecommendations.length > 0) { const totalSavings = finalRecommendations.reduce( (sum, rec) => sum + rec.potentialSavings.amount, 0, ); response += `\n**Total Potential Savings:** ${formatCurrency(totalSavings)}\n`; } return { content: [ { type: "text", text: response, }, ], }; } catch (error: any) { logger.error(`Error generating cost recommendations: ${error.message}`); throw new GcpMcpError( `Failed to generate cost recommendations: ${error.message}`, error.code || "UNKNOWN", error.status || 500, ); } }, );

Other Tools

Related 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