Files
ai-agent/internal/pkg/toolx/mcp_policy.go
T
t 2bbf42b741 refactor(auth): delegate access control to be-system
Remove Agent Desk users, roles, login sessions, tokens, and local permission persistence. Expose the backend as an embeddable ai-agent module with host-provided subject lookup and operation authorization callbacks, and complete the frontend/backend repository split.
2026-08-21 00:41:07 +08:00

52 lines
1.3 KiB
Go

package toolx
import (
"strings"
"code.tczkiot.com/wlw/ai-agent/internal/pkg/dto/request"
)
const (
MCPRiskLevelRead = "read"
MCPRiskLevelWrite = "write"
)
type TrustedMCPToolPolicy struct {
ToolCode string
Title string
RiskLevel string
RequireConfirmation bool
}
var trustedMCPToolPolicies = map[string]TrustedMCPToolPolicy{
"system/server_time": {
ToolCode: "system/server_time",
Title: "获取当前时间",
RiskLevel: MCPRiskLevelRead,
RequireConfirmation: false,
},
"system/service_info": {
ToolCode: "system/service_info",
Title: "查看服务信息",
RiskLevel: MCPRiskLevelRead,
RequireConfirmation: false,
},
}
func GetTrustedMCPToolPolicy(toolCode string) (TrustedMCPToolPolicy, bool) {
policy, ok := trustedMCPToolPolicies[NormalizeToolCodeAlias(strings.TrimSpace(toolCode))]
return policy, ok
}
func ApplyTrustedMCPToolPolicy(item request.AIAgentMCPToolRequest) request.AIAgentMCPToolRequest {
policy, ok := GetTrustedMCPToolPolicy(item.ToolCode)
if !ok {
return item
}
item.ToolCode = policy.ToolCode
item.Title = policy.Title
item.RiskLevel = policy.RiskLevel
item.RequireConfirmation = policy.RequireConfirmation
return item
}