🐳 MCP容器工具
](https://pypi.org/project/mcp-container-tools/)   
用于Docker、Kubernetes和Azure Application Insights的模型上下文协议(MCP)服务器,具有高级日志过滤和监控功能。
✨ 特性
- 🐳 码头工人 --容器日志、检查、执行、列出容器
- 🐙 Docker Compose --服务日志,启动/停止/重启服务
- ☸️ 库贝内特斯 --Pod日志、部署日志、事件、exec到Pod
- ☁️ Azure应用洞察 --异常、跟踪、请求、指标
- 🔍 日志筛选 --按日志级别、正则表达式模式、排除模式过滤
- 🌐 远程支持 --通过SSH或TCP连接到远程Docker主机
📋 需求
| 要求 | 版本 | 必需 |
|---|---|---|
| 🐍 Python | 3.11+ | 全部 |
| 🐳 Docker | 最新 | Docker工具 |
| ☸️ kubectl | 最新 | Kubernetes工具 |
| ☁️ Azure CLI | 最新 | Azure工具(可选) |
🚀 安装
📦 快速安装(推荐)
# Basic installation
pip install mcp-container-tools
# With Azure Application Insights support
pip install mcp-container-tools[azure]🐙 从GitHub安装
# Latest version from GitHub
pip install git+https://github.com/simseksem/mcp-container-tools.git
# With Azure support
pip install "mcp-container-tools[azure] @ git+https://github.com/simseksem/mcp-container-tools.git"🔧 从源代码安装(用于开发)
git clone https://github.com/simseksem/mcp-container-tools.git
cd mcp-container-tools
pip install -e ".[all]"✅ 验证安装
mcp-server --help⚙️ 配置
🖥️ 克劳德桌面版
添加到 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"container-tools": {
"command": "/path/to/mcp-container-tools/.venv/bin/python",
"args": ["-m", "mcp_server.server"],
"env": {
"AZURE_LOG_ANALYTICS_WORKSPACE_ID": "your-workspace-id",
"AZURE_APP_INSIGHTS_RESOURCE_ID": "/subscriptions/.../resourceGroups/.../providers/microsoft.insights/components/..."
}
}
}
}💻 克劳德代码
添加到 ~/.claude/settings.json 或创建 .mcp.json 在您的项目中:
{
"mcpServers": {
"container-tools": {
"command": "/path/to/mcp-container-tools/.venv/bin/python",
"args": ["-m", "mcp_server.server"]
}
}
}☁️ Azure身份验证
Azure工具使用 DefaultAzureCredential 它支持:
- Azure命令行界面(
az login) - 环境变量
- 管理身份
- Visual Studio Code
# Easiest: Login with Azure CLI
az login📖 使用示例
🐳 码头工人
# Read container logs
docker_logs(container="my-app", tail=100)
# Read logs from last 30 minutes
docker_logs(container="my-app", since="30m")
# Filter by log level (only errors and above)
docker_logs(container="my-app", min_level="error")
# Search for patterns
docker_logs(container="my-app", pattern="timeout|connection refused")
# Exclude health checks
docker_logs(container="my-app", exclude_pattern="GET /health")
# Remote Docker host via SSH
docker_logs(container="my-app", host="ssh://user@server.com")
# List containers
docker_ps(all=True)🐙 Docker Compose
# Read service logs
compose_logs(service="api", tail=200)
# Read all services logs
compose_logs(project_dir="/path/to/project")
# Service management
compose_up(service="api", project_dir="/path/to/project")
compose_down(project_dir="/path/to/project")
compose_restart(service="api")☸️ 库贝内特斯
# Read pod logs
k8s_logs(pod="api-7d4b8c6f9-x2k4m", namespace="production")
# Read logs from all pods in a deployment
k8s_deployment_logs(deployment="api", namespace="production")
# Filter logs
k8s_logs(pod="api-*", min_level="warn", pattern="database")
# Use different context
k8s_logs(pod="my-pod", context="production-cluster", namespace="backend")
# List pods
k8s_pods(namespace="all", selector="app=api")
# Get events
k8s_events(namespace="production")
# Execute command in pod
k8s_exec(pod="api-xyz", command="printenv", namespace="production")☁️ Azure应用洞察
# Query exceptions from last hour
azure_exceptions(timespan="PT1H", limit=50)
# Get only critical exceptions
azure_exceptions(severity="critical", search="NullReference")
# Query application traces
azure_traces(timespan="PT1H", severity="error")
# Query HTTP requests
azure_requests(timespan="PT1H", failed_only=True)
# Get slow requests (>1 second)
azure_requests(min_duration_ms=1000, limit=20)
# Query external dependencies (SQL, HTTP, etc.)
azure_dependencies(timespan="PT1H", failed_only=True, type_filter="SQL")
# Get metrics
azure_metrics(metric_name="requests/count", timespan="P1D", interval="PT1H")
# Query availability test results
azure_availability(timespan="P1D", failed_only=True)
# Run custom Kusto query
azure_query(query="""
requests
| where success == false
| summarize count() by bin(timestamp, 1h), resultCode
| order by timestamp desc
""", timespan="P1D")🔍 日志筛选选项
所有日志工具都支持这些过滤选项:
| 选项 | 描述 | 示例 | |
|---|---|---|---|
min_level | 最低日志级别 | "error", "warn", "info" | |
pattern | 正则表达式包括 | `"error\ | exception"` |
exclude_pattern | 要排除的正则表达式 | "health.*check" | |
context_lines | 比赛周围的线条 | 5 |
支持的日志级别: trace → debug → info → warn → error → fatal
⏱️ 时间跨度格式(Azure)
Azure工具使用ISO 8601持续时间格式:
| 格式 | 持续时间 |
|---|---|
PT1H | 1小时 |
PT30M | 30分钟 |
P1D | 1天 |
P7D | 7天 |
🛠️ 可用工具
🐳 Docker工具
| 工具 | 说明 |
|---|---|
docker_logs | 📄 通过过滤读取容器日志 |
docker_ps | 📋 列出容器 |
docker_inspect | 🔎 获取容器详细信息 |
docker_exec | ⚡ 在容器中执行命令 |
🐙 Docker编写工具
| 工具 | 说明 |
|---|---|
compose_logs | 📄 读取服务日志 |
compose_ps | 📋 列出服务 |
compose_up | ▶️ 启动服务 |
compose_down | ⏹️ 停止服务 |
compose_restart | 🔄 重新启动服务 |
☸️ Kubernetes工具
| 工具 | 说明 |
|---|---|
k8s_logs | 📄 读取pod日志 |
k8s_deployment_logs | 📚 读取部署日志 |
k8s_pods | 📋 列出Pod |
k8s_describe | 🔎 描述吊舱 |
k8s_exec | ⚡ 在pod中执行 |
k8s_events | 📢 获取活动 |
k8s_contexts | 🌐 列出上下文 |
☁️ Azure应用洞察工具
| 工具 | 说明 |
|---|---|
azure_query | 🔍 运行自定义Kusto查询 |
azure_exceptions | ❌ 查询应用程序异常 |
azure_traces | 📝 查询应用程序跟踪 |
azure_requests | 🌐 查询HTTP请求 |
azure_dependencies | 🔗 查询外部依赖关系 |
azure_metrics | 📊 查询指标 |
azure_availability | ✅ 查询可用性测试 |
👨💻 发展
安装开发依赖项
pip install -e ".[all]"运行测试
pytest过梁和类型检查
ruff check .
mypy src/📁 项目结构
mcp-container-tools/
├── 📂 src/mcp_server/
│ ├── 📄 __init__.py
│ ├── 📄 server.py # Main server entry point
│ ├── 📂 tools/
│ │ ├── 🐳 docker.py # Docker tools
│ │ ├── 🐙 docker_compose.py # Compose tools
│ │ ├── ☸️ kubernetes.py # K8s tools
│ │ ├── ☁️ azure_insights.py # Azure App Insights
│ │ └── 📁 file_operations.py # File tools
│ ├── 📂 resources/
│ │ ├── ⚙️ config.py # Config resources
│ │ └── 📊 data.py # Data resources
│ ├── 📂 prompts/
│ │ └── 📝 templates.py # Prompt templates
│ └── 📂 utils/
│ └── 🔍 log_filter.py # Log filtering
├── 📂 tests/
├── 📄 pyproject.toml
└── 📄 README.md🔐 环境变量
| 变量 | 描述 |
|---|---|
AZURE_LOG_ANALYTICS_WORKSPACE_ID | Azure日志分析工作区ID |
AZURE_APP_INSIGHTS_RESOURCE_ID | Azure应用程序洞察资源ID |
📄 许可证
MIT许可证-请参阅 许可证 了解详情。
______________________________________________________________________
Made with ❤️ for the MCP community
