mcpField
D
datadog-mcp

datadog-mcp

本地服务
github.com/tantiope云与基础设施617 周前更新

关于 datadog-mcp

datadog-mcp 向 AI 助手开放 Datadog 可观测性 API,涵盖日志、指标、追踪、监控器等。支持本地 stdio 和远程 HTTP 传输,也可配置为只读模式。

主要功能

  1. 01搜索并聚合日志与追踪
  2. 02查询和检查指标
  3. 03管理监控器与仪表板
  4. 04处理事件、事故与 SLO
  5. 05使用 stdio 或 HTTP 传输

适用场景

  1. 01关联日志与追踪以调查错误
  2. 02查看指标趋势和监控活动
  3. 03通过 AI 客户端管理 Datadog 资源

MCP 相关

该 MCP 服务向兼容客户端提供 Datadog API 工具,用于可观测性查询和资源管理,并支持 stdio 与 HTTP 传输。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"tantiope-datadog": {
"command": "npx",
"args": [
"-y",
"datadog-mcp"
],
"env": {
"DD_API_KEY": "<DD_API_KEY>",
"DD_APP_KEY": "<DD_APP_KEY>",
"DD_SITE": "<DD_SITE>"
}
}
}
}
启动命令npx -y datadog-mcp
需要配置的环境变量
DD_API_KEY密钥Datadog API key
DD_APP_KEY密钥Datadog Application key
DD_SITEDatadog site (e.g., datadoghq.com, datadoghq.eu, us3.datadoghq.com)

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npmdatadog-mcp1.0.9

工具

19

收录的工具列表 · 更新于 2 周前

参数类型必填说明
idstring否监控器 ID(get/update/delete/mute/unmute 必填)
endnumber否静默结束时间戳(用于 mute 操作)
namestring否按名称筛选(用于 list 操作)
tagsarray否按标签筛选
limitnumber否要返回的监控器数量上限
querystring否搜索操作的查询
actionenum是要执行的操作list | get | search | create | update | delete | mute | unmute
configobject否监控器配置(用于 create/update)
messagestring否静默消息(用于 mute 操作)
groupStatesarray否按组状态筛选:alert、warn、no data、ok

详细介绍

Datadog MCP 服务

Quality gate CI/Release npm License Coverage

免责声明:这是一个由社区维护的项目,与 Datadog, Inc. 没有官方关联,也未获得其认可或支持。此 MCP 服务使用 Datadog API,但由独立团队开发。

为 AI 助手提供完整 Datadog 可观测性访问能力的 MCP 服务。功能包括类似 grep 的日志搜索、按持续时间/状态/错误查询筛选 APM 跟踪、提升 Token 效率的智能采样模式,以及日志、跟踪和指标之间的交叉关联。支持 stdio(本地)和 http(远程/Kubernetes)传输方式。

快速开始

Claude Desktop/VS Code/Cursor 的最简配置——仅需两个必填项:

{
  "mcpServers": {
    "datadog": {
      "command": "npx",
      "args": ["-y", "datadog-mcp"],
      "env": {
        "DD_API_KEY": "your-api-key",
        "DD_APP_KEY": "your-app-key"
      }
    }
  }
}

添加可选配置(EU 站点、自定义默认限制、延长日志时间范围):

{
  "mcpServers": {
    "datadog": {
      "command": "npx",
      "args": ["-y", "datadog-mcp"],
      "env": {
        "DD_API_KEY": "your-api-key",
        "DD_APP_KEY": "your-app-key",
        "DD_SITE": "datadoghq.eu",
        "MCP_DEFAULT_LIMIT": "50",
        "MCP_DEFAULT_LOG_LINES": "200",
        "MCP_DEFAULT_METRIC_POINTS": "1000",
        "MCP_DEFAULT_TIME_RANGE": "24"
      }
    }
  }
}

如需作为 HTTP 服务运行(例如在容器或 Kubernetes Pod 中),请在同一 env 块中添加传输变量:

"env": {
  "DD_API_KEY": "your-api-key",
  "DD_APP_KEY": "your-app-key",
  "MCP_TRANSPORT": "http",
  "MCP_PORT": "3000",
  "MCP_HOST": "0.0.0.0"
}

配置

必需的环境变量
DD_API_KEY=your-api-key
DD_APP_KEY=your-app-key
可选环境变量
DD_SITE=datadoghq.com  # Default. Use datadoghq.eu for EU, etc.

# Limit defaults (fallbacks when the AI doesn't specify)
MCP_DEFAULT_LIMIT=50              # General tools default limit
MCP_DEFAULT_LOG_LINES=200         # Logs tool default limit
MCP_DEFAULT_METRIC_POINTS=1000    # Metrics timeseries data points
MCP_DEFAULT_TIME_RANGE=24         # Default time range in hours

# Transport (alternative to CLI flags — useful in Kubernetes)
MCP_TRANSPORT=stdio               # stdio | http
MCP_PORT=3000                     # HTTP port
MCP_HOST=0.0.0.0                  # HTTP host
可选标志
--site=datadoghq.com     # Datadog site (overrides DD_SITE)
--transport=stdio|http   # Transport mode (default: stdio)
--port=3000              # HTTP port when using http transport
--host=0.0.0.0           # HTTP host when using http transport
--read-only              # Block all write operations
--disable-tools=synthetics,rum,security    # Comma-separated list of tools to disable

传输方式

传输方式使用场景端点
stdio(默认)本地 MCP 客户端——Claude Desktop、Cursor、VS Coden/a(进程 stdin/stdout)
http远程/容器/KubernetesPOST /mcp · GET /mcp(SSE)· DELETE /mcp · GET /health

使用 --transport=http 或 MCP_TRANSPORT=http 进行选择。

部署

Docker
{
  "mcpServers": {
    "datadog": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-e", "DD_API_KEY",
        "-e", "DD_APP_KEY",
        "-e", "DD_SITE",
        "ghcr.io/tantiope/datadog-mcp"
      ],
      "env": {
        "DD_API_KEY": "your-api-key",
        "DD_APP_KEY": "your-app-key",
        "DD_SITE": "datadoghq.com"
      }
    }
  }
}
Kubernetes

使用环境变量而非容器参数来配置传输方式:

env:
  - name: DD_API_KEY
    value: "your-api-key"
  - name: DD_APP_KEY
    value: "your-app-key"
  - name: MCP_TRANSPORT
    value: "http"
  - name: MCP_PORT
    value: "3000"
  - name: MCP_HOST
    value: "0.0.0.0"

注意: Kubernetes 的 args: 会替换整个 Dockerfile CMD,导致 Node.js 接收这些标志而不是应用程序。使用环境变量可以避免此问题。

工具

工具操作类别描述所需权限范围
monitorslist告警列出监视器,可选筛选条件monitors_read
monitorsget告警按 ID 获取监视器monitors_read
monitorssearch告警根据查询搜索监视器monitors_read
monitorscreate告警创建新监视器;config 会根据涵盖已记录选项(notifyNoData、renotifyInterval、thresholds 等)的类型化架构进行验证;未知键会显示在 warnings 中。传入 dry_run: true 可在不创建监视器的情况下进行验证(使用 /api/v1/monitor/validate,只读模式下允许)。monitors_write
monitorsupdate告警更新现有监视器;使用与 create 相同的已验证架构;接受部分配置;验证错误会在任何 HTTP 调用之前终止操作,并返回 EINVALID_MONITOR_CONFIG:monitors_write
monitorspreview告警渲染监视器模板(内联 message 或通过 monitor_id/id 指定),可选传入包含变量和条件语句的 context。返回 {rendered, variablesUsed, variablesMissing, conditionalsResolved, tagConditionalsResolved}。支持 Datadog Mustache 子集:变量替换、六种已记录的条件语句(is_alert、is_warning、is_no_data、is_recovery、is_alert_to_warning、is_warning_to_alert),以及标签条件语句 {{#is_match "tag" "val"}}/{{#is_exact_match "tag" "val"}}(以及 ^ 否定形式);{{#each}}/partials 会抛出 EUNSUPPORTED_TEMPLATE_SYNTAX。只读。monitors_read
monitorstest_notification告警已知限制:返回 ENOT_SUPPORTED — Datadog 没有用于触发测试通知的公开 REST 端点。响应中提供文档链接。不适用
monitorsdelete告警删除监视器monitors_write
monitorsmute告警静默监视器monitors_write
monitorsunmute告警取消静默监视器monitors_write
monitorstop告警按告警频率列出前 N 个监视器,并提供真实监视器名称和上下文细分。警告:total_count 包含重新通知/重新评估(处于 Alert 状态时,Datadog 每隔 renotify_interval 分钟就会发出一个重新通知事件)。如需查看真实触发次数,请使用 action=history。monitors_read
monitorshistory告警统计并列出某个监视器在指定时间范围内的真实状态转换。按 transitionType 筛选(默认值为 ["alert","alert recovery"] — 触发+恢复,不包括重新通知),也可选按 group 筛选。返回 {transitions: [...], count, meta},其中 count 是真实状态转换的数量(例如,对于一个始终处于 Alert 状态的燃烧率监视器,在 7d 内有 98 个原始事件,但只有 38 次真实状态转换)。monitors_read、events_read
dashboardslist可视化列出所有仪表板dashboards_read
dashboardsget可视化按 ID 获取仪表板dashboards_read
dashboardscreate可视化创建新仪表板dashboards_write
dashboardsupdate可视化更新仪表板dashboards_write
dashboardsdelete可视化删除仪表板dashboards_write
logssearch日志使用查询语法和筛选条件搜索日志logs_read_data、logs_read_index_data
logsaggregate日志使用 groupBy 聚合日志数据logs_read_data
logs_pipelineslist, get日志配置检查日志处理管道及其处理器logs_read_config
logs_pipelinescreate, update, delete, reorder日志配置编写管道和处理器链logs_write_config
logs_pipelinesget_order日志配置读取管道评估顺序logs_read_config
logs_indexeslist, get日志配置检查索引(筛选条件、保留期限、Flex 层、排除筛选条件);根据 Datadog 的规定,create/delete 仅可通过 UI 操作,因此不提供logs_read_config
logs_indexesupdate, reorder日志配置更新索引筛选条件/保留期限/配额并重新排序评估顺序logs_write_config
logs_indexesget_order日志配置读取索引评估顺序logs_read_config
logs_archiveslist, get日志配置检查日志归档(S3 / GCS / Azure 目标);各提供商的凭据字段会原样转发logs_read_archives
logs_archivescreate, update, delete, reorder日志配置管理归档目标;在调用 SDK 前,destination.type 会根据 `s3gcs
logs_archivesget_order日志配置读取归档评估顺序logs_read_archives
metricsquery指标查询时间序列数据。响应中的 meta 包含 rollupRequested(从 rollup(method, seconds) 解析得出,并包含 methodInferred 标记)、rollupEffective(根据返回的 pointlist 间隔得出的间隔,以及多序列情况下去重后的 intervalsObserved)和 rollupOverridden: boolean,以便调用方检测 Datadog 是否进行了未提示的降采样。metrics_read、timeseries_query
metricssearch指标按名称搜索指标metrics_read
metricslist指标列出活跃指标metrics_read
metricsmetadata指标获取指标元数据metrics_read
tracessearchAPM使用筛选条件搜索跨度apm_read
tracesaggregateAPM聚合追踪数据apm_read
tracesservicesAPM列出 APM 服务apm_service_catalog_read
eventslist事件列出事件events_read
eventsget事件按 ID 获取事件events_read
eventscreate事件创建事件events_read
eventssearch事件使用 v2 API 和游标分页搜索事件。可选的 transitionType 筛选条件(例如 ["alert","alert recovery"])可将结果限定为监视器状态转换事件 — 不使用该筛选条件时,source:alert 会包含重新通知。要查看特定监视器的触发事件,请使用 monitors action=history。可选的 timezone 会为每个时间戳添加 *Local ISO 8601 同级字段。无结果的响应会包含 diagnostics 数组,提示可能的原因(UNINDEXED_TAG_PREFIX、NARROW_TIME_RANGE、RESTRICTIVE_SOURCE_FILTER)。events_read
eventshistogram事件在服务端按 IANA timezone 中的 hour_of_day、day_of_week 或 day_of_month 对事件分桶(通过 Intl.DateTimeFormat 安全处理夏令时)。接受与 search 相同的 transitionType 筛选条件,因此监视器直方图可以排除重新通知。对底层搜索使用游标分页;上限为 limits.maxEventsForHistogram(默认值为 5000,可通过 MCP_MAX_EVENTS_HISTOGRAM 环境变量配置)。达到上限时,会返回 bucketCountIncomplete: true 和用于继续查询的 nextCursor。events_read
eventsaggregate事件在客户端按 monitor_name、source 等聚合events_read
eventstop事件按数量列出前 N 个事件组,支持通用 groupBy(部署、配置、告警等)。不含上下文标签的组会列为 "no_context"events_read
eventstimeseries事件按时间分桶的告警趋势(每小时/每日计数)events_read
eventsincidents事件将告警去重并归并为事件,配对 Trigger/Recoverevents_read
incidentslist事件列出事件incident_read
incidentsget事件按 ID 获取事件incident_read
incidentssearch事件搜索事件incident_read
incidentscreate事件创建事件incident_write
incidentsupdate事件更新事件incident_write
incidentsdelete事件删除事件incident_write
sloslistSLO列出 SLO。每个项目都会公开 query、monitorIds、monitorTags、groups 和 UI url,确保往返操作(get → edit → update)能够保留定义字段。slos_read
slosgetSLO按 ID 获取 SLO(投影方式与 list 相同)。slos_read
sloscreateSLO创建 SLOslos_write
slosupdateSLO更新 SLOslos_write
slosdeleteSLO删除 SLOslos_write
sloshistorySLO获取 SLO 历史记录slos_read
syntheticslist合成监控列出合成测试synthetics_read
syntheticsget合成监控按公开 ID 获取测试synthetics_read
syntheticscreate合成监控创建测试synthetics_write
syntheticsupdate合成监控更新测试synthetics_write
syntheticsdelete合成监控删除测试synthetics_write
syntheticstrigger合成监控触发测试运行synthetics_write
syntheticsresults合成监控获取测试结果synthetics_read
downtimeslist停机时间列出停机时间monitors_downtime
downtimesget停机时间按 ID 获取停机时间monitors_downtime
downtimescreate停机时间创建停机时间monitors_downtime
downtimesupdate停机时间更新停机时间monitors_downtime
downtimescancel停机时间取消停机时间monitors_downtime
downtimeslistByMonitor停机时间列出某监视器的停机时间monitors_downtime
hostslist基础设施列出主机hosts_read
hoststotals基础设施获取主机总数hosts_read
hostsmute基础设施静默主机hosts_read
hostsunmute基础设施取消静默主机hosts_read
rumapplicationsRUM列出 RUM 应用rum_read
rumeventsRUM搜索 RUM 事件rum_read
rumaggregateRUM聚合 RUM 数据rum_read
rumperformanceRUM获取 Core Web Vitals(LCP、FCP、CLS、FID、INP)rum_read
rumwaterfallRUM获取包含资源/操作/错误的会话时间线rum_read
securityrules安全列出安全规则security_monitoring_rules_read
securitysignals安全搜索安全信号security_monitoring_signals_read
securityfindings安全列出安全发现security_monitoring_findings_read
notebookslist笔记本列出笔记本notebooks_read
notebooksget笔记本按 ID 获取笔记本notebooks_read
notebookscreate笔记本创建笔记本notebooks_write
notebooksupdate笔记本更新笔记本notebooks_write
notebooksdelete笔记本删除笔记本notebooks_write
userslist管理列出用户user_access_read
usersget管理按 ID 获取用户user_access_read
teamslist管理列出团队teams_read
teamsget管理按 ID 获取团队teams_read
teamsmembers管理列出团队成员teams_read
tagslist基础设施列出所有标签hosts_read
tagsget基础设施获取主机标签hosts_read
tagsadd基础设施为主机添加标签hosts_read
tagsupdate基础设施更新主机标签hosts_read
tagsdelete基础设施删除主机标签hosts_read
usagesummary账单使用情况摘要usage_read
usagehosts账单主机使用情况usage_read
usagelogs账单日志使用情况usage_read
usagecustom_metrics账单自定义指标使用情况usage_read
usageindexed_spans账单已索引跨度使用情况usage_read
usageingested_spans账单已摄取跨度使用情况usage_read
authvalidate身份验证测试 API 密钥和 App 密钥是否有效—

限制控制

AI 助手可以完全控制查询限制。MCP_DEFAULT_* 环境变量仅在 AI 未指定限制时设置回退值,并不会限制 AI 可以请求的上限。

工具默认值参数描述
日志200limit返回的日志行数
指标(时间序列)1000pointLimit每个序列的数据点数(控制分辨率)
通用工具50limit返回的结果数

工具级别的令牌缩减功能(日志上的 compact: true、sample: "diverse" | "spread" | "first"、字段投影、诊断信息)会显示在每个工具的 MCP 描述中,由 AI 在调用时选择。

值得注意的行为

以下是一些值得了解的模式;AI 可以从工具描述中了解其他内容。

  • 重新通知与实际触发。 monitors top 和带有 source:alert 的 events search 会统计 Datadog 发出的每次重新通知(当监控器处于 Alert 状态时,每隔一个 renotify_interval 发出一次)。要获取实际的状态转换,请使用 monitors history(默认值为 transitionType: ["alert","alert recovery"]),或向 events search 传入 transitionType。
  • 适配夏令时的时间分桶。 events histogram 使用 Intl.DateTimeFormat,通过任意 IANA timezone 按 hour_of_day / day_of_week / day_of_month 分桶。底层搜索采用游标分页;上限由 MCP_MAX_EVENTS_HISTOGRAM 控制(默认值为 5000),超出时会返回 bucketCountIncomplete 和 nextCursor。
  • 创建前先验证。 使用 dry_run: true 调用 monitors create 时,会调用 /api/v1/monitor/validate,而不是持久化数据。此操作允许在 --read-only 模式下执行。
  • 监控器模板预览。 monitors preview 会使用 context 负载渲染通知,包括变量替换、Datadog 文档中记录的六种条件(is_alert、is_warning、is_no_data、is_recovery、is_alert_to_warning、is_warning_to_alert),以及标签条件 {{#is_match "tag" "val"}}(子字符串匹配)和 {{#is_exact_match "tag" "val"}}(精确匹配),支持 ^ 取反和多个比较值的 OR 逻辑(根据 context.variables 解析;区分大小写)。{{#each}} 和 partials 会抛出 EUNSUPPORTED_TEMPLATE_SYNTAX。
  • SLO 往返。 slos get 会投影 query、monitorIds、monitorTags、groups 和 UI url,方便你编辑后传回 slos update,而不会丢失定义字段。
  • 交叉关联。 logs(sample:"diverse") → 提取 dd.trace_id → traces(query:"trace_id:<id>") → metrics(query:"p95:trace.express.request{service:...}")(计算百分位数时使用不带 .duration 的根指标)。

深层链接

每个查询响应都包含一个 datadog_url 字段,该字段根据你配置的 DD_SITE 构建,支持 datadoghq.com(默认值)、.eu、us3 / us5 / ap1.datadoghq.com 或 ddog-gov.com。支持 logs、metrics、traces、events、monitors、rum、slos。

贡献

欢迎贡献!如果你有任何建议、错误报告或改进提议,欢迎提交 issue 或 pull request。

许可证

本项目基于 Apache License, Version 2.0 授权。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。