mirror of
https://gitee.com/fit2cloud-feizhiyun/1Panel.git
synced 2026-11-19 19:34:49 +08:00
feat(mcp): add 1Panel MCP and enhance MCP credential management (#14189)
* feat(mcp): add 1Panel MCP and enhance MCP credential management * feat(i18n): implement MCP document localization and remove legacy code
This commit is contained in:
@@ -10,10 +10,15 @@ import (
|
||||
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
|
||||
"github.com/1Panel-dev/1Panel/agent/global"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/cmd"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/mcpapi"
|
||||
"github.com/1Panel-dev/1Panel/agent/utils/xpack"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
var loadNodeProxyID = func() (string, error) {
|
||||
return cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout("cat", "/etc/1panel/.nodeProxyID")
|
||||
}
|
||||
|
||||
func Certificate() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if global.IsMaster {
|
||||
@@ -25,16 +30,23 @@ func Certificate() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
conn := c.Request.Header.Get("Connection")
|
||||
if conn == "Upgrade" {
|
||||
mcpRequest, _ := mcpapi.Check(c.Request)
|
||||
mcpTransport := mcpRequest || c.Request.URL.Path == mcpapi.CapabilitiesPath
|
||||
if conn == "Upgrade" && !mcpTransport {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
masterProxyID := c.Request.Header.Get("Proxy-Id")
|
||||
proxyID, err := cmd.NewCommandMgr(cmd.WithTimeout(20*time.Second)).RunWithStdout("cat", "/etc/1panel/.nodeProxyID")
|
||||
proxyID, err := loadNodeProxyID()
|
||||
if mcpTransport && (err != nil || strings.TrimSpace(proxyID) == "" || strings.TrimSpace(proxyID) != strings.TrimSpace(masterProxyID)) {
|
||||
c.AbortWithStatus(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
if err == nil && len(proxyID) != 0 && strings.TrimSpace(proxyID) != strings.TrimSpace(masterProxyID) {
|
||||
helper.InternalServer(c, fmt.Errorf("err proxy id"))
|
||||
return
|
||||
}
|
||||
c.Request = mcpapi.BindVerifiedNodeTransport(c.Request)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user