Files
gin-vue-admin/server/mcp/server.go
T
PiexlMax(奇淼 375b21c222 发布2.9.1版本 (#2189)
* feat: mcp能力调整为 streamhttp的独立服务 不再依赖gva本体

* feat: 增加MCP启动能力,增加AI工作流需求整理能力。

* feat: 增加需求梳理能力

* feat: 清理无用日志

* feat: 移除无用的Dify Chatflow文本和代码生成器按钮
2026-03-27 12:14:13 +08:00

53 lines
1010 B
Go

package mcpTool
import (
"net/http"
"strings"
"github.com/flipped-aurora/gin-vue-admin/server/global"
mcpServer "github.com/mark3labs/mcp-go/server"
)
func NewMCPServer() *mcpServer.MCPServer {
config := global.GVA_CONFIG.MCP
s := mcpServer.NewMCPServer(
config.Name,
config.Version,
)
global.GVA_MCP_SERVER = s
RegisterAllTools(s)
return s
}
func NewStreamableHTTPServer() *mcpServer.StreamableHTTPServer {
config := global.GVA_CONFIG.MCP
path := config.Path
if path == "" {
path = "/mcp"
}
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
mux := http.NewServeMux()
httpSrv := &http.Server{
Handler: mux,
}
handler := mcpServer.NewStreamableHTTPServer(
NewMCPServer(),
mcpServer.WithHTTPContextFunc(WithHTTPRequestContext),
mcpServer.WithStreamableHTTPServer(httpSrv),
)
mux.Handle(path, handler)
mux.HandleFunc("/health", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("ok"))
})
return handler
}