mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-13 19:21:08 +02:00
Add files via upload
This commit is contained in:
3 files changed
+38
-27
No files matched your search
@@ -52,8 +52,9 @@ type OpenAIConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SecurityConfig struct {
|
type SecurityConfig struct {
|
||||||
Tools []ToolConfig `yaml:"tools,omitempty"` // 向后兼容:支持在主配置文件中定义工具
|
Tools []ToolConfig `yaml:"tools,omitempty"` // 向后兼容:支持在主配置文件中定义工具
|
||||||
ToolsDir string `yaml:"tools_dir,omitempty"` // 工具配置文件目录(新方式)
|
ToolsDir string `yaml:"tools_dir,omitempty"` // 工具配置文件目录(新方式)
|
||||||
|
ToolDescriptionMode string `yaml:"tool_description_mode,omitempty"` // 工具描述模式: "short" | "full",默认 short
|
||||||
}
|
}
|
||||||
|
|
||||||
type DatabaseConfig struct {
|
type DatabaseConfig struct {
|
||||||
|
|||||||
@@ -174,18 +174,10 @@ func (h *ConfigHandler) GetConfig(c *gin.Context) {
|
|||||||
configToolMap[tool.Name] = true
|
configToolMap[tool.Name] = true
|
||||||
tools = append(tools, ToolConfigInfo{
|
tools = append(tools, ToolConfigInfo{
|
||||||
Name: tool.Name,
|
Name: tool.Name,
|
||||||
Description: tool.ShortDescription,
|
Description: h.pickToolDescription(tool.ShortDescription, tool.Description),
|
||||||
Enabled: tool.Enabled,
|
Enabled: tool.Enabled,
|
||||||
IsExternal: false,
|
IsExternal: false,
|
||||||
})
|
})
|
||||||
// 如果没有简短描述,使用详细描述的前10000个字符
|
|
||||||
if tools[len(tools)-1].Description == "" {
|
|
||||||
desc := tool.Description
|
|
||||||
if len(desc) > 10000 {
|
|
||||||
desc = desc[:10000] + "..."
|
|
||||||
}
|
|
||||||
tools[len(tools)-1].Description = desc
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 从MCP服务器获取所有已注册的工具(包括直接注册的工具,如知识检索工具)
|
// 从MCP服务器获取所有已注册的工具(包括直接注册的工具,如知识检索工具)
|
||||||
@@ -291,18 +283,10 @@ func (h *ConfigHandler) GetTools(c *gin.Context) {
|
|||||||
configToolMap[tool.Name] = true
|
configToolMap[tool.Name] = true
|
||||||
toolInfo := ToolConfigInfo{
|
toolInfo := ToolConfigInfo{
|
||||||
Name: tool.Name,
|
Name: tool.Name,
|
||||||
Description: tool.ShortDescription,
|
Description: h.pickToolDescription(tool.ShortDescription, tool.Description),
|
||||||
Enabled: tool.Enabled,
|
Enabled: tool.Enabled,
|
||||||
IsExternal: false,
|
IsExternal: false,
|
||||||
}
|
}
|
||||||
// 如果没有简短描述,使用详细描述的前10000个字符
|
|
||||||
if toolInfo.Description == "" {
|
|
||||||
desc := tool.Description
|
|
||||||
if len(desc) > 10000 {
|
|
||||||
desc = desc[:10000] + "..."
|
|
||||||
}
|
|
||||||
toolInfo.Description = desc
|
|
||||||
}
|
|
||||||
|
|
||||||
// 根据角色配置标注工具状态
|
// 根据角色配置标注工具状态
|
||||||
if roleName != "" {
|
if roleName != "" {
|
||||||
@@ -1193,7 +1177,7 @@ func (h *ConfigHandler) getExternalMCPTools(ctx context.Context) []ToolConfigInf
|
|||||||
enabled := h.calculateExternalToolEnabled(mcpName, actualToolName, externalMCPConfigs)
|
enabled := h.calculateExternalToolEnabled(mcpName, actualToolName, externalMCPConfigs)
|
||||||
|
|
||||||
// 处理描述信息
|
// 处理描述信息
|
||||||
description := h.formatToolDescription(externalTool.ShortDescription, externalTool.Description)
|
description := h.pickToolDescription(externalTool.ShortDescription, externalTool.Description)
|
||||||
|
|
||||||
result = append(result, ToolConfigInfo{
|
result = append(result, ToolConfigInfo{
|
||||||
Name: actualToolName,
|
Name: actualToolName,
|
||||||
@@ -1249,10 +1233,13 @@ func (h *ConfigHandler) calculateExternalToolEnabled(mcpName, toolName string, c
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// formatToolDescription 格式化工具描述(限制长度)
|
// pickToolDescription 根据 security.tool_description_mode 选择 short 或 full 描述并限制长度
|
||||||
func (h *ConfigHandler) formatToolDescription(shortDesc, fullDesc string) string {
|
func (h *ConfigHandler) pickToolDescription(shortDesc, fullDesc string) string {
|
||||||
|
useFull := strings.TrimSpace(strings.ToLower(h.config.Security.ToolDescriptionMode)) == "full"
|
||||||
description := shortDesc
|
description := shortDesc
|
||||||
if description == "" {
|
if useFull {
|
||||||
|
description = fullDesc
|
||||||
|
} else if description == "" {
|
||||||
description = fullDesc
|
description = fullDesc
|
||||||
}
|
}
|
||||||
if len(description) > 10000 {
|
if len(description) > 10000 {
|
||||||
|
|||||||
@@ -224,13 +224,13 @@ func (e *Executor) RegisterTools(mcpServer *mcp.Server) {
|
|||||||
toolName := toolConfig.Name
|
toolName := toolConfig.Name
|
||||||
toolConfigCopy := toolConfig
|
toolConfigCopy := toolConfig
|
||||||
|
|
||||||
// 使用简短描述(如果存在),否则使用详细描述的前10000个字符
|
// 根据配置决定暴露给 AI/API 的描述:short_description 或 description
|
||||||
|
useFullDescription := strings.TrimSpace(strings.ToLower(e.config.ToolDescriptionMode)) == "full"
|
||||||
shortDesc := toolConfigCopy.ShortDescription
|
shortDesc := toolConfigCopy.ShortDescription
|
||||||
if shortDesc == "" {
|
if shortDesc == "" {
|
||||||
// 如果没有简短描述,从详细描述中提取第一行或前10000个字符
|
// 如果没有简短描述,从详细描述中提取第一行或前10000个字符
|
||||||
desc := toolConfigCopy.Description
|
desc := toolConfigCopy.Description
|
||||||
if len(desc) > 10000 {
|
if len(desc) > 10000 {
|
||||||
// 尝试找到第一个换行符
|
|
||||||
if idx := strings.Index(desc, "\n"); idx > 0 && idx < 10000 {
|
if idx := strings.Index(desc, "\n"); idx > 0 && idx < 10000 {
|
||||||
shortDesc = strings.TrimSpace(desc[:idx])
|
shortDesc = strings.TrimSpace(desc[:idx])
|
||||||
} else {
|
} else {
|
||||||
@@ -240,6 +240,9 @@ func (e *Executor) RegisterTools(mcpServer *mcp.Server) {
|
|||||||
shortDesc = desc
|
shortDesc = desc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if useFullDescription {
|
||||||
|
shortDesc = "" // 使用 description 时清空 ShortDescription,下游会回退到 Description
|
||||||
|
}
|
||||||
|
|
||||||
tool := mcp.Tool{
|
tool := mcp.Tool{
|
||||||
Name: toolConfigCopy.Name,
|
Name: toolConfigCopy.Name,
|
||||||
@@ -303,7 +306,23 @@ func (e *Executor) buildCommandArgs(toolName string, toolConfig *config.ToolConf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先处理标志参数(对于大多数命令,标志应该在位置参数之前)
|
// 对于需要子命令的工具(如 gobuster dir),position 0 必须紧跟在命令名后、所有 flag 之前
|
||||||
|
for _, param := range positionalParams {
|
||||||
|
if param.Name == "additional_args" || param.Name == "scan_type" || param.Name == "action" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if param.Position != nil && *param.Position == 0 {
|
||||||
|
value := e.getParamValue(args, param)
|
||||||
|
if value == nil && param.Default != nil {
|
||||||
|
value = param.Default
|
||||||
|
}
|
||||||
|
if value != nil {
|
||||||
|
cmdArgs = append(cmdArgs, e.formatParamValue(param, value))
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 处理标志参数
|
// 处理标志参数
|
||||||
for _, param := range flagParams {
|
for _, param := range flagParams {
|
||||||
// 跳过特殊参数,它们会在后面单独处理
|
// 跳过特殊参数,它们会在后面单独处理
|
||||||
@@ -416,7 +435,11 @@ func (e *Executor) buildCommandArgs(toolName string, toolConfig *config.ToolConf
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 按位置顺序处理参数,确保即使某些位置没有参数或使用默认值,也能正确传递
|
// 按位置顺序处理参数,确保即使某些位置没有参数或使用默认值,也能正确传递
|
||||||
|
// position 0 已在前面插入(子命令优先),此处从 1 开始
|
||||||
for i := 0; i <= maxPosition; i++ {
|
for i := 0; i <= maxPosition; i++ {
|
||||||
|
if i == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, param := range positionalParams {
|
for _, param := range positionalParams {
|
||||||
// 跳过特殊参数,它们会在后面单独处理
|
// 跳过特殊参数,它们会在后面单独处理
|
||||||
// action 参数仅用于工具内部逻辑,不传递给命令
|
// action 参数仅用于工具内部逻辑,不传递给命令
|
||||||
|
|||||||
Reference in new issue
Block a user