feat(mcp): integrate MCP Server into backend service as built-in endpoint
Build and Deploy / build-and-push (push) Successful in 54s
Build and Deploy / build-and-push (push) Successful in 54s
- Add MCP Controller and register /mcp route - MCP Server now uses OpenAPI Token for authentication - Update frontend settings to show built-in MCP endpoint config - Update docs to reflect integrated MCP endpoint
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"github.com/engigu/taskpool/internal/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// initMCPRoutes 初始化 MCP Server 路由
|
||||
// 使用 OpenAPI Token 进行鉴权
|
||||
func initMCPRoutes(root *gin.RouterGroup, c *Controllers) {
|
||||
// MCP 路由组 (使用 Bearer Token 鉴权,复用 OpenAPI 中间件)
|
||||
mcp := root.Group("/mcp")
|
||||
mcp.Use(middleware.OpenapiRequired())
|
||||
{
|
||||
// 所有 MCP 请求都通过同一个 handler 处理
|
||||
// StreamableHTTP 协议支持 POST 和 GET
|
||||
mcp.POST("/*action", c.MCP.HandleMCP)
|
||||
mcp.GET("/*action", c.MCP.HandleMCP)
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@ func RegisterControllers() *Controllers {
|
||||
Interconnect: controllers.NewInterconnectController(interconnectService),
|
||||
Data: controllers.NewDataController(taskController, envController),
|
||||
Install: controllers.NewInstallController(),
|
||||
MCP: controllers.NewMCPController(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ type Controllers struct {
|
||||
Interconnect *controllers.InterconnectController
|
||||
Data *controllers.DataController
|
||||
Install *controllers.InstallController
|
||||
MCP *controllers.MCPController
|
||||
}
|
||||
|
||||
func Setup(c *Controllers) *gin.Engine {
|
||||
@@ -79,6 +80,9 @@ func Setup(c *Controllers) *gin.Engine {
|
||||
initAgentAPIRoutes(root, c)
|
||||
initOpenAPIV1Routes(root, c)
|
||||
|
||||
// 5. [ location /mcp ] MCP Server 路由(供 AI Agent 使用)
|
||||
initMCPRoutes(root, c)
|
||||
|
||||
// =========================================================================
|
||||
// [ location / ] 全局 404 兜底与 SPA 渲染
|
||||
// 对应 Nginx: try_files $uri $uri/ /index.html;
|
||||
|
||||
Reference in New Issue
Block a user