azure_price_compare
Compare Azure service pricing across regions or SKUs to identify cost differences and optimize cloud spending.
Instructions
Compare Azure prices across regions or SKUs
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| service_name | Yes | Azure service name to compare | |
| sku_name | No | Specific SKU to compare (optional) | |
| regions | No | List of regions to compare (if not provided, compares SKUs) | |
| currency_code | No | Currency code (default: USD) | USD |
| discount_percentage | No | 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 | No | Set to true to apply a discount; uses default 10% unless discount_percentage is explicitly specified. |
Implementation Reference
- The handler function that executes the azure_price_compare tool. It resolves discount settings, calls the pricing service's compare_prices method, attaches discount metadata, and formats the response.async def handle_price_compare(self, arguments: dict[str, Any]) -> list[TextContent]: """Handle azure_price_compare tool calls.""" discount_pct, discount_specified, used_default = self._resolve_discount(arguments) result = await self._pricing_service.compare_prices(**arguments) self._attach_discount_metadata(result, discount_pct, discount_specified, used_default) response_text = format_price_compare_response(result) return [TextContent(type="text", text=response_text)]
- Core implementation of the compare_prices logic in PricingService. Supports comparing prices across regions (when regions list is provided) or across SKUs (when no regions specified). Applies discounts, sorts results by price, and returns comparison data.async def compare_prices( self, service_name: str, sku_name: str | None = None, regions: list[str] | None = None, currency_code: str = "USD", discount_percentage: float | None = None, ) -> dict[str, Any]: """Compare prices across different regions or SKUs.""" comparisons = [] if regions and isinstance(regions, list): for region in regions: try: result = await self.search_prices( service_name=service_name, sku_name=sku_name, region=region, currency_code=currency_code, limit=10, ) if result["items"]: item = result["items"][0] comparisons.append( { "region": region, "sku_name": item.get("skuName"), "retail_price": item.get("retailPrice"), "unit_of_measure": item.get("unitOfMeasure"), "product_name": item.get("productName"), "meter_name": item.get("meterName"), } ) except Exception as e: logger.warning(f"Failed to get prices for region {region}: {e}") else: result = await self.search_prices( service_name=service_name, currency_code=currency_code, limit=20, ) sku_prices: dict[str, dict[str, Any]] = {} items = result.get("items", []) for item in items: sku = item.get("skuName") if sku and sku not in sku_prices: sku_prices[sku] = { "sku_name": sku, "retail_price": item.get("retailPrice"), "unit_of_measure": item.get("unitOfMeasure"), "product_name": item.get("productName"), "region": item.get("armRegionName"), "meter_name": item.get("meterName"), } comparisons = list(sku_prices.values()) if discount_percentage is not None and discount_percentage > 0: for comparison in comparisons: if "retail_price" in comparison and comparison["retail_price"]: original_price = comparison["retail_price"] discounted_price = original_price * (1 - discount_percentage / 100) comparison["retail_price"] = round(discounted_price, 6) comparison["original_price"] = original_price comparisons.sort(key=lambda x: x.get("retail_price", 0)) result_data: dict[str, Any] = { "comparisons": comparisons, "service_name": service_name, "currency": currency_code, "comparison_type": "regions" if regions else "skus", } if discount_percentage is not None and discount_percentage > 0: result_data["discount_applied"] = { "percentage": discount_percentage, "note": "Prices shown are after discount", } return result_data
- src/azure_pricing_mcp/tools.py:62-98 (schema)Tool definition and input schema for azure_price_compare. Defines parameters: service_name (required), sku_name (optional), regions (optional array), currency_code, discount_percentage, and show_with_discount flags.Tool( name="azure_price_compare", description="Compare Azure prices across regions or SKUs", inputSchema={ "type": "object", "properties": { "service_name": { "type": "string", "description": "Azure service name to compare", }, "sku_name": { "type": "string", "description": "Specific SKU to compare (optional)", }, "regions": { "type": "array", "items": {"type": "string"}, "description": "List of regions to compare (if not provided, compares SKUs)", }, "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"], }, ),
- Response formatter for price comparison results. Adds service name header, discount notification if applicable, and returns the comparisons as formatted JSON.def format_price_compare_response(result: dict[str, Any]) -> str: """Format the price comparison response for display.""" response_text = f"Price comparison for {result['service_name']}:\n\n" if "discount_applied" in result: response_text += f"π° {result['discount_applied']['percentage']}% discount applied - {result['discount_applied']['note']}\n\n" response_text += json.dumps(result["comparisons"], indent=2) return response_text
- src/azure_pricing_mcp/server.py:109-110 (registration)Tool registration in the MCP server's call_tool handler. Routes azure_price_compare calls to the handle_price_compare method in tool_handlers.elif name == "azure_price_compare": return await handlers.handle_price_compare(arguments)