Stateless MCP Server on Azure App Service
Enables a stateless, horizontally scaled MCP server using the 2026-07-28 specification, with tools for load testing and instance-aware operations.
README
Stateless MCP Server on Azure App Service — 2026-07-28 edition
A reference implementation of a stateless, horizontally scaled MCP server
built on the MCP 2026-07-28 specification and deployed behind Azure App
Service's built-in load balancer.
The 2026-07-28 revision makes MCP stateless at the protocol level: it removes
the initialize handshake and the Mcp-Session-Id header, so any instance can
serve any request with no prior context. That is a perfect match for App
Service's built-in load balancer — scale out and every instance is
interchangeable.
Part 2. This is the sequel to You can scale MCP servers behind a load balancer on App Service — here's how, which scaled a
2025-11-25server. The original sample lives at app-service-mcp-stateless-scale-python. This repo is the standalone2026-07-28version.
- Stateless Streamable HTTP (MCP
2026-07-28) — no handshake, no session - Three App Service instances by default, no sticky sessions
- Explicit-handle tool (
tally) — the stateless replacement for session state - Spec-compliant Python client that exercises the new headers +
_meta - Staging deployment slot for zero-downtime updates
- Application Insights auto-instrumentation with per-instance request tagging
- k6 load test that visualizes load distribution
What changed from 2025-11-25
| Area | 2025-11-25 |
2026-07-28 (this sample) |
|---|---|---|
| Handshake | initialize + notifications/initialized |
Removed — every request self-describes via _meta (SEP-2575) |
| Sessions | Mcp-Session-Id header pins a client to state |
Removed — explicit server-minted handles as tool args (SEP-2567) |
| Discovery | implied by initialize result |
server/discover RPC, required (SEP-2575) |
| Headers | none required | Mcp-Method + Mcp-Name required on POST (SEP-2243) |
| List results | plain | ttlMs + cacheScope cache hints (SEP-2549) |
| Results | plain | resultType: "complete" on every result (SEP-2322) |
| Tracing | ad hoc | W3C Trace Context in _meta (SEP-414) |
| Tool schema | subset | full JSON Schema 2020-12 (SEP-2106) |
| Resource-not-found | -32002 |
-32602 (Invalid Params) |
Full changelog: https://modelcontextprotocol.io/specification/draft/changelog
What's in the box
.
├── main.py # FastAPI app — MCP 2026-07-28 over stateless HTTP
├── requirements.txt
├── azure.yaml # azd service definition
├── client/
│ └── mcp_client.py # spec-compliant 2026-07-28 client (headers + _meta + handles)
├── infra/
│ ├── main.bicep # Resource group scope
│ ├── main.parameters.json
│ ├── abbreviations.json
│ ├── app/
│ │ └── web.bicep # App Service + staging slot
│ └── shared/
│ ├── app-service-plan.bicep
│ └── monitoring.bicep # Log Analytics + App Insights
├── loadtest/
│ ├── k6-mcp.js # k6 script — tags hits per instance
│ └── README.md
├── static/style.css
└── templates/index.html # Status page showing serving instance
MCP tools
| Tool | Purpose |
|---|---|
whoami |
Returns the App Service instance ID handling the request |
echo |
Echoes a message, tagged with the instance ID |
lookup_fact |
Static read-only fact lookup (stateless) |
compute_primes |
CPU-bound prime counter (useful for load testing each instance's CPU) |
tally |
Running total via an explicit signed handle — stateless cross-call state |
Why tally matters
In 2025-11-25, a tool that needed to remember something across calls leaned on
the session. The 2026-07-28 spec removes sessions, so this server mints an
explicit handle instead: tally returns a signed token that contains the
running total. Pass it back on the next call and the total accumulates — even
though the load balancer may route each call to a different instance. State
travels with the request, not the connection. (For real workloads you'd back
handles with a shared store like Azure Storage, Cosmos DB, or Redis; here the
handle is self-contained so the sample needs zero extra infrastructure.)
Local development
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
python main.py
Open http://localhost:8000/. The MCP endpoint is at
http://localhost:8000/mcp.
Try the bundled client
python client/mcp_client.py # against localhost
python client/mcp_client.py https://<your-app>.azurewebsites.net
It runs server/discover, lists tools (showing the cache hints), calls
whoami a few times so you can watch the instance ID move, then drives the
tally handle across calls — all with the required 2026-07-28 headers and
_meta.
Strict header mode
By default the server is lenient about the new Mcp-Method / Mcp-Name headers
so that not-yet-2026-07-28 clients still work. To enforce them (return
-32020 HeaderMismatch when they're missing or wrong), set:
MCP_STRICT_HEADERS=1 python main.py
The bundled client and load test always send them.
Deploy to Azure
azd auth login
azd up
azd up provisions:
- A Premium v3 (P0v3) Linux App Service Plan with
capacity: 3— three live instances behind App Service's built-in load balancer. - The Web App, with
clientAffinityEnabled: false— no ARR Affinity cookie, so the load balancer is free to round-robin every request. - A
stagingdeployment slot wired to the same plan for zero-downtime swaps. - A Log Analytics workspace + Application Insights resource, connected via
APPLICATIONINSIGHTS_CONNECTION_STRINGso the OpenTelemetry distro emits traces tagged withcloud_RoleInstance = WEBSITE_INSTANCE_ID.
Tune the scale-out level
azd env set INSTANCE_COUNT 5
azd provision
(The instanceCount bicep parameter accepts 1–10, wired through
infra/main.parameters.json.)
Connect VS Code to the deployed server
Update .vscode/mcp.json:
{
"servers": {
"stateless-mcp-app-service-2026": {
"url": "https://<your-app>.azurewebsites.net/mcp",
"type": "http"
}
}
}
Verify load distribution
-
Hit the home page a few times — the Instance ID value should change.
-
Run the bundled client or the k6 load test:
BASE_URL=https://<your-app>.azurewebsites.net k6 run loadtest/k6-mcp.js -
Inspect Application Insights:
requests | where timestamp > ago(15m) | where name contains "/mcp" | summarize count() by cloud_RoleInstance
Architecture
┌─────────────────────────────────────────┐
│ Azure App Service (P0v3 × 3) │
│ ┌────────────┐ ┌────────────┐ ┌──────┐ │
MCP client ── HTTP ─┤ ▶ instance0 │ │ instance1 │ │ … │ │
(stateless, │ └────────────┘ └────────────┘ └──────┘ │
no session, │ ▲ built-in load balancer ▲ │
no cookies) │ │ clientAffinityEnabled=false │
│ ┌──┴────────────────────────────────┐ │
│ │ Staging slot (same plan) │ │
│ └───────────────────────────────────┘ │
└────────────────────┬────────────────────┘
▼
Application Insights
(cloud_RoleInstance =
WEBSITE_INSTANCE_ID)
License
MIT.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。