Skip to main content
Glama
msftnadavbh

Azure Pricing MCP Server

by msftnadavbh

azure_cost_estimate

Calculate Azure service costs by specifying service, SKU, region, and usage parameters to generate monthly expenditure estimates.

Instructions

Estimate Azure costs based on usage patterns

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
service_nameYesAzure service name
sku_nameYesSKU name
regionYesAzure region
hours_per_monthNoExpected hours of usage per month (default: 730 for full month)
currency_codeNoCurrency code (default: USD)USD
discount_percentageNoDiscount percentage to apply to prices (e.g., 10 for 10% discount). If not specified and show_with_discount is false, no discount is applied. If show_with_discount is true, defaults to 10%.
show_with_discountNoSet to true to apply a discount; uses default 10% unless discount_percentage is explicitly specified.

Implementation Reference

  • The main handler function that processes azure_cost_estimate tool calls. It resolves discount settings, calls the pricing service's estimate_costs method, attaches discount metadata, and formats the response.
    async def handle_cost_estimate(self, arguments: dict[str, Any]) -> list[TextContent]: """Handle azure_cost_estimate tool calls.""" discount_pct, discount_specified, used_default = self._resolve_discount(arguments) result = await self._pricing_service.estimate_costs(**arguments) self._attach_discount_metadata(result, discount_pct, discount_specified, used_default) response_text = format_cost_estimate_response(result) return [TextContent(type="text", text=response_text)]
  • The core business logic in PricingService.estimate_costs() that searches for prices, calculates hourly/daily/monthly/yearly costs, applies discounts if specified, and estimates savings plans pricing.
    async def estimate_costs( self, service_name: str, sku_name: str, region: str, hours_per_month: float = 730, currency_code: str = "USD", discount_percentage: float | None = None, ) -> dict[str, Any]: """Estimate monthly costs based on usage.""" result = await self.search_prices( service_name=service_name, sku_name=sku_name, region=region, currency_code=currency_code, limit=5, ) if not result["items"]: return { "error": f"No pricing found for {sku_name} in {region}", "service_name": service_name, "sku_name": sku_name, "region": region, } item = result["items"][0] hourly_rate = item.get("retailPrice", 0) original_hourly_rate = hourly_rate if discount_percentage is not None and discount_percentage > 0: hourly_rate = hourly_rate * (1 - discount_percentage / 100) monthly_cost = hourly_rate * hours_per_month daily_cost = hourly_rate * 24 yearly_cost = monthly_cost * 12 savings_plans = item.get("savingsPlan", []) savings_estimates = [] for plan in savings_plans: plan_hourly = plan.get("retailPrice", 0) original_plan_hourly = plan_hourly if discount_percentage is not None and discount_percentage > 0: plan_hourly = plan_hourly * (1 - discount_percentage / 100) plan_monthly = plan_hourly * hours_per_month plan_yearly = plan_monthly * 12 savings_percent = ((hourly_rate - plan_hourly) / hourly_rate) * 100 if hourly_rate > 0 else 0 plan_data: dict[str, Any] = { "term": plan.get("term"), "hourly_rate": round(plan_hourly, 6), "monthly_cost": round(plan_monthly, 2), "yearly_cost": round(plan_yearly, 2), "savings_percent": round(savings_percent, 2), "annual_savings": round((yearly_cost - plan_yearly), 2), } if discount_percentage is not None and discount_percentage > 0: plan_data["original_hourly_rate"] = original_plan_hourly plan_data["original_monthly_cost"] = round(original_plan_hourly * hours_per_month, 2) plan_data["original_yearly_cost"] = round(original_plan_hourly * hours_per_month * 12, 2) savings_estimates.append(plan_data) estimate_result: dict[str, Any] = { "service_name": service_name, "sku_name": item.get("skuName"), "region": region, "product_name": item.get("productName"), "unit_of_measure": item.get("unitOfMeasure"), "currency": currency_code, "on_demand_pricing": { "hourly_rate": round(hourly_rate, 6), "daily_cost": round(daily_cost, 2), "monthly_cost": round(monthly_cost, 2), "yearly_cost": round(yearly_cost, 2), }, "usage_assumptions": { "hours_per_month": hours_per_month, "hours_per_day": round(hours_per_month / 30.44, 2), }, "savings_plans": savings_estimates, } if discount_percentage is not None and discount_percentage > 0: estimate_result["discount_applied"] = { "percentage": discount_percentage, "note": "All prices shown are after discount", } estimate_result["on_demand_pricing"]["original_hourly_rate"] = original_hourly_rate estimate_result["on_demand_pricing"]["original_daily_cost"] = round(original_hourly_rate * 24, 2) estimate_result["on_demand_pricing"]["original_monthly_cost"] = round( original_hourly_rate * hours_per_month, 2 ) estimate_result["on_demand_pricing"]["original_yearly_cost"] = round( original_hourly_rate * hours_per_month * 12, 2 ) return estimate_result
  • Tool schema definition for azure_cost_estimate with input validation including required fields (service_name, sku_name, region) and optional parameters (hours_per_month, currency_code, discount_percentage, show_with_discount).
    Tool( name="azure_cost_estimate", description="Estimate Azure costs based on usage patterns", inputSchema={ "type": "object", "properties": { "service_name": { "type": "string", "description": "Azure service name", }, "sku_name": { "type": "string", "description": "SKU name", }, "region": { "type": "string", "description": "Azure region", }, "hours_per_month": { "type": "number", "description": "Expected hours of usage per month (default: 730 for full month)", "default": 730, }, "currency_code": { "type": "string", "description": "Currency code (default: USD)", "default": "USD", }, "discount_percentage": { "type": "number", "description": "Discount percentage to apply to prices (e.g., 10 for 10% discount). If not specified and show_with_discount is false, no discount is applied. If show_with_discount is true, defaults to 10%.", }, "show_with_discount": { "type": "boolean", "description": "Set to true to apply a discount; uses default 10% unless discount_percentage is explicitly specified.", "default": False, }, }, "required": ["service_name", "sku_name", "region"], }, ),
  • Server-side routing that maps the 'azure_cost_estimate' tool name to the handler's handle_cost_estimate method in the handle_call_tool function.
    elif name == "azure_cost_estimate": return await handlers.handle_cost_estimate(arguments)
  • Helper function that formats the cost estimate results into a human-readable text response, displaying usage assumptions, on-demand pricing, discount information, and savings plans options.
    def format_cost_estimate_response(result: dict[str, Any]) -> str: """Format the cost estimate response for display.""" if "error" in result: return f"Error: {result['error']}" estimate_text = f""" Cost Estimate for {result['service_name']} - {result['sku_name']} Region: {result['region']} Product: {result['product_name']} Unit: {result['unit_of_measure']} Currency: {result['currency']} """ if "discount_applied" in result: estimate_text += f"\nπŸ’° {result['discount_applied']['percentage']}% discount applied - {result['discount_applied']['note']}\n" estimate_text += f""" Usage Assumptions: - Hours per month: {result['usage_assumptions']['hours_per_month']} - Hours per day: {result['usage_assumptions']['hours_per_day']} On-Demand Pricing: - Hourly Rate: ${result['on_demand_pricing']['hourly_rate']} - Daily Cost: ${result['on_demand_pricing']['daily_cost']} - Monthly Cost: ${result['on_demand_pricing']['monthly_cost']} - Yearly Cost: ${result['on_demand_pricing']['yearly_cost']} """ if "discount_applied" in result and "original_hourly_rate" in result["on_demand_pricing"]: estimate_text += f""" Original Pricing (before discount): - Hourly Rate: ${result['on_demand_pricing']['original_hourly_rate']} - Daily Cost: ${result['on_demand_pricing']['original_daily_cost']} - Monthly Cost: ${result['on_demand_pricing']['original_monthly_cost']} - Yearly Cost: ${result['on_demand_pricing']['original_yearly_cost']} """ if result["savings_plans"]: estimate_text += "\nSavings Plans Available:\n" for plan in result["savings_plans"]: estimate_text += f""" {plan['term']} Term: - Hourly Rate: ${plan['hourly_rate']} - Monthly Cost: ${plan['monthly_cost']} - Yearly Cost: ${plan['yearly_cost']} - Savings: {plan['savings_percent']}% (${plan['annual_savings']} annually) """ if "original_hourly_rate" in plan: estimate_text += f"""- Original Hourly Rate: ${plan['original_hourly_rate']} - Original Monthly Cost: ${plan['original_monthly_cost']} - Original Yearly Cost: ${plan['original_yearly_cost']} """ return estimate_text

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/msftnadavbh/AzurePricingMCP'

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