Skip to main content
Glama

adf-mcp-server

用于 Azure Data Factory 监控和根因分析的只读 MCP(模型上下文协议)服务器,专为从 VS Code / Claude Code 使用而构建。

状态:第 1 步(骨架 + 健康检查)。 尚无 Azure 连接 - 将在第 2 步(身份验证)和第 3 步(ADF 工具)中添加。

要求

  • Python 3.11+

  • 一个 Azure AD 应用注册(服务主体),在你要检查的 Data Factory 资源上具有 Reader 角色(Reader 就足够了 - 此服务器端到端只读,因此永远不需要 Contributor)

Related MCP server: adf-mcp-server

本地设置

cd adf-mcp-server
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
cp .env.example .env

创建服务主体(一次性,通过 az-cli)

az ad sp create-for-rbac \
  --name "adf-mcp-server-reader" \
  --role "Reader" \
  --scopes "/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.DataFactory/factories/<FACTORY_NAME>"

这会打印 appId、password 和 tenant - 将它们分别映射到 .env 中的 AZURE_CLIENT_ID、AZURE_CLIENT_SECRET 和 AZURE_TENANT_ID。将角色分配范围限定到特定工厂(或最多资源组),而不是整个订阅 - 最小权限,并且此 SPN 永远不需要接触 ADF 之外的任何内容。

运行服务器

python -m adf_mcp.server
# or, after `pip install -e .`:
adf-mcp-server

服务器通过 stdio 通信 - 直接在终端中运行它看起来像挂起;这是预期的,它正在等待 MCP 客户端(VS Code 扩展、Claude Code、mcp dev 等)通过 stdin/stdout 连接。

在 VS Code 中配置

将你的支持 MCP 的扩展的服务器配置指向:

{
  "command": "python",
  "args": ["-m", "adf_mcp.server"],
  "cwd": "/absolute/path/to/adf-mcp-server"
}

连接后:

  1. 调用 health_check - 应返回 {"status": "ok", ...},完全不接触 Azure。

  2. 调用 check_auth - 这会向 Azure AD 发出一次真实调用以获取 ARM 令牌。成功看起来像:

    {"authenticated": true, "auth_mode": "service_principal", "token_expires_on": 1735000000}

    失败返回结构化(非堆栈跟踪)说明,例如缺少环境变量或无效密钥 - 请参阅下面的故障排除。

  3. 调用 list_factories - 这会向 Azure Data Factory 发出真实调用。返回每个工厂的 resource_group,下面所有其他工具都需要它作为输入:

    {"factories": [{"name": "shell-prod-adf", "resource_group": "rg-shell-prod", "location": "eastus"}]}

可用工具(第 3 步)

所有工具都是只读的 - 它们都不能在 Azure Data Factory 中创建、修改、触发或删除任何内容。

工具

必需参数

说明

health_check

—

无 Azure 调用

check_auth

—

仅验证服务主体

list_factories

—

从这里开始 - 返回每个工厂的 resource_group

get_factory

resource_group, factory_name

list_pipelines

resource_group, factory_name

轻量级:名称 + 活动计数/名称

get_pipeline

resource_group, factory_name, pipeline_name

单个管道的完整活动列表

list_pipeline_runs

resource_group, factory_name

start_time/end_time 可选(默认:最近 24 小时),以及可选的 pipeline_name/status 过滤器。消息截断为 500 个字符。

get_pipeline_run

resource_group, factory_name, run_id

完整、未截断的运行详情 - 先从 list_pipeline_runs 获取 run_id

代理的示例 RCA 流程:list_factories → list_pipeline_runs(status="Failed") → get_failed_activity_details(run_id=...) 直接获取错误分解。

可用工具(第 4 步新增)

工具

必需参数

说明

list_activity_runs

resource_group, factory_name, run_id

运行的完整活动列表;start_time/end_time 可选(默认:最近 7 天)

get_failed_activity_details

resource_group, factory_name, run_id

RCA 工具 - 仅失败的活动,已提取 error_code/message/failure_type

list_triggers

resource_group, factory_name

所有触发器 + 当前运行时状态(已启动/已停止)

get_trigger_status

resource_group, factory_name, trigger_name

单个触发器的运行时状态 - 捕获“管道从未运行,因为其触发器已停止”

list_trigger_runs

resource_group, factory_name

trigger_name 可选(省略则所有触发器);默认窗口最近 7 天;可选 status 过滤器

失败管道的完整 RCA 流程:list_pipeline_runs(status="Failed") → get_failed_activity_details(run_id=...) 获取错误,并单独使用 get_trigger_status(trigger_name=...) 排除“它甚至从未触发”的情况。

运行测试

pip install -e ".[dev]" pytest-asyncio
pytest -v

项目结构

参见 src/adf_mcp/ - server.py(MCP 传输)、config.py(设置)、logging_config.py(结构化日志)。从第 3 步开始,在 src/adf_mcp/domain/ 下添加领域逻辑和 Azure 连接。

故障排除

  • 客户端立即显示“服务器已断开”:首先检查 python -m adf_mcp.server 能否独立正常运行 - 启动异常会在客户端连接之前终止进程。

  • 客户端无法解析响应 / 输出乱码:有东西写入了 stdout,而不是 MCP 协议本身(例如多余的 print())。本项目中的所有日志都输出到 stderr,正是出于这个原因。

  • check_auth 返回“缺少必需的服务主体设置”:AZURE_TENANT_ID / AZURE_CLIENT_ID / AZURE_CLIENT_SECRET 之一在 .env 中为空。请注意,这三个不使用 ADF_MCP_ 前缀。

  • check_auth 返回“Azure 身份验证失败”:通常是客户端密钥过期/轮换、应用注册被禁用或租户 ID 拼写错误。使用 az ad sp show --id <AZURE_CLIENT_ID> 重新验证。

  • ClientAuthenticationError: AADSTS7000215:客户端密钥无效 - 在应用注册中重新生成并更新 .env。

  • 工具返回 {"error": "AZURE_SUBSCRIPTION_ID is not set..."}:将 AZURE_SUBSCRIPTION_ID 添加到 .env - 每个 ADF 工具都需要(check_auth 不需要,它只需要租户/客户端/密钥)。

  • 工具返回 {"error": "Azure API error (403): ..."}:服务主体缺少对该工厂/资源组的 Reader 访问权限 - 重新检查设置中的 az ad sp create-for-rbac --role Reader --scopes ... 分配。

  • 工具返回 {"error": "Azure API error (404): ..."}:检查 resource_group/factory_name/pipeline_name 的拼写 - 这些区分大小写,必须与 list_factories/list_pipelines 返回的内容完全匹配。

  • get_failed_activity_details 返回空列表,但你知道管道失败了:失败可能发生在管道级别(例如参数无效),而不是任何单个活动 - 请改用 get_pipeline_run 检查父运行自身的 message。

  • 管道“就是没运行”,完全没有失败的运行:检查其触发器的 get_trigger_status - runtime_state: "Stopped" 表示触发器已被禁用且从未触发,这不会显示为失败的运行,因为从未创建任何运行。

Available Tools

13 tools
check_authA

Verify Azure Service Principal credentials by acquiring a real ARM token.

Makes no Azure Data Factory calls - it only proves auth is configured correctly (tenant/client/secret valid, SPN enabled) before any ADF connectivity exists. Run this after health_check and before Step 3.

Inputs: no named parameters. Returns: object

get_factoryC

Get details for a single Data Factory instance.

Inputs: factory_name (required), resource_group (required). Returns: object

get_failed_activity_detailsA

RCA convenience tool: returns only the activities that failed within a pipeline run, each with error_code/message/failure_type already extracted. Prefer this over list_activity_runs when you just need "what went wrong" rather than the full activity list.

Inputs: run_id (required), factory_name (required), resource_group (required), end_time, +1 more. Returns: object

get_pipelineC

Get a single pipeline's activity list.

Inputs: factory_name (required), pipeline_name (required), resource_group (required). Returns: object

get_pipeline_runB

Get full, untruncated detail for a single pipeline run.

Get run_id from list_pipeline_runs first.

Inputs: run_id (required), factory_name (required), resource_group (required). Returns: object

get_trigger_statusB

Get a single trigger's current runtime state. A stopped trigger is a common silent cause of "why didn't this pipeline run today" - the pipeline simply was never invoked, so pipeline-run history alone won't show it.

Inputs: factory_name (required), trigger_name (required), resource_group (required). Returns: object

health_checkA

Report that the MCP server is up and configuration loaded correctly.

Useful as a first call from any MCP client (VS Code, Claude Code) to confirm the server started, before any Azure-dependent tools exist.

Inputs: no named parameters. Returns: object

list_activity_runsA

List every activity run within a pipeline run, each with error detail populated if it failed. Time window defaults to the last 7 days. Get run_id from list_pipeline_runs first.

Inputs: run_id (required), factory_name (required), resource_group (required), end_time, +1 more. Returns: object

list_factoriesA

List all Data Factory instances the configured Service Principal can see.

Returns each factory's resource_group, which every other ADF tool below requires as an input - call this first.

Inputs: no named parameters. Returns: object

list_pipeline_runsA

List pipeline runs in a time window (default: last 24 hours).

Time values are ISO 8601 strings, e.g. "2026-08-22T00:00:00Z". Narrow results with pipeline_name and/or status (e.g. "Failed", "Succeeded", "InProgress"). Run messages are truncated to 500 chars here - use get_pipeline_run with a run_id from this result for full detail.

Inputs: factory_name (required), resource_group (required), status, end_time, +2 more. Returns: object

list_pipelinesA

List pipelines in a factory with a lightweight activity summary (count and names only - use get_pipeline for full detail on one).

Inputs: factory_name (required), resource_group (required). Returns: object

list_trigger_runsA

List trigger firing history (default: last 7 days). Omit trigger_name to see every trigger's runs, or narrow to one; filter by status (e.g. "Succeeded", "Failed") to spot triggers that fired but errored.

Inputs: factory_name (required), resource_group (required), status, end_time, +2 more. Returns: object

list_triggersA

List every trigger in a factory with its current runtime state (Started/Stopped).

Inputs: factory_name (required), resource_group (required). Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 13 tools

    Disambiguation5/5

    Each tool targets a distinct layer of the ADF workflow: health/auth bootstrap, factory discovery, pipeline inspection, run monitoring, activity diagnostics, and trigger management. Even the closest pair, list_activity_runs and get_failed_activity_details, is clearly separated by scope and purpose.

    Naming Consistency4/5

    The naming is overwhelmingly consistent with list_/get_ + resource noun in snake_case, and the run-related tools follow a clear pattern. health_check is a minor convention break compared to check_auth, but this is a small deviation in an otherwise predictable set.

    Tool Count5/5

    13 tools is well-scoped for an ADF server: each tool maps to a distinct object hierarchy or bootstrap step without unnecessary redundancy. The count is substantial enough to cover real workflows but not bloated.

    Completeness4/5

    The set covers the read-only factory, pipeline, run, activity, and trigger diagnostics lifecycle well, including failure RCA. It lacks any management/remediation operations such as stopping or starting triggers, canceling runs, or rerunning pipelines, so it is slightly incomplete for full operational control.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables read-only querying of Azure Log Analytics and Azure Resource Graph through MCP, supporting KQL queries, workspace discovery, and resource inventory exploration with Azure RBAC authentication.
      11
      41 npm
      2
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables read-only monitoring and root-cause analysis of Azure Data Factory resources through MCP, allowing users to inspect factories, pipelines, and pipeline runs and diagnose failures via natural language.
      -
    • A
      license
      B
      quality
      C
      maintenance
      Provides read-only access to multiple production services with unified status and timeline tools for cross-service monitoring and diagnostics.
      13
      1
      MIT