feat(mcp): 设置 → MCP 子页 + 策略 API + 官网/文档接入
借鉴 DBX:安装检测(Node/npm/包/Go 二进制)、只读与 allow_dangerous、 连接白名单、多客户端配置片段;GET/PUT /api/ai/mcp-policy、/mcp-install; 文档 /docs/mcp 与落地页 AI/MCP 块;对照 docs/16 勾选设置项、列仍未完清单。
This commit is contained in:
1 parent
5416e86379
commit
1513f4bc2d
20 files changed
+1567
-98
No files matched your search
@@ -584,6 +584,49 @@ func NewRouter(token string) *gin.Engine {
|
||||
c.JSON(http.StatusOK, aitools.GetMCPStatus())
|
||||
})
|
||||
|
||||
// MCP 策略读写(设置 → MCP):~/.opsxdb/mcp.json
|
||||
api.GET("/ai/mcp-policy", func(c *gin.Context) {
|
||||
p, err := aitools.LoadPolicy()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
path, _ := aitools.PolicyPath()
|
||||
c.JSON(http.StatusOK, gin.H{"policy": p, "path": path})
|
||||
})
|
||||
|
||||
api.PUT("/ai/mcp-policy", func(c *gin.Context) {
|
||||
var req struct {
|
||||
AllowedConnectionIDs []string `json:"allowed_connection_ids"`
|
||||
Mode string `json:"mode"`
|
||||
AllowDangerous bool `json:"allow_dangerous"`
|
||||
DefaultLimit int `json:"default_limit"`
|
||||
MaxLimit int `json:"max_limit"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
p := aitools.Policy{
|
||||
AllowedConnectionIDs: req.AllowedConnectionIDs,
|
||||
Mode: req.Mode,
|
||||
AllowDangerous: req.AllowDangerous,
|
||||
DefaultLimit: req.DefaultLimit,
|
||||
MaxLimit: req.MaxLimit,
|
||||
}
|
||||
if err := aitools.SavePolicy(p); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
saved, _ := aitools.LoadPolicy()
|
||||
path, _ := aitools.PolicyPath()
|
||||
c.JSON(http.StatusOK, gin.H{"ok": true, "policy": saved, "path": path})
|
||||
})
|
||||
|
||||
api.GET("/ai/mcp-install", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, aitools.ProbeMCPInstall())
|
||||
})
|
||||
|
||||
api.POST("/ai/generate", func(c *gin.Context) {
|
||||
var req ai.ChatReq
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
|
||||
Reference in new issue
Block a user