Azure Diagram MCP Server

Azure Diagram MCP Server

A remotely-hosted MCP server that generates Azure architecture diagrams from agent-generated topology descriptions, with safe execution and consistent styling.

Category
访问服务器

README

Azure Diagram MCP Server

A remotely-hosted Model Context Protocol (MCP) server that turns agent-written architecture descriptions into Azure diagrams. Agents describe topology (services, groups, connections); the server owns layout and styling so output stays consistent across models and prompts.

Built for Streamable HTTP so any MCP client (Cursor, VS Code, Copilot, custom agents) can connect over the network. Diagrams are returned inline as PNG and can be persisted to Azure Blob Storage with a shareable SAS URL.

Features

  • MCP tools for diagram generation, Azure node discovery, and worked examples
  • Server-side style profiles — Graphviz layout, fonts, cluster boxes, and connector colors are injected at render time; agents do not hard-code graph_attr or colors
  • Safe execution of agent-supplied Python via AST validation, process isolation, restricted builtins, and a render timeout
  • CAF-aligned visual language — default caf-default profile matches Microsoft reference-architecture styling (grey cluster boxes, dashed private paths, dotted observability links)
  • Optional Blob persistence — inline PNG always returned; shareable URL when storage is configured
  • Docker-ready — single image with Graphviz, Cairo, and Node.js (for optional Azure best-practice validation)
  • Azure Container Apps deployment — Bicep + Azure Developer CLI (azd) template included

How it works

flowchart LR
  Agent["MCP client / LLM"] -->|"POST /mcp"| Server["FastMCP server"]
  Server --> Validate["AST safety check"]
  Validate --> Style["Inject style profile"]
  Style --> Render["Graphviz → PNG"]
  Render --> Inline["Inline PNG response"]
  Render --> Blob["Azure Blob (optional)"]
  1. The agent calls list_azure_components and get_diagram_example to learn valid diagrams.azure.* imports.
  2. The agent writes topology-only Python using the diagrams DSL and calls generate_diagram.
  3. The server validates the code, injects the active style profile, renders in an isolated subprocess, and returns the PNG.

Note: A second pipeline for declarative YAML/JSON reference architectures (generate_reference_diagram) exists in the codebase but is currently disabled in the MCP server. All diagram generation today goes through generate_diagram.

MCP tools

Tool Description
generate_diagram(code, filename?, title?, style_profile?) Render diagrams DSL to PNG. Style/layout come from style_profile (default caf-default).
list_azure_components(category?) List importable diagrams.azure.* node classes (compute, network, database, …).
get_diagram_example() Return a minimal worked DSL example (topology only, no styling).
list_style_profiles() List bundled layout/style presets and the default profile name.

Authoring diagrams (for agents)

Do: describe nodes, Cluster groupings, and connections.

Do not: set graph_attr, direction, show, filename, or arbitrary edge colors — the server applies those from the style profile.

from diagrams import Diagram, Cluster, Edge
from diagrams.azure.network import ApplicationGateway
from diagrams.azure.web import AppServices
from diagrams.azure.security import KeyVaults
from diagrams.azure.database import SQLDatabases

with Diagram("Azure Web App"):
    agw = ApplicationGateway("App Gateway")

    with Cluster("Application"):
        app = AppServices("App Service")

    kv = KeyVaults("Key Vault")
    db = SQLDatabases("SQL Database")

    agw >> Edge(label="HTTPS") >> app
    app >> kv
    app >> Edge(style="dashed") >> db   # dashed = indirect / private path

Connector semantics (colors come from the profile):

Edge(...) Meaning
plain >> Solid data-flow connector
Edge(style="dashed") Indirect, egress, or private path
Edge(style="dotted") Observability, identity, or governance
Edge(label="HTTPS") Label only — no custom colors needed

Style profiles

Profiles live under src/azure_diagram_mcp/assets/style/. The default caf-default profile defines:

  • Top-to-bottom layout (direction: TB), spline routing, spacing
  • Light grey dashed cluster boxes (VNet / subscription groupings)
  • CAF connector palette (solid / dashed / dotted)

To tune diagram appearance globally, edit caf-default.yaml under the diagrams_dsl section — no agent prompt changes required.

# excerpt from assets/style/caf-default.yaml
diagrams_dsl:
  direction: TB
  graph_attr:
    fontsize: "22"
    bgcolor: white
    splines: spline
  connectors:
    solid:  { style: solid,  color: "#323130" }
    dashed: { style: dashed, color: "#605E5C" }
    dotted: { style: dotted, color: "#A19F9D" }

Pass a different profile to generate_diagram(..., style_profile="caf-default").

Security

Executing agent-supplied Python is the primary risk. Mitigations:

Layer What it does
AST allowlist (validation.py) Only diagrams imports permitted; dangerous builtins and dunder escapes rejected
Process isolation (renderer.py) Code runs in a separate process with open / eval / exec stripped from builtins
Timeout Wall-clock limit on each render (default 30 s)
Style injection Server overrides layout kwargs — agents cannot control filenames or open arbitrary files via Diagram

For production, also restrict Container Apps ingress (authentication, IP allow lists).

Quick start

Prerequisites

  • Python 3.12+
  • Graphviz (dot on PATH)
    • Windows: winget install graphviz
    • macOS: brew install graphviz
    • Linux: apt-get install graphviz

Run locally (Python)

python -m venv .venv
# Windows:  .venv\Scripts\activate
# macOS/Linux:  source .venv/bin/activate

pip install -e .
python -m azure_diagram_mcp.server

Server endpoints:

URL Purpose
http://localhost:8000/mcp MCP Streamable HTTP transport
http://localhost:8000/health Liveness probe ({"status":"ok","version":"0.1.0"})

Run locally (Docker)

docker build -t azure-diagram-mcp:local .
docker run -d --name azure-diagram-mcp-local -p 8000:8000 --restart unless-stopped azure-diagram-mcp:local

Rebuild and redeploy after code changes:

docker build -t azure-diagram-mcp:local .
docker rm -f azure-diagram-mcp-local
docker run -d --name azure-diagram-mcp-local -p 8000:8000 --restart unless-stopped azure-diagram-mcp:local

Connect an MCP client

Point your client at the /mcp URL. Example for Cursor / VS Code (.cursor/mcp.json or .vscode/mcp.json):

{
  "mcpServers": {
    "azure-diagram": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

For a deployed Container App, replace the host with your app FQDN: https://<fqdn>/mcp.

Optional: Blob persistence

Without storage, diagrams are returned inline only. For shareable URLs locally:

# Windows PowerShell
$env:AZURE_STORAGE_CONNECTION_STRING = "<connection-string>"
$env:BLOB_CONTAINER = "diagrams"

In Azure (Container Apps deployment), the app uses managed identity and user-delegation SAS — no connection string required.

Deploy to Azure Container Apps

Prerequisites: Azure Developer CLI, Docker, Azure subscription.

azd auth login
azd up          # first-time: provision infra + deploy
azd deploy      # subsequent code/image updates
azd down        # tear down

azd up provisions (via infra/):

  • Log Analytics + Container Apps environment
  • Azure Container Registry
  • User-assigned managed identity (ACR pull + Storage Blob Data Contributor)
  • Storage account + diagrams container
  • Container App with external ingress on port 8000

When complete, azd prints SERVICE_MCP_ENDPOINT_URL. Your MCP endpoint is that URL + /mcp.

Variable Purpose
STORAGE_ACCOUNT_URL Blob endpoint (managed identity)
BLOB_CONTAINER Container name (diagrams)
AZURE_CLIENT_ID User-assigned identity client ID
PORT Listen port (8000)

Project layout

src/azure_diagram_mcp/
  server.py           # FastMCP app, MCP tools, /health
  renderer.py         # Isolated subprocess render + style injection
  dsl_style.py        # Style profile loader for diagrams DSL
  validation.py       # AST safety allowlist
  catalog.py          # diagrams.azure.* node discovery
  storage.py          # Blob upload + SAS URLs
  assets/
    style/            # Style profiles (caf-default.yaml, …)
    icon_map.yaml     # Service metadata (reference pipeline)
  renderers/          # CAF layout engine (reference pipeline, currently disabled)
examples/             # Sample reference-architecture YAML
infra/                # Bicep (Container Apps, ACR, Storage, identity)
Dockerfile
azure.yaml            # azd service definition

Environment variables

Variable Default Description
PORT 8000 HTTP listen port
HOST 0.0.0.0 Bind address
LOG_LEVEL INFO Python log level
AZURE_STORAGE_CONNECTION_STRING Local/dev Blob storage
STORAGE_ACCOUNT_URL Blob endpoint (Azure managed identity)
BLOB_CONTAINER diagrams Blob container name
AZURE_CLIENT_ID Managed identity client ID
DISABLE_AZURE_MCP Set to 1 to skip external best-practice calls

License

MIT — see LICENSE.

Acknowledgements

Inspired by David Minkovski's Stop Drawing, Start Prompting and his stdio azure-diagram-mcp. This project adapts the idea for remote Streamable HTTP hosting, server-side style profiles, and durable Blob storage.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选