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 (
"fmt"
"net/http"
"os"
"strings"
@@ -10,15 +9,10 @@ import (
imc "github.com/engigu/taskpool/internal/mcp"
)
// Run 启动 TaskPool MCP Server
// 模式:
// - stdio(默认):通过 stdin/stdout 通信,适用于 Claude Desktop / Cursor 等本地 Agent
// - http:通过 HTTP/SSE 通信,适用于 Hermes / OpenClaw 等远程 Agent
//
// 环境变量:
// TASKPOOL_URL 面板地址,如 http://127.0.0.1:8052 或 https://panel.example.com
// TASKPOOL_TOKEN 设置页 OpenAPI Token
// MCP_HTTP_ADDR HTTP 模式监听地址(默认 :8053)
// Run 启动 TaskPool MCP Serverstdio 模式)
// 环境变量(可选,默认使用本地服务器配置):
// TASKPOOL_URL 面板地址
// TASKPOOL_TOKEN OpenAPI Token
func Run(args []string) {
for _, a := range args {
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)
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()
// 设置外部客户端(用于 stdio 模式连接远程服务器)
// 设置外部客户端(用于连接远程服务器)
if client.Token != "" {
mcp.SetExternalClient(client)
}
if err := mcp.ServeStdio(s); err != nil {
fmt.Fprintf(os.Stderr, "[taskpool-mcp] server 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)
fmt.Fprintf(os.Stderr, "[taskpool-mcp] error: %v\n", err)
os.Exit(1)
}
}
@@ -106,26 +50,22 @@ func maskToken(t string) string {
func printHelp() {
fmt.Fprintf(os.Stderr, `
TaskPool MCP Server(内置模式)
TaskPool MCP Server
MCP Server 已集成到后端服务中,推荐直接使用内置端点
http://your-server:8052/mcp
MCP Server 已内置在后端服务中:
HTTP 端点: http://your-server:8052/mcp
此命令用于
- stdio 模式:本地 AgentClaude Desktop / Cursor
- 独立 HTTP 服务:需要单独端口时
此命令用于 stdio 模式(Claude Desktop / Cursor 等)。
用法:
taskpool mcp # stdio 模式
taskpool mcp --http # HTTP 模式,监听 :8053
taskpool mcp --http :9000 # HTTP 模式,指定端口
taskpool mcp
环境变量(stdio 模式可选):
TASKPOOL_URL 面板地址(默认本机)
环境变量(可选):
TASKPOOL_URL 面板地址(默认使用本机)
TASKPOOL_TOKEN OpenAPI Token(默认从系统设置读取)
Agent 配置示例:
HTTP 模式(推荐:
Agent 配置:
HTTP 模式(Hermes / OpenClaw:
{
"mcpServers": {
"taskpool": {
@@ -137,7 +77,7 @@ Agent 配置示例:
}
}
stdio 模式:
stdio 模式Claude Desktop / Cursor:
{
"mcpServers": {
"taskpool": {