Azure APIM + MCP Server Demo
Exposes backend APIs through Azure API Management as an MCP server to enable AI assistants to interact with product catalogs and order systems. It provides standardized tools for searching products, retrieving details, and managing orders via the Model Context Protocol.
README
Azure APIM + MCP Server Demo
This project demonstrates how to expose backend APIs through Azure API Management (APIM) as a Model Context Protocol (MCP) Server, enabling AI assistants and tools to interact with your APIs using the standardized MCP protocol.
🏗️ Architecture
┌──────────────────┐ ┌─────────────────────────┐ ┌─────────────────────────┐
│ MCP Client │────▶│ Azure API Management │────▶│ Azure App Service │
│ (AI Assistant) │ │ (Gateway) │ │ (Express.js API) │
└──────────────────┘ └─────────────────────────┘ └─────────────────────────┘
│ │ │
│ MCP Protocol │ Subscription Key │ REST API
│ (JSON-RPC 2.0) │ Rate Limiting │ Products/Orders
│ │ Monitoring │
└─────────────────────────┴──────────────────────────────┘
📦 Components
Backend API (backend-api/)
- Express.js application with TypeScript
- REST API endpoints for products and orders
- MCP JSON-RPC endpoint handler
- 5 MCP tools:
get_products- List all products in the catalogget_product_by_id- Get product details by IDsearch_products- Search products by query stringget_orders- List all orderscreate_order- Create a new order
Infrastructure (infrastructure/)
- Bicep templates for Azure deployment
- Azure App Service (Linux, Node.js 20 LTS, B1 Basic)
- Azure API Management (Developer SKU)
- Application Insights for monitoring
- Log Analytics workspace
🌐 Endpoints
| Endpoint | Description |
|---|---|
https://apimmcp-api-dev.azurewebsites.net/ |
Backend root |
https://apimmcp-api-dev.azurewebsites.net/api/health |
Health check |
https://apimmcp-api-dev.azurewebsites.net/api/products |
Products REST API |
https://apimmcp-api-dev.azurewebsites.net/api/orders |
Orders REST API |
https://apimmcp-api-dev.azurewebsites.net/api/mcp |
MCP endpoint (direct) |
https://apimmcp-apim-dev.azure-api.net/mcp |
MCP endpoint (via APIM) ⭐ |
📡 MCP Protocol
The server implements the Model Context Protocol (version 2024-11-05):
Initialize
{
"jsonrpc": "2.0",
"method": "initialize",
"id": 1,
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": { "name": "client", "version": "1.0.0" }
}
}
List Tools
{
"jsonrpc": "2.0",
"method": "tools/list",
"id": 2
}
Call Tool
{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 3,
"params": {
"name": "get_products"
}
}
Example: Search Products
{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 4,
"params": {
"name": "search_products",
"arguments": { "query": "smart" }
}
}
Example: Create Order
{
"jsonrpc": "2.0",
"method": "tools/call",
"id": 5,
"params": {
"name": "create_order",
"arguments": { "productId": "prod-001", "quantity": 2 }
}
}
🚀 Deployment
Prerequisites
- Azure CLI installed and logged in
- Azure subscription
- Node.js 18+ installed locally
1. Create Resource Group
az group create --name apim-mcp-demo-rg --location eastus
2. Deploy Infrastructure
az deployment group create `
--resource-group apim-mcp-demo-rg `
--template-file ./infrastructure/main-appservice.bicep `
--parameters location=eastus namePrefix=apimmcp environment=dev apimPublisherEmail="your-email@example.com"
⚠️ Note: APIM provisioning takes 15-30 minutes on first deployment.
3. Build Backend API
cd backend-api
npm install
npm run build
4. Deploy Backend API
Compress-Archive -Path "dist\*", "package.json", "web.config", "node_modules" -DestinationPath "deploy.zip" -Force
az webapp deploy --resource-group apim-mcp-demo-rg --name apimmcp-api-dev --src-path deploy.zip --type zip
5. Get APIM Subscription Key
az rest --method post `
--uri "https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/apim-mcp-demo-rg/providers/Microsoft.ApiManagement/service/apimmcp-apim-dev/subscriptions/mcp-subscription/listSecrets?api-version=2022-08-01" `
--query "primaryKey" -o tsv
🧪 Testing
Run Test Script
.\test-mcp.ps1
Expected Output
========================================
MCP Server Test Suite
========================================
Endpoint: https://apimmcp-apim-dev.azure-api.net/mcp
1. Testing initialize...
Server: azure-product-catalog-server v1.0.0
Protocol: 2024-11-05
2. Testing tools/list...
Found 5 tools:
- get_products: Retrieve a list of all products in the catalog
- get_product_by_id: Get details of a specific product by its ID
...
3. Testing tools/call (get_products)...
Found 8 products:
- Widget Pro: $29.99
- Gadget Plus: $49.99
...
Manual Testing
$headers = @{
"Ocp-Apim-Subscription-Key" = "YOUR_SUBSCRIPTION_KEY"
"Content-Type" = "application/json"
}
$body = '{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}}}'
Invoke-RestMethod -Uri "https://apimmcp-apim-dev.azure-api.net/mcp" -Method POST -Headers $headers -Body $body
🛠️ Development
Local Development
cd backend-api
npm install
npm run dev
The server will start on http://localhost:3000.
Project Structure
APIM-MCP/
├── backend-api/
│ ├── src/
│ │ ├── index.ts # Express server entry
│ │ ├── routes.ts # REST API routes
│ │ ├── mcp.ts # MCP endpoint handler
│ │ └── data.ts # Mock data store
│ ├── dist/ # Compiled JavaScript
│ ├── package.json
│ ├── tsconfig.json
│ └── web.config # IIS configuration for Azure
├── infrastructure/
│ └── main-appservice.bicep # Azure resources
├── test-mcp.ps1 # Test script
└── README.md
🔧 Configuration
APIM Settings
- Subscription Required: Yes
- Rate Limiting: Configurable via APIM policies
- Authentication: Subscription key header (
Ocp-Apim-Subscription-Key)
App Service Settings
- SKU: B1 Basic (Linux)
- Node Version: 20 LTS
- Startup Command:
node index.js
📊 Monitoring
- Application Insights integrated with both App Service and APIM
- Access logs in Log Analytics workspace
- Health endpoint available at
/api/health
🔗 Resources
- Model Context Protocol Specification
- Azure API Management Documentation
- Azure App Service Documentation
📄 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 模型以安全和受控的方式获取实时的网络信息。