使用说明
🐳 Docker资源管理器MCP服务器
📋 概述
Docker Explorer是一个功能强大的模型上下文协议(MCP)服务器,它提供了与Docker映像、容器和注册表交互的工具和资源。该服务器使Claude等AI助手能够通过标准化的界面搜索、分析Docker资源并与之交互,从而使容器管理和探索更容易访问。
✨ 特性
核心功能
- 跨注册表搜索Docker镜像
- 搜索Docker镜像的特定标签
- 搜索Docker Hub用户/组织
- 获取Docker镜像的详细元数据
- 分析Dockerfile内容
- 比较Docker镜像
高级工具
- 🔒 安全扫描仪:分析Docker镜像中的已知漏洞和安全问题
- 📦 图像大小优化器:获取减小Docker镜像大小的建议
- 📄 Docker编写生成器:为您的应用程序生成docker-compose.yml文件
- 📊 容器运行时分析器:了解容器运行时行为和资源使用情况
- 🔍 图像比较工具:比较两个Docker镜像并突出它们的差异
- 📜 Dockerfile生成器:根据自然语言应用程序描述创建Dockerfiles
🚀 安装
先决条件
- Python 3.10或更高版本
- MCP Python SDK
- 所需的Python包:
requests,pydantic
设置
- 克隆此存储库:
git clone https://github.com/yourusername/docker-mcp-server.git
cd docker-mcp-server
- 创建虚拟环境:
python -m venv .venv310
source .venv310/bin/activate # On Windows: .venv310\Scripts\activate
- 安装依赖项:
pip install -r requirements.txt
或者安装单独的软件包:
pip install anthropic-mcp requests pydantic
💻 用法
运行服务器
您可以直接从命令行运行服务器:
python docker_explorer.py
这将在默认端口(5000)上启动MCP服务器。
与Claude Desktop集成
要将Docker Explorer MCP服务器与Claude Desktop一起使用:
- 更新Claude Desktop配置:
- 打开或创建
claude_desktop_config.jsonClaude Desktop配置目录中的文件 - 添加Docker Explorer服务器配置
- 打开或创建
{
"mcp_servers": [
{
"name": "docker-explorer",
"command": ["python", "/path/to/mcpIS421/docker_explorer.py"],
"cwd": "/path/to/mcpIS421"
}
]
}
- 重新启动克劳德桌面 加载新配置
使用工具
一旦与Claude Desktop集成,您可以通过向Claude提出以下问题来使用Docker Explorer工具:
核心工具
-
搜索Docker镜像:
Can you search for Python Docker images? -
获取图像详细信息:
What are the details of the python:3.11-slim image? -
查找可用标签:
What tags are available for the nginx image?
高级工具
-
安全扫描仪:
Scan the security of the nginx image -
图像大小优化器:
How can I reduce the size of my python:3.9 image? -
Docker编写生成器:
Generate a docker-compose file for nginx with port 8080:80 -
容器运行时分析器:
Analyze the runtime behavior of mysql:5.7 as a database
👷 发展
项目结构
docker-explorer-mcp/
├── docker_explorer.py # Main server implementation with all tools
├── requirements.txt # Project dependencies
├── .gitignore # Git ignore file
└── docs/ # Documentation
├── server_guide.md # Guide for setting up and using the server
├── new_tools_suggestions.md # Ideas for additional tools
└── docker_mcp_server_project.md # Project overview
添加新功能
要向Docker Explorer MCP服务器添加新工具,请执行以下操作:
- 在中实现工具功能
docker_explorer.py使用MCP工具装饰器:
@mcp.tool()
def my_new_tool(
param1: str = Field(description="Description of param1"),
param2: int = Field(default=10, description="Description of param2")
) -> str:
"""Description of what your tool does"""
try:
# Implementation logic here
result = f"Your formatted result"
return result
except Exception as e:
return f"Error in my_new_tool: {str(e)}"
- 遵循以下工具实施的最佳实践:
- 保持输出简洁,并为Claude Desktop格式化
- 优雅地处理异常
- 提供清晰的参数描述
- 返回结构良好的结果
测试
-
手动测试:
- 运行服务器:
python docker_explorer.py - 通过提问相关问题与Claude Desktop进行测试
- 运行服务器:
-
调试:
- 检查终端输出是否有任何错误
- 在Claude Desktop中验证工具响应
- 如果Claude有容量限制,请调整输出格式
📚 API文档
核心工具
search_images
- 描述:跨注册表搜索Docker镜像
- 参数:
query(string):Docker镜像搜索查询limit(整数,默认值=10):返回的最大结果数
- 退货:带有元数据的Docker镜像列表
search_tags
- 描述:搜索Docker镜像的特定标签
- 参数:
image_name(string):Docker镜像的名称tag_pattern(string,默认值=“”):用于匹配标签的模式limit(整数,默认值=25):要返回的最大结果数
- 退货:匹配标签列表
get_image_details
- 描述:获取Docker镜像的详细信息
- 参数:
image_name(string):Docker镜像的名称tag(string,default=“latest”):Docker镜像的标签
- 退货:详细的图像信息
高级工具
scan_security
- 描述:分析Docker镜像中的已知漏洞和安全问题
- 参数:
image_name(string):Docker镜像的名称tag(string,default=“latest”):要扫描的Docker镜像的标签
- 退货:附有建议的安全分析报告
optimize_image_size
- 描述:分析Docker镜像并建议减小其大小的方法
- 参数:
repository_url(string):Docker Hub仓库的完整URLtag(string,default=“latest”):要分析的Docker镜像的标签
- 退货:尺寸优化建议
generate_docker_compose
- 描述:基于图像生成docker-compose.yml文件
- 参数:
repository_url(string):Docker Hub仓库的完整URLtag(string,default=“latest”):Docker镜像的标签port_mapping(string,默认值=“”):可选端口映射(例如,'8080:80')environment_variables(string,默认值=“”):可选环境变量include_db(boolean,default=false):是否包含数据库服务
- 退货:生成的docker-compose.yml内容
analyze_runtime
- 描述:分析容器在运行时的行为方式
- 参数:
image_name(string):Docker镜像的名称tag(string,default=“latest”):Docker镜像的标签app_type(string,默认值=“web”):应用程序类型(web、数据库、缓存、api、批处理)
- 退货:运行时分析,包括资源使用预测和建议
compare_images
- 描述:比较两个Docker镜像并突出显示差异
- 参数:
image1(string):第一个要比较的Docker镜像(例如,'nginx:1.21'或'user/report:tag')image2(string):要比较的第二个Docker镜像(例如,'nginx:1.22'或'user/report:tag')
- 退货:详细的比较报告,突出大小、层次、配置和兼容性的差异
generate_dockerfile
- 描述:根据自然语言描述的应用程序需求生成一个Dockerfile
- 参数:
app_description(string):容器化应用程序的描述(例如,“带Redis的Python Flask web应用程序”)app_type(string,默认值=“web”):应用程序类型(web、api、数据库、worker、静态)base_image(string,default=“”):要使用的可选基础映像(例如,“python:3.9 alpine”)include_comments(boolean,default=true):是否在Dockerfile中包含解释性注释
- 退货:生成带有使用说明的Dockerfile
🔒 安全考虑
Docker Explorer MCP服务器专为教育和开发目的而设计。使用时:
- 不要公开敏感凭据或API密钥
- 生成和运行Docker Compose文件时要小心
- 在实施之前,始终审查安全建议
📌 许可证
麻省理工学院
👥 贡献
欢迎投稿!请随时提交带有新工具或现有功能改进的Pull Request。