/ 目錄 / 演練場 / Azure Data API Builder (MCP)
● 官方 Azure 🔑 需要你的金鑰

Azure Data API Builder (MCP)

作者 Azure · Azure/data-api-builder

Microsoft 官方的開源工具,讓 Azure SQL、Cosmos DB、Postgres 或 MySQL 透過一個設定檔——無需寫程式——即可成為 REST + GraphQL + MCP 端點。

Data API Builder(DAB)是 Azure 官方支援的方案,讓關聯式或 NoSQL 資料庫對外提供標準協議,包含 MCP。你只需撰寫一個列出實體、關聯與策略的 JSON 設定檔;DAB 會啟動一個處理程序,將其公開為 REST、GraphQL 與(自 2026 年起的)MCP 工具。支援 Azure SQL、SQL Server、Cosmos DB(NoSQL + PostgreSQL)、Postgres、MySQL 及 Azure Data Lake。透過 Static Web Apps、Easy Auth 或 JWT 進行驗證。

為什麼要用

核心特性

即時演示

實際使用效果

azure-data-api-builder-mcp.replay ▶ 就緒
0/0

安裝

選擇你的客戶端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "azure-data-api-builder-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-v",
        "${PWD}/dab-config.json:/App/dab-config.json:ro",
        "-e",
        "DAB_ENVIRONMENT=Production",
        "mcr.microsoft.com/azure-databases/data-api-builder:latest",
        "--ConfigFileName",
        "/App/dab-config.json"
      ]
    }
  }
}

開啟 Claude Desktop → Settings → Developer → Edit Config。儲存後重啟應用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "azure-data-api-builder-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-v",
        "${PWD}/dab-config.json:/App/dab-config.json:ro",
        "-e",
        "DAB_ENVIRONMENT=Production",
        "mcr.microsoft.com/azure-databases/data-api-builder:latest",
        "--ConfigFileName",
        "/App/dab-config.json"
      ]
    }
  }
}

Cursor 使用與 Claude Desktop 相同的 mcpServers 格式。專案級設定優先於全域。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "azure-data-api-builder-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-v",
        "${PWD}/dab-config.json:/App/dab-config.json:ro",
        "-e",
        "DAB_ENVIRONMENT=Production",
        "mcr.microsoft.com/azure-databases/data-api-builder:latest",
        "--ConfigFileName",
        "/App/dab-config.json"
      ]
    }
  }
}

點擊 Cline 側欄中的 MCP Servers 圖示,然後選 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "azure-data-api-builder-mcp": {
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-v",
        "${PWD}/dab-config.json:/App/dab-config.json:ro",
        "-e",
        "DAB_ENVIRONMENT=Production",
        "mcr.microsoft.com/azure-databases/data-api-builder:latest",
        "--ConfigFileName",
        "/App/dab-config.json"
      ]
    }
  }
}

格式與 Claude Desktop 相同。重啟 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "azure-data-api-builder-mcp",
      "command": "docker",
      "args": [
        "run",
        "--rm",
        "-i",
        "-v",
        "${PWD}/dab-config.json:/App/dab-config.json:ro",
        "-e",
        "DAB_ENVIRONMENT=Production",
        "mcr.microsoft.com/azure-databases/data-api-builder:latest",
        "--ConfigFileName",
        "/App/dab-config.json"
      ]
    }
  ]
}

Continue 使用伺服器物件陣列,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "azure-data-api-builder-mcp": {
      "command": {
        "path": "docker",
        "args": [
          "run",
          "--rm",
          "-i",
          "-v",
          "${PWD}/dab-config.json:/App/dab-config.json:ro",
          "-e",
          "DAB_ENVIRONMENT=Production",
          "mcr.microsoft.com/azure-databases/data-api-builder:latest",
          "--ConfigFileName",
          "/App/dab-config.json"
        ]
      }
    }
  }
}

加入 context_servers。Zed 儲存後熱重載。

claude mcp add azure-data-api-builder-mcp -- docker run --rm -i -v ${PWD}/dab-config.json:/App/dab-config.json:ro -e DAB_ENVIRONMENT=Production mcr.microsoft.com/azure-databases/data-api-builder:latest --ConfigFileName /App/dab-config.json

一行命令搞定。用 claude mcp list 驗證,claude mcp remove 移除。

使用場景

實戰用法: Azure Data API Builder (MCP)

以角色存取控制將 Azure SQL 資料庫公開給 Claude

👤 Azure 生態系的團隊;需要查詢而非傾印資料的分析師 ⏱ ~30 min intermediate

何時使用: 你有一個內部 Azure SQL DB,並希望 AI Agent 以嚴格的每資料表權限讀取,而非以 god-mode 管理員身份存取。

前置條件
  • Azure SQL 連線字串 — 從 Azure 入口網站 → SQL DB → 連線字串
  • 已安裝 Docker — Docker Desktop 或任何 OCI 執行環境
步驟
  1. 生成 dab-config.json
    Create a DAB config that exposes the Customers and Orders tables read-only over MCP. Connect to my Azure SQL via env var DAB_CONN.✓ 已複製
    → dab-config.json 已寫入,含兩個實體且 actions: ["read"]
  2. 本地執行
    Spin up DAB locally via Docker on port 5000 and verify the MCP endpoint responds.✓ 已複製
    → GET /api/Customers 返回資料列;MCP 工具清單顯示實體
  3. 連接 Claude
    Add the local DAB MCP to my Claude config and ask: 'Top 10 customers by orders in 2026.'✓ 已複製
    → Claude 透過組合讀取呼叫返回結果

結果: Claude 能在嚴格設定的邊界內查詢資料庫,而非直接執行 SQL。

注意事項
  • Azure SQL 防火牆封鎖了本地 Docker 的 IP — 在 Azure 入口網站 → SQL Server → 網路中允許你的 IP,或在 Azure 內部執行 DAB

在 Cosmos DB NoSQL 前加上 GraphQL + MCP 層

👤 已使用 Cosmos 且想讓 LLM 存取而無需自建 API 的團隊 ⏱ ~40 min advanced

何時使用: 你有一個 Cosmos NoSQL 容器,需要 Claude 以欄位層級策略進行讀寫存取。

前置條件
  • Cosmos DB 帳號與容器 — 從 Azure 入口網站——記下連線字串及資料庫/容器名稱
步驟
  1. 設定實體
    Add an entity for Cosmos container products with a JSON schema mapped from the actual docs. Allow read+update; require role 'editor' for updates.✓ 已複製
    → 更新後的 dab-config.json 含 permissions 區塊
  2. 設定 Easy Auth
    Add a JWT auth provider config with the issuer of my Entra tenant.✓ 已複製
    → 已新增驗證區塊;DAB 強制執行
  3. 驗證策略
    Try a write as anonymous (should fail), then with editor token (should succeed).✓ 已複製
    → 先 401 後 200——證明策略已生效

結果: 為 Claude 提供安全的 Cosmos 介面——讀取開放、寫入受控。

注意事項
  • Cosmos schema 是動態的,但 DAB 需要 GraphQL 類型 — 提供 GraphQL schema 檔案;若未提供,DAB 會退回 REST

將預存程序公開為 MCP 工具

👤 在 TSQL 中有完善業務邏輯的 DBA ⏱ ~25 min advanced

何時使用: 現有預存程序封裝了業務規則,你寧願將其公開給 Claude,而非讓 Claude 直接存取資料表。

步驟
  1. 定義實體
    In dab-config, add entity GetSalesByRegion of type stored-procedure pointing to dbo.usp_GetSalesByRegion. Map parameters to MCP tool inputs.✓ 已複製
    → 預存程序顯示為可呼叫的 MCP 工具
  2. 測試
    Call GetSalesByRegion for region='APAC', period='2026Q1'.✓ 已複製
    → 返回結果資料列

結果: 業務邏輯保留在資料庫中,AI 只負責呼叫。

注意事項
  • 預存程序返回多個結果集 — DAB 僅返回第一個;重構為單一結果集,或拆分成多個程序

組合

與其他 MCP 搭配,撬動十倍槓桿

azure-data-api-builder-mcp + filesystem

將 dab-config.json 與生成的 GraphQL schema 持久化到版本庫

Save dab-config.json and schema.graphql under /db/dab/.✓ 已複製
azure-data-api-builder-mcp + github

DAB 設定變更時開啟 PR

Diff against main; if changed, open PR titled 'DAB config update'.✓ 已複製

工具

此 MCP 暴露的能力

工具輸入參數何時呼叫成本
list_entities (none) 了解已公開的內容 free
<entity>.read filter?, top?, select?, orderby? 標準讀取;將 <entity> 替換為實際實體名稱 1 DB query per call
<entity>.create fields object 僅在權限允許建立時使用 1 DB insert
<storedproc> configured params 封裝業務邏輯 1 DB call

成本與限制

運行它的成本

API 配額
受限於你的 Azure DB 方案
每次呼叫 Token 數
依返回資料列數,100–2000 個 token
費用
DAB 免費;資料庫費用自行負擔。本地 Docker 無額外費用。
提示
使用 top + select 控制結果集大小,讓 token 費用可預測

安全

權限、密鑰、影響範圍

最小權限: DB read role (e.g. db_datareader for read-only)
憑證儲存: 透過環境變數或 Azure Managed Identity(在 Azure 中為首選)提供連線字串
資料出站: 若在 Azure 中部署 DAB,資料將保留在 Azure 內部
切勿授予: db_owner DDL rights

故障排查

常見錯誤與修復

使用者登入失敗

檢查連線字串——DAB 需要存在的 SQL 或 Entra 帳號;防火牆需允許該主機

驗證: 從相同主機以相同憑證執行 `sqlcmd`
MCP 工具清單中找不到實體

編輯 dab-config.json 後重新啟動 DAB——設定在啟動時載入一次

驗證: 查看容器日誌中的「Entity X registered」
Cosmos 缺少 GraphQL 類型

在 dab-config.json 旁提供 schema.graphql,或設定 GraphQL.Mode = REST-only

替代方案

Azure Data API Builder (MCP) 對比其他方案

替代方案何時用它替代權衡
Hasura你想要更完善的 GraphQL 介面且目前不需要 MCPHasura 功能更廣但較重;DAB 與 Azure 對齊且更輕量
Direct Postgres MCP / Postgres MCP server你不在 Azure 上且只需要直接存取 PostgresPostgres MCP 更簡單;DAB 強制執行每實體/每列策略

更多

資源

📖 閱讀 GitHub 上的官方 README

🐙 查看未解決的 issue

🔍 瀏覽全部 400+ MCP 伺服器和 Skills