Skip to main content
Glama

netdiag-mcp

English | 日本語

用于按需网络诊断的 MCP 服务器 — DNS 查询(带 DNSSEC AD 位检查)、ping、基于 mtr 的路径报告、TCP 端口检查、HTTP 状态/重定向检查、TLS 证书检查以及 WHOIS,全部集中在一台服务器上。

专为排查"无法访问 X"/"DNS 是否已传播"类报告而构建,无需为每次一次性的 dig/ping/curl 操作登录跳板机。

工具

工具

用途

dns_lookup

通过 dig 解析 DNS 记录(A/AAAA/MX/TXT/NS/CNAME/SOA/PTR/CAA),可选择指定解析器,并支持普通 DNS/DoT/DoH

dnssec_check

查询已知的验证解析器并报告 AD 位是否已设置(普通/DoT/DoH)— 这是确认 DNSSEC 验证的唯一可靠方式,因为普通 dig 回复中存在 RRSIG 本身并不能证明有任何东西验证了它

ping_host

ICMP ping(计数限制为 1-10)

traceroute_path

通过 mtr --report 报告逐跳路径/丢包情况(固定周期,非实时/持续运行)

tcp_port_check

TCP 端口是否开放 — 仅普通套接字连接,非端口扫描

http_check

对 URL 执行 HEAD/GET 请求,报告状态、重定向链和延迟

tls_cert_check

获取主机提供的证书,报告主题/颁发者/有效期/SAN

whois_lookup

域名的 WHOIS 查询

asn_lookup

通过 Team Cymru 的 whois 服务查询 IP 的 ASN + 国家/地区代码,或 AS 号的组织信息 — 无需 API 密钥或 GeoIP 数据库

health_check

版本信息以及 PATH 中存在哪些被封装的二进制文件(dig/ping/mtr/whois)

所有工具均为只读且单目标(无批量/扫描模式)— 这是对运维人员手动执行的检查的便捷封装,而非扫描工具。nmap 风格的多主机/多端口扫描被有意排除在范围之外;故意探测大量主机或端口是另一种影响范围更大的操作,需要专门的工具和审批流程。

tcp_port_check、http_check 和 tls_cert_check 使用 Python 自带的 socket/ssl/httpx 栈,而不是调用 nc/curl/openssl,因此即使主机上只安装了 dig/ping/mtr/whois 二进制文件(或一个都没有 — health_check 会报告哪些缺失而不会导致整个服务器失败),这三个工具也能正常工作。

dns_lookup/dnssec_check 通过 transport="dot"/"doh" 支持 DNS-over-TLS 和 DNS-over-HTTPS(dig 的 +tls/+https)。这需要 BIND 9.18+ 的 dig — 较旧的 dig 会直接拒绝该标志,而不是静默回退到普通 DNS,因此过时的二进制文件会明确失败,而不会让人误以为已通过加密传输进行了检查。

对裸 IP 地址执行 tls_cert_check/http_check 时,在 SNI 托管/CDN 前置源站(例如 Cloudflare 后面)上可能会因"握手失败"或类似错误而导致 TLS 握手失败 — TLS 的 SNI 扩展只携带主机名,因此 IP 字面量无法在共享边缘节点上路由到正确的证书。这是正常的 TLS 行为,不是工具缺陷;当目标是 CDN 前置时,请使用主机名进行检查。

Related MCP server: Keel

设置

1. 系统依赖

dns_lookup、dnssec_check、ping_host、traceroute_path 和 whois_lookup 分别调用 dig、ping、mtr 和 whois。请安装您需要使用的那些:

# Debian/Ubuntu
sudo apt install dnsutils iputils-ping mtr-tiny whois

mtr 需要原始套接字访问权限。Debian/Ubuntu 的 mtr-tiny 包在安装时会向 mtr-packet 辅助程序授予 cap_net_raw 权限,因此它通常无需额外设置即可供非特权服务用户使用 — 如果 traceroute_path 报告套接字权限错误,请使用 getcap "$(command -v mtr-packet)" 进行验证。如果没有该权限,traceroute_path 会以 ToolError 干净地失败,而不会导致服务器崩溃。

2. 安装

pip install netdiag-mcp
# or
uv tool install netdiag-mcp

3. Claude Code(手动)

claude mcp add netdiag -- netdiag-mcp

无需环境变量。

命令行界面

netdiag-mcp --version   # print version
netdiag-mcp --check     # report which wrapped binaries are present (exit 0 when all are)

安全说明

  • 每次外部二进制调用都传递 argv 列表(绝不使用 shell 字符串),因此任何工具参数都无法逃逸为 shell 语法。

  • 主机名/IP 和端口参数在使用前都会经过验证和大小/范围限制 — 工具输入由模型驱动,并被视为不受信任的数据,与任何其他工具调用面相同。

  • tcp_port_check 每次调用仅连接一个 host:port;按照设计,没有循环或范围参数。

开发

实时冒烟测试

单元测试根据固定数据检查逻辑;它们无法告诉您某个工具是否已停止返回真实数据(dig/ping/mtr/whois 二进制文件已死、TLS 信任库损坏、网络阻止出站 ICMP)。scripts/smoke_test.py 会针对真实的公共端点运行每个已注册的工具,并在返回空、格式错误或错误答案时失败:

uv run python scripts/smoke_test.py
uv run python scripts/smoke_test.py --only ping --traceback
  • 没有清单,因此每个目标都是固定的公共端点 — Cloudflare 的 1.1.1.1 和 IANA 的 example.com(保留用于文档/测试用途,RFC 2606)。该服务器不接受任何配置,也没有可从中发现目标的清单,与此系列中的设备群 MCP 服务器不同。

  • tests/test_smoke_probes.py 是离线部分:它只检查每个已注册的工具是否都有探针规范(反之亦然),因此 CI 可以在无需网络访问的情况下捕获添加了工具但未决定如何确认其工作正常的问题。

许可证

MIT

Available Tools

12 tools
asn_lookupA

ASN + country-code lookup for an IP, or org info for an AS number (e.g. AS15169 or 15169).

Via Team Cymru's whois service — no API key or GeoIP database needed. Takes an IP literal or AS number, not a hostname; resolve first with dns_lookup if you only have a name.

Inputs: target (required). Returns: result

current_timeA

Current date, time and weekday in an IANA timezone (e.g. "Asia/Tokyo").

Call this rather than deriving the weekday from a date yourself — that is calendar arithmetic and it fails silently. Returns the date, the 24h time, the weekday in English and Japanese, the offset, UTC and the epoch, so it also serves as a clock check on this server.

Inputs: timezone.

dns_lookupA

Resolve a DNS record via dig. record_type: A/AAAA/MX/TXT/NS/CNAME/SOA/PTR/CAA.

Pass resolver to query a specific nameserver instead of the host default (e.g. to check whether a change has propagated to a given resolver). transport: "plain" (UDP/TCP 53, default), "dot" (DNS-over-TLS, 853) or "doh" (DNS-over-HTTPS, 443). Requires dig from BIND 9.18+; an older dig rejects dot/doh outright instead of silently querying over plain DNS.

Inputs: hostname (required), resolver, transport, record_type. Returns: result

dnssec_checkA

Check whether a name validates DNSSEC against a known-validating resolver (AD bit).

transport: "plain" (default), "dot" or "doh" — compare validation over plain DNS vs. an encrypted transport when port 53 may be intercepted.

Inputs: hostname (required), resolver, transport. Returns: result

health_checkA

Service health: version, wrapped binaries on PATH, the http_get auth prefixes and the NAT64 prefix.

Returns a fixed shape (status/service/version + backend fields) so a monitoring caller never has to branch on missing keys. status is "healthy" when every wrapped binary is found and NETDIAG_HTTP_AUTH and NETDIAG_NAT64_PREFIX (if set) parse, "degraded" otherwise (the affected tools fail at call time). http_auth lists the configured URL prefixes, never the header values. nat64 shows the prefix IPv4 literals are reached through on an IPv6-only host (null when unset).

Inputs: no named parameters.

http_checkB

HEAD/GET a URL and report status, redirect chain and latency.

Inputs: url (required), timeout. Returns: result

http_getA

GET a URL and return the response body (text/JSON/XML only, capped at max_bytes, hard cap 1 MiB).

Use this to read a JSON endpoint or inspect an error page. For status/latency only, use http_check instead.

Inputs: url (required), timeout, max_bytes. Returns: result

ping_hostB

ICMP ping a host or IP. count is clamped to 1-10.

Inputs: host (required), count. Returns: result

tcp_port_checkA

Check whether a TCP port is open (plain socket connect, no port scanning).

Inputs: host (required), port (required), timeout. Returns: result

tls_cert_checkA

Fetch the TLS certificate presented on host:port and report subject/issuer/validity/SANs.

Inputs: host (required), port. Returns: result

traceroute_pathB

Path/MTU-style hop report via mtr --report (fixed cycles, not a live run). cycles clamped 1-10.

Inputs: host (required), cycles. Returns: result

whois_lookupC

WHOIS lookup for a domain.

Inputs: domain (required). Returns: result

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 12 tools

    Disambiguation5/5

    Each tool targets a distinct diagnostic purpose: DNS resolution, DNSSEC validation, HTTP status/body, ICMP, TCP ports, TLS certs, traceroute, WHOIS, ASN, health, and time. The closest overlaps, http_check vs http_get and dns_lookup vs dnssec_check, are explicitly differentiated in their descriptions.

    Naming Consistency3/5

    All names use snake_case and are readable, but the verb placement is mixed: most are noun_verb (dns_lookup, http_check), while ping_host is verb_noun and traceroute_path/current_time are noun phrases. The convention is serviceable but not fully predictable.

    Tool Count5/5

    Twelve tools is well-scoped for a network diagnostics server, covering common checks without excessive breadth. Each tool appears to earn its place by covering a distinct diagnostic category.

    Completeness4/5

    The surface covers the core network diagnostic workflows: DNS, DNSSEC, HTTP, ICMP, TCP, TLS, traceroute, WHOIS, ASN, health, and time. Minor gaps exist, such as no UDP port check or broader HTTP request methods, but agents can work around them for diagnostics.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      MCP server for DNS lookups, reverse DNS, WHOIS, and domain checks. Zero auth, zero config.
      5
      72 npm
      3
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Network diagnostics — ping, traceroute, DNS lookup, port scanning, and connectivity testing via MCP.
      14
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      MCP server for network diagnostics providing tools like ping, DNS lookup, port check, traceroute, speed test, Wake-on-LAN, SSL certificate check, and MAC address lookup.
      8
      MIT

    Appeared in Searches