Skip to main content
Glama
azure-pricing-mcp

azure-pricing-mcp

by amritsc
README.md
# mcp-azure-pricing-server

An [MCP](https://modelcontextprotocol.io) server that lets an AI agent answer Azure pricing questions
correctly: "Where is a D4s v5 cheapest?", "What do six of these cost per month on a 3-year savings
plan?" It wraps the public [Azure Retail Prices API](https://learn.microsoft.com/rest/api/cost-management/retail-prices/azure-retail-prices),
which needs no auth, and runs over **stdio** for local clients or **Streamable HTTP** for remote ones such as
Copilot Studio and Microsoft 365 Copilot agents.

[![CI](https://github.com/amritsc/mcp-azure-pricing-server/actions/workflows/ci.yml/badge.svg)](https://github.com/amritsc/mcp-azure-pricing-server/actions/workflows/ci.yml)

## Why this exists

Pricing is one of the first things people ask a cloud agent, and the raw API is easy to get wrong.
One VM size in one region returns around eleven rows (Spot, Low Priority, DevTest, Windows,
reservations), and reservation prices are totals for the whole term even though the unit reads
"1 Hour". If a model reads those rows itself, it will confidently quote a Spot price as the normal
rate, or a 1-year reservation as an hourly price.

This server puts those rules in code and gives the model four narrow tools. It's also a worked example of
MCP tool design: schemas that fail safely, structured output, and caching and rate limiting for a public
upstream. The reasoning is in [docs/TOOL-DESIGN.md](docs/TOOL-DESIGN.md).

## Tools

| Tool | What it does |
| --- | --- |
| `list_skus` | Lists the SKUs a service offers in a region, so the model can find exact names before pricing |
| `compare_regions` | Gives the pay-as-you-go price of one VM size across 2–15 regions, cheapest first, with % deltas and the regions where it isn't offered |
| `estimate_monthly_cost` | Prices up to 25 VM line items under pay-as-you-go, savings plans (1y/3y) or reservations (1y/3y), with warnings for anything it couldn't price |
| `search_prices` | Returns raw price rows for anything else (storage, databases), compacted and capped |

All tools return structured content (JSON Schema-typed output) and are annotated read-only.

## Architecture

```mermaid
flowchart LR
    subgraph Clients
        A[Claude / VS Code<br/>stdio]
        B[Copilot Studio /<br/>M365 Copilot agent<br/>Streamable HTTP]
    end
    subgraph Server["azure-pricing-mcp"]
        T[Tool layer<br/>schemas + validation]
        C[Catalog rules<br/>row selection, amortization]
        Q[OData builder<br/>allowlist + escaping]
        P[PricingClient<br/>TTL cache · token bucket · retries · paging]
    end
    API[(prices.azure.com<br/>Retail Prices API)]
    S[(Sample catalog<br/>--offline)]
    A --> T
    B --> T
    T --> C --> P
    T --> Q --> P
    P --> API
    P -.-> S
```

## Quickstart

You need Python 3.11+ and [uv](https://docs.astral.sh/uv/).

```bash
git clone https://github.com/amritsc/mcp-azure-pricing-server
cd mcp-azure-pricing-server
uv sync

# Exercise every tool end to end over stdio, using the bundled sample catalog (no network)
uv run python examples/test_client.py --offline

# Same thing against live Azure prices
uv run python examples/test_client.py

# Run the test suite
uv run pytest
```

`--offline` serves a synthetic catalog generated by `scripts/make_sample_data.py`. It has the same row
shapes as the real API, but the prices are made up. The server logs a warning in this mode and tells
the model that the numbers aren't real.

### Use it from a client

**Claude Desktop** (`claude_desktop_config.json`) or any stdio client:

```json
{
  "mcpServers": {
    "azure-pricing": {
      "command": "uv",
      "args": ["--directory", "/path/to/mcp-azure-pricing-server", "run", "azure-pricing-mcp"]
    }
  }
}
```

**VS Code** (`.vscode/mcp.json`):

```json
{
  "servers": {
    "azure-pricing": {
      "type": "stdio",
      "command": "uv",
      "args": ["--directory", "${workspaceFolder}", "run", "azure-pricing-mcp"]
    }
  }
}
```

**Remote (Copilot Studio, Microsoft 365 Copilot agents, anything that needs a URL):**

```bash
uv run azure-pricing-mcp --transport http --port 8000     # endpoint: http://127.0.0.1:8000/mcp
curl localhost:8000/healthz
```

To deploy, build the `Dockerfile` and run it anywhere that serves containers, e.g. Azure Container Apps.
Then pass your public hostname with `--allowed-host` or `ALLOWED_HOSTS` so DNS-rebinding protection
accepts it. To use the server as a declarative agent action, see
[copilot-agent-authoring-paths](https://github.com/amritsc/copilot-agent-authoring-paths), which ships an
agent package pointing at it.

## Tradeoffs

- **Narrow tools over a generic query tool.** A single `query(filter)` tool would cover more ground,
  but it would make every model rediscover the row-selection traps, and it would invite OData
  injection. The narrow tools cover the common questions. `search_prices` is the escape hatch, with
  guardrails.
- **API version `2023-01-01-preview`.** It's the only version that returns savings plan rates. The
  cost is case-sensitive filter values, so empty results come back with a hint that says so.
- **Commitment pricing is Linux-only.** Savings plans and reservations discount compute, not the
  Windows license, so a compute-only Windows number would be misleadingly low. The tools decline
  and say why, instead of guessing at license costs.
- **730 hours a month.** This matches the Azure pricing calculator. Reservations always bill all 730,
  and the estimator enforces that.
- **Client-side rate limiting.** The API publishes no limit but does throttle bursts. A token bucket
  (5 req/s, burst 10) smooths fan-out from `compare_regions`. Retries back off and honor `Retry-After`.
- **One hour of caching.** Retail prices change a few times a month, so the cache trades a tiny
  staleness window for much less upstream traffic. The cache is in memory and per replica, which
  keeps the deployment stateless.
- **Stateless HTTP.** No sessions, so any replica can serve any request. Nothing in these tools
  needs per-session state.
- **Synthetic offline data, plus a weekly live job.** Tests stay deterministic and network-free. The
  scheduled `live` CI job checks the real API weekly so drift in its shape gets caught. It reports
  without blocking merges, because the upstream is out of our hands.

## Limitations

The server covers retail list prices only, with no EA, MCA or CSP discounts. Estimates cover compute
only (no disks, bandwidth or support). Non-USD prices are Microsoft's reference conversions.

## License

MIT

TDQS

A3.8/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a distinct scope: raw price lookup, SKU discovery, regional VM comparison, and VM cost estimation. The descriptions explicitly position search_prices as the fallback for cases the more specific tools do not cover, reducing overlap confusion.

Naming Consistency5/5

All four names use a consistent snake_case verb_noun pattern: search_prices, list_skus, compare_regions, estimate_monthly_cost. The convention is predictable and readable throughout.

Tool Count5/5

Four tools is well-scoped for an Azure pricing server: one broad search, one SKU lister, and two higher-level cost comparison/estimation tools. Each tool earns its place without redundancy.

Completeness4/5

The core pricing workflow is covered: discover SKUs, search raw prices, compare VM costs across regions, and estimate VM monthly cost. Non-VM monthly cost aggregation and richer pricing models are not directly supported, though search_prices provides a raw fallback.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues