I

ITMCP工具(安全网络管理MCP服务器)

@andrewhopper/itmcp
0 Stars 30 次浏览 andrewhopper 更新于 2026-08-23

安全的网络管理MCP服务器, enables人工智能助手在Docker容器沙箱中安全地执行SSH、ping和DNS查询等网络命令。请注意,原文中的“enables”在这里需要根据上下文调整为合适的中文表述,比如“使得”或“让”:“安全的网络管理MCP服务器,使得人工智能助手在Docker容器沙箱中能够安全地执行SSH、ping和DNS查询等网络命令。”

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

ITMCP

通过 Model Context Protocol (MCP) 为 AI 助手提供安全的网络管理工具。

概述

ITMCP 是一个 MCP 服务器,它使 AI 助手能够在 Docker 容器沙箱中安全地执行网络命令。它提供了运行常见的网络诊断和管理工具的安全接口,同时保持严格的安全控制。

该项目实现了 Model Context Protocol (MCP),将网络工具作为可调用函数暴露给 AI 助手,允许它们在一个受控环境中执行网络诊断和系统管理任务。

特性

  • Docker 隔离:所有命令都在沙箱化的 Docker 容器中运行,以增强安全性
  • 安全控制:全面的主机、目录和命令白名单
  • 网络诊断工具:SSH、ping、nslookup、telnet、dig、tcpdump 等
  • 文件操作:使用 cat、grep、head、tail 等工具安全地查看和分析文件
  • 进程管理:使用 ps 和 top 工具查看正在运行的进程
  • 凭证管理:安全处理 SSH 密钥和密码
  • MCP 集成:与 Model Context Protocol 全面兼容
  • 企业级安全:会话管理、审计日志和访问控制

安装

前提条件

  • Python 3.10 或更高版本
  • Docker(用于容器化执行)
  • MCP 库(版本 1.0.0 或更高)

基本安装

  1. 克隆仓库:

    git clone https://github.com/yourusername/itmcp.git
    cd itmcp
    
  2. 安装依赖项:

    pip install -e .
    

Docker 设置

  1. 构建 Docker 容器:

    docker build -t itmcp_container .
    
  2. 运行容器:

    docker-compose up -d
    

配置

ITMCP 使用基于 YAML 的配置系统和环境变量进行设置。

环境变量

在项目根目录下创建一个 .env 文件,并添加以下变量:

# Docker configuration
USE_DOCKER=true
DOCKER_CONTAINER=itmcp_container

# SSH credentials configuration
SSH_CREDENTIALS_PATH=/app/secrets/ssh_credentials.json
SSH_KEYS_PATH=/app/secrets/keys

# Security whitelists
ALLOWED_HOSTS=localhost,127.0.0.1,example.com
ALLOWED_DIRECTORIES=/tmp,/var/log
ALLOWED_REMOTE_COMMANDS=ls,cat,grep

安全白名单

ITMCP 实现了三个关键的白名单以确保安全:

  1. 允许的主机:限制网络工具可以针对的目标主机
  2. 允许的目录:限制文件系统访问到特定目录
  3. 允许的远程命令:控制可以远程执行的命令

可用工具

ITMCP 提供了以下网络管理工具:

工具 描述
ssh_tool 通过 SSH 连接到目标
ping_tool Ping 主机以检查连通性
nslookup_tool 对主机名或 IP 地址执行 DNS 查询
telnet_tool 测试到主机和端口的 TCP 连通性
dig_tool 使用 dig 命令执行 DNS 查询
tcpdump_tool 捕获网络数据包(限时)
ps_tool 列出正在运行的进程
cat_tool 显示文件内容
top_tool 显示系统进程(快照)
grep_tool 在文件中搜索模式
head_tool 显示文件开头部分
tail_tool 显示文件末尾部分

安全特性

ITMCP 实现了企业级的安全特性:

会话管理

  • 使用加密令牌创建安全会话
  • 会话过期和超时控制
  • 并发会话限制
  • 会话验证和重新生成

审计日志

  • 全面的命令日志记录
  • 所有操作的用户归属
  • 成功/失败日志记录
  • 安全事件标记
  • 防篡改日志

访问控制

  • 命令白名单
  • 目录限制
  • 主机限制
  • 输入验证和清理

Docker 集成

ITMCP 使用 Docker 创建一个安全沙箱用于命令执行:

  1. 所有命令都通过 Docker 容器路由
  2. 容器对宿主系统的访问权限有限
  3. 可以设置资源限制以防止滥用
  4. 网络隔离提供了额外的安全层

使用示例

MCP 配置

Claude 桌面配置

要使用 ITMCP 与 Claude 桌面,向您的 config.json 文件添加以下内容:

{
  "servers": [
    {
      "name": "itmcp",
      "command": ["python", "-m", "itmcp.server"],
      "environment": {
        "USE_DOCKER": "true",
        "DOCKER_CONTAINER": "itmcp_container",
        "ALLOWED_HOSTS": "localhost,127.0.0.1,yahoo.com,firewall.local"
      }
    }
  ]
}

Cline 配置

对于 Cline AI,在此仓库提供的 mcp-config.json 文件中有更详细的配置说明:

{
    "servers": [
        {
            "name": "itmcp",
            "command": [
                "python",
                "-m",
                "itmcp.server"
            ],
            "environment": {
                "USE_DOCKER": "true",
                "DOCKER_CONTAINER": "itmcp_container",
                "ALLOWED_HOSTS": "localhost,127.0.0.1,yahoo.com,firewall.local",
                "ALLOWED_DIRECTORIES": "/tmp,/var/log",
                "ALLOWED_REMOTE_COMMANDS": "ls,cat,grep,ping,ssh,nslookup,dig,telnet,tcpdump,ps,top,head,tail"
            },
            "description": "Secure network administration tools running in a Docker sandbox",
            "tools": [
                {
                    "name": "ssh_tool",
                    "description": "Connect to a target via SSH"
                },
                {
                    "name": "ping_tool",
                    "description": "Ping a host to check connectivity"
                },
                {
                    "name": "nslookup_tool",
                    "description": "Perform DNS lookup on a hostname or IP address"
                },
                {
                    "name": "telnet_tool",
                    "description": "Test TCP connectivity to a host and port"
                },
                {
                    "name": "dig_tool",
                    "description": "Perform DNS lookup with dig command"
                },
                {
                    "name": "tcpdump_tool",
                    "description": "Capture network packets (limited time)"
                },
                {
                    "name": "ps_tool",
                    "description": "List running processes"
                },
                {
                    "name": "cat_tool",
                    "description": "Display content of a file"
                },
                {
                    "name": "top_tool",
                    "description": "Display system processes (snapshot)"
                },
                {
                    "name": "grep_tool",
                    "description": "Search for patterns in files"
                },
                {
                    "name": "head_tool",
                    "description": "Display the beginning of a file"
                },
                {
                    "name": "tail_tool",
                    "description": "Display the end of a file"
                }
            ]
        }
    ]
}

要将此配置用于 Cline:

  1. mcp-config.json 文件复制到您的 Cline 配置目录
  2. 使用 --mcp-config 标志指向该文件启动 Cline
  3. ITMCP 工具将在您的 Cline 会话中可用

示例 1:Ping 一个主机

# Using the ping_tool to check connectivity to yahoo.com
<use_mcp_tool>
<server_name>itmcp</server_name>
<tool_name>ping_tool</tool_name>
<arguments>
{
  "target": "yahoo.com",
  "count": 4
}
</arguments>
</use_mcp_tool>

示例 2:SSH 连接到防火墙

# Using the ssh_tool to connect to a firewall and run a command
<use_mcp_tool>
<server_name>itmcp</server_name>
<tool_name>ssh_tool</tool_name>
<arguments>
{
  "target": "firewall.local",
  "user": "admin",
  "command": "show interface status"
}
</arguments>
</use_mcp_tool>

示例 3:DNS 查询

# Using the dig_tool to perform a DNS lookup
<use_mcp_tool>
<server_name>itmcp</server_name>
<tool_name>dig_tool</tool_name>
<arguments>
{
  "target": "yahoo.com",
  "type": "MX"
}
</arguments>
</use_mcp_tool>

贡献

欢迎贡献!请随时提交 Pull Request。

  1. 分叉仓库
  2. 创建你的功能分支 (git checkout -b feature/amazing-feature)
  3. 提交更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开 Pull Request

许可证

本项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。

作者

Andrew Hopper

安全注意事项

ITMCP 在设计时考虑了安全性,但正确的配置是必不可少的:

  • 始终在 Docker 容器中运行以实现隔离
  • 仔细配置主机、目录和命令的白名单
  • 定期审查审计日志以发现可疑活动
  • 保持系统更新,安装安全补丁
  • 遵循文档中的安全最佳实践