mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-14 00:06:05 +00:00
* feat(mcp): add Panel MCP task configuration and website binding structures * fix(mcp): correct variable assignment in mcpWebsiteDomain function
33 lines
942 B
Go
33 lines
942 B
Go
package router
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/service"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const panelMCPTaskAccessHeader = "X-Panel-MCP-Task-Access"
|
|
|
|
func panelMCPTaskProxyPolicy() agentProxyPolicy {
|
|
return agentProxyPolicy{
|
|
clear: func(req *http.Request) { req.Header.Del(panelMCPTaskAccessHeader) },
|
|
grant: setPanelMCPTaskAccess,
|
|
}
|
|
}
|
|
|
|
func setPanelMCPTaskAccess(c *gin.Context, local bool) {
|
|
if !local || !isPanelMCPTaskEndpoint(c.Request.Method, c.Request.URL.Path) {
|
|
return
|
|
}
|
|
owner, err := service.NewMCPService().ManagementOwner(c, false)
|
|
if err == nil && owner.IsSuperAdmin {
|
|
c.Request.Header.Set(panelMCPTaskAccessHeader, "1")
|
|
}
|
|
}
|
|
|
|
func isPanelMCPTaskEndpoint(method, reqPath string) bool {
|
|
return method == http.MethodPost && (reqPath == "/api/v2/logs/tasks/search" || reqPath == "/api/v2/logs/tasks/read") ||
|
|
method == http.MethodGet && reqPath == "/api/v2/logs/tasks/executing/count"
|
|
}
|