refactor(mcp): remove standalone HTTP mode, keep only built-in endpoint and stdio
Build and Deploy / build-and-push (push) Successful in 54s

- MCP Server is now only available via built-in /mcp endpoint or stdio
- Remove --http flag and standalone HTTP server code
- Simplify documentation and frontend settings
This commit is contained in:
2026-07-27 02:52:46 +08:00
parent f3a44a901e
commit bcf7cbbeea
3 changed files with 30 additions and 168 deletions
+17 -77
View File
@@ -2,7 +2,6 @@ package mcp
import ( import (
"fmt" "fmt"
"net/http"
"os" "os"
"strings" "strings"
@@ -10,15 +9,10 @@ import (
imc "github.com/engigu/taskpool/internal/mcp" imc "github.com/engigu/taskpool/internal/mcp"
) )
// Run 启动 TaskPool MCP Server // Run 启动 TaskPool MCP Serverstdio 模式)
// 模式: // 环境变量(可选,默认使用本地服务器配置):
// - stdio(默认):通过 stdin/stdout 通信,适用于 Claude Desktop / Cursor 等本地 Agent // TASKPOOL_URL 面板地址
// - http:通过 HTTP/SSE 通信,适用于 Hermes / OpenClaw 等远程 Agent // TASKPOOL_TOKEN OpenAPI Token
//
// 环境变量:
// TASKPOOL_URL 面板地址,如 http://127.0.0.1:8052 或 https://panel.example.com
// TASKPOOL_TOKEN 设置页 OpenAPI Token
// MCP_HTTP_ADDR HTTP 模式监听地址(默认 :8053)
func Run(args []string) { func Run(args []string) {
for _, a := range args { for _, a := range args {
if a == "-h" || a == "--help" { if a == "-h" || a == "--help" {
@@ -27,68 +21,18 @@ func Run(args []string) {
} }
} }
mode := "stdio"
httpAddr := ":8053"
for i, a := range args {
if a == "--http" {
mode = "http"
if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
httpAddr = args[i+1]
}
}
}
if envAddr := os.Getenv("MCP_HTTP_ADDR"); envAddr != "" {
httpAddr = envAddr
}
if mode == "http" {
runHTTP(httpAddr)
} else {
runStdio()
}
}
func runStdio() {
// 使用内部 OpenAPI 客户端(自动获取服务器地址和 Token) // 使用内部 OpenAPI 客户端(自动获取服务器地址和 Token)
client := imc.GetOpenAPIClient() client := imc.GetOpenAPIClient()
fmt.Fprintf(os.Stderr, "[taskpool-mcp] mode=stdio url=%s token=%s\n", client.BaseURL, maskToken(client.Token)) fmt.Fprintf(os.Stderr, "[taskpool-mcp] stdio mode, url=%s token=%s\n", client.BaseURL, maskToken(client.Token))
s := mcp.GetServer() s := mcp.GetServer()
// 设置外部客户端(用于 stdio 模式连接远程服务器) // 设置外部客户端(用于连接远程服务器)
if client.Token != "" { if client.Token != "" {
mcp.SetExternalClient(client) mcp.SetExternalClient(client)
} }
if err := mcp.ServeStdio(s); err != nil { if err := mcp.ServeStdio(s); err != nil {
fmt.Fprintf(os.Stderr, "[taskpool-mcp] server error: %v\n", err) fmt.Fprintf(os.Stderr, "[taskpool-mcp] error: %v\n", err)
os.Exit(1)
}
}
func runHTTP(addr string) {
client := imc.GetOpenAPIClient()
fmt.Fprintf(os.Stderr, "[taskpool-mcp] mode=http addr=%s url=%s token=%s\n", addr, client.BaseURL, maskToken(client.Token))
// 设置外部客户端
if client.Token != "" {
mcp.SetExternalClient(client)
}
handler := mcp.GetHTTPHandler()
// 添加健康检查端点
mux := http.NewServeMux()
mux.Handle("/mcp/", http.StripPrefix("/mcp", handler))
mux.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{"status":"ok"}`))
})
fmt.Fprintf(os.Stderr, "[taskpool-mcp] MCP endpoint: http://%s/mcp\n", strings.TrimPrefix(addr, ":"))
if err := http.ListenAndServe(addr, mux); err != nil {
fmt.Fprintf(os.Stderr, "[taskpool-mcp] http server error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
} }
@@ -106,26 +50,22 @@ func maskToken(t string) string {
func printHelp() { func printHelp() {
fmt.Fprintf(os.Stderr, ` fmt.Fprintf(os.Stderr, `
TaskPool MCP Server(内置模式) TaskPool MCP Server
MCP Server 已集成到后端服务中,推荐直接使用内置端点 MCP Server 已内置在后端服务中:
http://your-server:8052/mcp HTTP 端点: http://your-server:8052/mcp
此命令用于 此命令用于 stdio 模式(Claude Desktop / Cursor 等)。
- stdio 模式:本地 AgentClaude Desktop / Cursor
- 独立 HTTP 服务:需要单独端口时
用法: 用法:
taskpool mcp # stdio 模式 taskpool mcp
taskpool mcp --http # HTTP 模式,监听 :8053
taskpool mcp --http :9000 # HTTP 模式,指定端口
环境变量(stdio 模式可选): 环境变量(可选):
TASKPOOL_URL 面板地址(默认本机) TASKPOOL_URL 面板地址(默认使用本机)
TASKPOOL_TOKEN OpenAPI Token(默认从系统设置读取) TASKPOOL_TOKEN OpenAPI Token(默认从系统设置读取)
Agent 配置示例: Agent 配置:
HTTP 模式(推荐: HTTP 模式(Hermes / OpenClaw:
{ {
"mcpServers": { "mcpServers": {
"taskpool": { "taskpool": {
@@ -137,7 +77,7 @@ Agent 配置示例:
} }
} }
stdio 模式: stdio 模式Claude Desktop / Cursor:
{ {
"mcpServers": { "mcpServers": {
"taskpool": { "taskpool": {
+12 -86
View File
@@ -14,17 +14,17 @@ TaskPool 提供官方 **MCP Server**,让 Hermes、OpenClaw、Cursor 等 AI Age
## 内置 MCP 端点 ## 内置 MCP 端点
MCP Server 已**内置在后端服务中**,无需单独启动进程。启用 OpenAPI 后,MCP 端点自动可用: MCP Server 已**内置在后端服务中**,无需单独进程。启用 OpenAPI 后,MCP 端点自动可用:
``` ```
http://your-server:8052/mcp http://your-server:8052/mcp
``` ```
## Agent 配置示例 ## Agent 配置
### HTTP 模式(推荐) ### HTTP 模式(推荐)
远程 Agent 直接访问内置端点,无需本地安装二进制 远程 Agent 直接访问内置端点,无需本地安装。
```json ```json
{ {
@@ -39,98 +39,24 @@ http://your-server:8052/mcp
} }
``` ```
适用于:Hermes、OpenClaw 等支持 HTTP URL 的 Agent。
### stdio 模式 ### stdio 模式
本地 Agent 需要安装 `taskpool` 二进制Claude Desktop、Cursor 本地 Agent 需要安装 `taskpool` 二进制。
```bash
export TASKPOOL_URL=http://your-server:8052
export TASKPOOL_TOKEN=你的OpenAPI_Token
taskpool mcp
```
Agent 配置:
```json ```json
{ {
"mcpServers": { "mcpServers": {
"taskpool": { "taskpool": {
"command": "taskpool", "command": "taskpool",
"args": ["mcp"], "args": ["mcp"]
"env": {
"TASKPOOL_URL": "http://your-server:8052",
"TASKPOOL_TOKEN": "你的OpenAPI_Token"
}
} }
} }
} }
``` ```
### 独立 HTTP 服务模式(可选) 适用于:Claude Desktop、Cursor 等只支持 stdio 的本地 Agent。
如果需要单独部署 MCP 服务(如不同的端口或机器):
```bash
# 监听默认端口 :8053
taskpool mcp --http
# 指定端口
taskpool mcp --http :9000
# 或通过环境变量
export MCP_HTTP_ADDR=:8053
taskpool mcp --http
```
独立模式暴露端点:
- `POST /mcp` - MCP 协议端点
- `GET /health` - 健康检查
## Agent 配置示例
### stdio 模式(Claude Desktop / Cursor
```json
{
"mcpServers": {
"taskpool": {
"command": "taskpool",
"args": ["mcp"],
"env": {
"TASKPOOL_URL": "http://127.0.0.1:8052",
"TASKPOOL_TOKEN": "替换为设置页 Token"
}
}
}
}
```
若二进制不在 PATH
```json
{
"command": "/path/to/taskpool",
"args": ["mcp"],
"env": {
"TASKPOOL_URL": "https://你的面板地址",
"TASKPOOL_TOKEN": "xxx"
}
}
```
### HTTP 模式(Hermes / OpenClaw
```json
{
"mcpServers": {
"taskpool": {
"url": "http://your-server:8053/mcp"
}
}
}
```
Docker 部署时,把 `TASKPOOL_URL` 写成 Agent 能访问的地址(宿主机映射端口或内网域名)。
## 工具清单(Tools ## 工具清单(Tools
@@ -197,7 +123,7 @@ Skill 是说明书;**真正执行依赖 MCP Tools**。两者一起用效果最
| 现象 | 处理 | | 现象 | 处理 |
|------|------| |------|------|
| `TASKPOOL_TOKEN 未配置` | 设置 env 或配置里的 Token | | `OpenAPI Token 未配置` | 设置页启用 OpenAPI 并生成 Token |
| `无效的 OpenAPI 令牌` | 设置页启用 OpenAPI 并重新生成 | | `无效的 OpenAPI 令牌` | 设置页重新生成 Token |
| 连接失败 | 检查 `TASKPOOL_URL`、防火墙、容器网络 | | 连接失败 | 检查服务器地址、防火墙、容器网络 |
| Agent 看不到 tools | 确认 `command` 路径正确,重启 Agent Gateway | | Agent 看不到 tools | 确认配置正确,Token 有效 |
+1 -5
View File
@@ -322,11 +322,7 @@ export default function Settings() {
"mcpServers": { "mcpServers": {
"taskpool": { "taskpool": {
"command": "taskpool", "command": "taskpool",
"args": ["mcp"], "args": ["mcp"]
"env": {
"TASKPOOL_URL": "${window.location.origin}",
"TASKPOOL_TOKEN": "${siteForm.openapi_token || '在设置页生成 Token'}"
}
} }
} }
}`}</pre> }`}</pre>