Initial commit

This commit is contained in:
2026-04-07 09:03:48 +08:00
commit c9ffb52b7f
713 changed files with 111641 additions and 0 deletions

52
server/mcp/server.go Normal file
View File

@@ -0,0 +1,52 @@
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
}