fix(router): trust all proxies to fix MCP 'invalid Host header' error
Build and Deploy / build-and-push (push) Successful in 53s

- Set TrustedProxies to nil to allow reverse proxy requests
- Add explicit routes for /mcp without trailing slash
This commit is contained in:
2026-07-27 03:10:24 +08:00
parent 2c9b44aeca
commit 19b3fb60f7
2 changed files with 14 additions and 0 deletions
+9
View File
@@ -14,7 +14,16 @@ func initMCPRoutes(root *gin.RouterGroup, c *Controllers) {
{
// 所有 MCP 请求都通过同一个 handler 处理
// StreamableHTTP 协议支持 POST 和 GET
// 使用 /*action 匹配 /mcp 和 /mcp/ 以及 /mcp/xxx
mcp.POST("/*action", c.MCP.HandleMCP)
mcp.GET("/*action", c.MCP.HandleMCP)
}
// 同时处理 /mcp 根路径(无尾部斜杠)
mcpRoot := root.Group("/mcp")
mcpRoot.Use(middleware.OpenapiRequired())
{
mcpRoot.POST("", c.MCP.HandleMCP)
mcpRoot.GET("", c.MCP.HandleMCP)
}
}
+5
View File
@@ -43,6 +43,11 @@ func Setup(c *Controllers) *gin.Engine {
gin.SetMode(gin.ReleaseMode)
}
router := gin.New()
// 信任所有反向代理(Docker/Nginx 场景)
// 设置为 nil 表示信任所有,避免 "invalid Host header" 错误
router.SetTrustedProxies(nil)
router.Use(middleware.GinLogger(), middleware.GinRecovery())
router.Use(middleware.TravelProxyMiddleware())