MCP 网络连通性测试服务(Python)
该服务提供在模型调试与运维排障场景中常用的网络连通性测试能力:TCP 连通检查、次数统计的“TCP ping”、DNS 解析以及系统 ping。
安装
- 从源码:
pip install -r requirements.txt
- 从 PyPI(发布后):
pip install mcp-network-tester
建议使用虚拟环境。
运行(命令行)
安装后将提供命令 mcp-network-tester,以 stdio 方式启动 MCP 服务器:
mcp-network-tester
运行(配合 MCP Inspector)
- 启动 Inspector:
npx @modelcontextprotocol/inspector - 在 Inspector 中添加自定义服务器:
- Command:
mcp-network-tester
- Command:
- 连接后即可在 Tools 面板看到以下工具:
tcp_check、tcp_ping、dns_resolve、system_ping。
将其接入到支持 MCP 的客户端
以通用配置为例:
{
"mcpServers": {
"fetch": {
"args": [
"-m",
"mcp_network_tester"
],
"command": "python"
}
}
}
工具说明
tcp_check(host: str, port: int, timeout_seconds: float = 2.0)- 单次 TCP 连接测试,返回 JSON 字符串,含
reachable与latency_ms。
- 单次 TCP 连接测试,返回 JSON 字符串,含
tcp_ping(host: str, port: int, count: int = 4, interval_seconds: float = 0.2, timeout_seconds: float = 2.0)- 多次 TCP 连接测试,统计成功率与时延(适合排查本地到 Docker 暴露端口是否可达)。
dns_resolve(host: str)- 解析 A/AAAA 记录,返回所有地址。
system_ping(target: str, count: int = 4, timeout_seconds: float = 2.0, size: int = 32)- 调用系统
ping(Windows 与 Linux/macOS 自动适配)。可能需要权限。
- 调用系统
发布到 PyPI(公共平台)
- 安装构建与发布工具:
pip install build twine
- 构建分发包:
python -m build
生成dist/*.tar.gz与dist/*.whl。 - 上传到 TestPyPI 验证:
twine upload -r testpypi dist/*
- 上传到正式 PyPI:
twine upload dist/*
请在
pyproject.toml中更新作者信息、主页链接等元数据;确保LICENSE为你选择的许可协议(默认 MIT)。版本号按语义化版本管理递增。
注意
system_ping依赖系统命令;若不可用,将返回错误信息。- TCP 检测依赖目标服务监听状态与本机出站规则,失败时请结合 DNS、系统防火墙与容器网络配置综合排查。
Metadata
Release files for mcp-network-tester 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_network_tester-0.1.0.tar.gz | 5.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_network_tester-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / mcp_network_tester-0.1.0.tar.gz
| Download URL | mcp_network_tester-0.1.0.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6024086a351c8b18b5ca3a8a949f4bc6023479a16ae0795b3af2bf5e6fe08a02
|
|
BLAKE2b-256 checksum How to use checksums |
b344c09f36aea353f10bdff5ce39f62db8704116b46da6c8b7ed25ada90525da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / mcp_network_tester-0.1.0-py3-none-any.whl
| Download URL | mcp_network_tester-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69e015d925ad6e1972a6c252aead4cfbf5940981fe1960ccade7764fd90e254a
|
|
BLAKE2b-256 checksum How to use checksums |
3232d4c340690bdccf9dea8910effc76b06cd1289d1c764f346c50f35e049b3e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for mcp-network-tester 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.