Portainer MCP HTTP服务器
这只是一个包装 便携式mcp 它允许您通过HTTP客户端访问Portainer。
运作原理
┌─────────────────────────────────────────────────────────────────────────────┐
│ YOUR INFRASTRUCTURE │
│ │
│ Kontainer App portainer-mcp-server Portainer │
│ (your phone) (your server) (your server) │
│ │
│ ┌─────────────┐ ┌────────────────────┐ ┌───────────┐ │
│ │ │ HTTPS/SSE │ │ │ │ │
│ │ Connect │───────────────▶│ Receive requests │─────▶│ Docker │ │
│ │ │ │ Forward to MCP │ │ Swarm │ │
│ │ Control │◀───────────────│ Return results │◀─────│ K8s │ │
│ │ │ Responses │ │ │ │ │
│ └─────────────┘ └────────────────────┘ └───────────┘ │
│ │
│ ● Your data stays on your servers │
│ ● Your credentials never leave your infrastructure │
│ ● No third-party services involved │
│ │
└─────────────────────────────────────────────────────────────────────────────┘数据流
- 您运行服务器 在您的机器/Portainer旁边的VPS上
- 应用程序连接 通过密码身份验证连接到您的服务器
- 服务器转发 通过MCP向Portainer发出请求
- 结果返回 直接到您的应用程序
您的Portainer API令牌和密码永远不会离开您的基础设施。
安装
选项1:自动安装脚本
# Install latest version (v0.7.0)
curl -fsSL https://raw.githubusercontent.com/1buck/portainer-mcp-http-server/main/install.sh | bash
# Install specific version
curl -fsSL https://raw.githubusercontent.com/1buck/portainer-mcp-http-server/main/install.sh | bash -s -- --version v0.7.0
# Show all options
curl -fsSL https://raw.githubusercontent.com/1buck/portainer-mcp-http-server/main/install.sh | bash -s -- --help______________________________________________________________________
选项2:Docker(推荐)
docker run -d \
-p 8080:8080 \
-e PORTAINER_URL=https://portainer.example.com \
-e PORTAINER_TOKEN=your-token \
-e MCP_PASSWORD=your-password \
-e MCP_BASE_URL=192.168.1.50:8080 \
-e MCP_READ_ONLY=false \
-e MCP_DEBUG=false \
ghcr.io/1buck/portainer-mcp-server:latest______________________________________________________________________
选项3:Docker Compose(推荐)
version: '3.8'
services:
portainer-mcp-server:
image: ghcr.io/1buck/portainer-mcp-server:latest
ports:
- "8080:8080"
environment:
- PORTAINER_URL=https://portainer.example.com
- PORTAINER_TOKEN=your-token
- MCP_PASSWORD=your-password
- MCP_BASE_URL=192.168.1.50:8080
- MCP_READ_ONLY=false
- MCP_DEBUG=false
- MCP_SKIP_VERSION_CHECK=false______________________________________________________________________
选项4:从源代码构建
git clone https://github.com/1buck/portainer-mcp-http-server.git
cd portainer-mcp-http-server
go build -o portainer-mcp-server .用法
二进制
二进制是 独立的 -它会自动提取并使用捆绑的 portainer-mcp 二进制在支持的平台上。
# Basic usage
./portainer-mcp-server \
-portainer-url http://localhost:9000 \
-portainer-token YOUR_TOKEN \
-password YOUR_PASSWORD \
-base-url 192.168.1.50:8080
# All options
./portainer-mcp-server \
-portainer-url http://localhost:9000 \
-portainer-token YOUR_TOKEN \
-password YOUR_PASSWORD \
-listen :8080 \
-base-url 192.168.1.50:8080 \
-mcp-path /usr/local/bin/portainer-mcp \
-read-only false \
-skip-version-check false \
-debug false \
-use-http false二进制分辨率: 服务器将:
- 使用捆绑的
portainer-mcp二进制(自动提取到临时目录) - 返回到搜索PATH
portainer-mcp如果捆绑的二进制文件不可用 - 如果满足以下条件,请使用显式路径
-mcp-path提供标志
Docker/Docker编写
环境变量映射到标志:
| 环境变量 | 标志 | 示例 | 默认值 |
|---|---|---|---|
PORTAINER_URL | -portainer-url | http://portainer:9000 | (必填) |
PORTAINER_TOKEN | -portainer-token | 您的API令牌 | (必需) |
MCP_PASSWORD | -password | 您的密码 | (必填) |
MCP_BASE_URL | -base-url | 192.168.1.50:8080 | 自动检测 |
MCP_LISTEN | -listen | :8080 | :8080 |
MCP_PATH | -mcp-path | /usr/local/bin/portainer-mcp | portainer-mcp |
MCP_READ_ONLY | -read-only | true 或 false | false |
MCP_SKIP_VERSION_CHECK | -skip-version-check | true 或 false | false |
MCP_DEBUG | -debug | true 或 false | false |
MCP_USE_HTTP | -use-http | true 或 false | false |
配置
所需标志
| 标志 | 描述 | 示例 |
|---|---|---|
-portainer-url | 您的门户URL | portainer.example.com 或 192.168.1.100:9443 |
-portainer-token | Portainer API令牌 | 从Portainer获取→ 设置→ API令牌 |
-password | 应用程序身份验证密码 | 您选择的任何密码 |
可选标志
| 标志 | 描述 | 默认值 | 环境变量 |
|---|---|---|---|
-listen | 服务器侦听地址 | :8080 | MCP_LISTEN |
-base-url | QR码和SSE的公共URL (例如。, 192.168.1.100:8080、主机名或完整URL) | 从主机名自动检测 | MCP_BASE_URL |
-mcp-path | portainer mcp二进制文件的路径 | portainer-mcp | MCP_PATH |
-read-only | 禁用写入操作 | false | MCP_READ_ONLY |
-skip-version-check | 跳过Portainer版本检查 | false | MCP_SKIP_VERSION_CHECK |
-debug | 启用调试日志记录 | false | MCP_DEBUG |
-use-http | 使用HTTP而不是HTTPS(仅限开发人员) | false | MCP_USE_HTTP |
从Kontainer应用程序连接
- 启动服务器
- 在Kontainer应用程序中
- 转到实例设置屏幕 - 扫描控制台生成的二维码或手动输入网址和密码
- 测试并保存连接
下载移动应用程序
- 安卓:https://play.google.com/store/apps/details?id=com.devculi.kontainer
- 网间网操作系统:https://apps.apple.com/us/app/portainer/id6742278087
Nginx代理配置
✅ 更新(v0.7.0):服务器现在自动处理nginx兼容性!
服务器发送 X-Accel-Buffering: no 头和SSE心跳(间隔30s),告诉nginx:
- 自动禁用SSE流的缓冲
- 通过nginx空闲超时保持连接活动
无需更改nginx配置 对于大多数nginx代理设置。只需在nginx后面部署服务器,它就应该可以工作了。
当你仍然需要手动Nginx配置时
如果在部署v0.7.1+后仍然遇到连接问题,请将此添加到Nginx代理管理器的 高级 选项卡:
为什么需要它
SSE连接需要:
- 无缓冲 -事件必须立即流式传输,而不是批处理
- 长时间超时 -连接长时间保持打开状态
- HTTP/1.1 -分块传输编码所需
Nginx代理设置
在Nginx Proxy中,将以下内容添加到您的代理主机:
# SSE endpoint - CRITICAL for streaming
location /sse {
proxy_pass http://YOUR_BACKEND_IP:PORT;
# MUST HAVE - Disable buffering for SSE
proxy_buffering off;
proxy_cache off;
proxy_max_temp_file_size 0;
# MUST HAVE - HTTP/1.1 for streaming
proxy_http_version 1.1;
proxy_set_header Connection '';
# Standard headers
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# MUST HAVE - Prevent timeout (24 hours)
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
# Clean chunk handling
chunked_transfer_encoding off;
}
# Message endpoint - normal timeout OK
location /mcp/message {
proxy_pass http://YOUR_BACKEND_IP:PORT;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Normal timeout for RPC calls
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
# Connect endpoint (for testing)
location /connect {
proxy_pass http://YOUR_BACKEND_IP:PORT;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}常见问题
| 问题 | 原因 | 修复 |
|---|---|---|
| 60秒后连接关闭 | 默认值 proxy_read_timeout | 设置为 86400s |
| 事件不流式传输 | proxy_buffering on (默认) | 设置 proxy_buffering off |
| “无效会话”错误 | SSE关闭,会话无效 | 修复超时+缓冲 |
| 双块错误 | Nginx重新编码块 | 设置 chunked_transfer_encoding off |
许可证
麻省理工学院
