mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-12 18:58:10 +02:00
Add files via upload
This commit is contained in:
2 files changed
+20
-17
No files matched your search
@@ -783,25 +783,25 @@ func (a *Agent) ExecuteMCPToolForConversation(ctx context.Context, conversationI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BeginLocalToolExecution 在非 CallTool 路径工具开始时写入 running 状态,供 MCP 监控页展示「执行中」。
|
// BeginLocalToolExecution 在非 CallTool 路径工具开始时写入 running 状态,供 MCP 监控页展示「执行中」。
|
||||||
func (a *Agent) BeginLocalToolExecution(toolName string, args map[string]interface{}) string {
|
func (a *Agent) BeginLocalToolExecution(ctx context.Context, toolName string, args map[string]interface{}) string {
|
||||||
if a == nil || a.mcpServer == nil {
|
if a == nil || a.mcpServer == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return a.mcpServer.BeginToolExecution(toolName, args)
|
return a.mcpServer.BeginToolExecution(ctx, toolName, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinishLocalToolExecution 完成 BeginLocalToolExecution 创建的记录;executionID 为空时一次性写入已完成记录。
|
// FinishLocalToolExecution 完成 BeginLocalToolExecution 创建的记录;executionID 为空时一次性写入已完成记录。
|
||||||
func (a *Agent) FinishLocalToolExecution(executionID, toolName string, args map[string]interface{}, resultText string, invokeErr error) string {
|
func (a *Agent) FinishLocalToolExecution(ctx context.Context, executionID, toolName string, args map[string]interface{}, resultText string, invokeErr error) string {
|
||||||
if a == nil || a.mcpServer == nil {
|
if a == nil || a.mcpServer == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return a.mcpServer.FinishToolExecution(executionID, toolName, args, resultText, invokeErr)
|
return a.mcpServer.FinishToolExecution(ctx, executionID, toolName, args, resultText, invokeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RecordLocalToolExecution 将非 CallTool 路径完成的工具调用写入 MCP 监控库(与 CallTool 落库一致),返回 executionId。
|
// RecordLocalToolExecution 将非 CallTool 路径完成的工具调用写入 MCP 监控库(与 CallTool 落库一致),返回 executionId。
|
||||||
// 用于 Eino filesystem execute 等场景,使助手气泡「渗透测试详情」与常规 MCP 一致可点进监控。
|
// 用于 Eino filesystem execute 等场景,使助手气泡「渗透测试详情」与常规 MCP 一致可点进监控。
|
||||||
func (a *Agent) RecordLocalToolExecution(toolName string, args map[string]interface{}, resultText string, invokeErr error) string {
|
func (a *Agent) RecordLocalToolExecution(ctx context.Context, toolName string, args map[string]interface{}, resultText string, invokeErr error) string {
|
||||||
return a.FinishLocalToolExecution("", toolName, args, resultText, invokeErr)
|
return a.FinishLocalToolExecution(ctx, "", toolName, args, resultText, invokeErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateMCPExecutionDisplayResult 将监控库中的工具结果更新为送入模型的展示正文(reduction 后)。
|
// UpdateMCPExecutionDisplayResult 将监控库中的工具结果更新为送入模型的展示正文(reduction 后)。
|
||||||
|
|||||||
+14
-11
@@ -650,11 +650,12 @@ type LogConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MCPConfig struct {
|
type MCPConfig struct {
|
||||||
Enabled bool `yaml:"enabled"`
|
Enabled bool `yaml:"enabled"`
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
AuthHeader string `yaml:"auth_header,omitempty"` // 鉴权 header 名,留空表示不鉴权
|
AuthHeader string `yaml:"auth_header,omitempty"` // 可选的全局服务凭证 header;普通调用优先使用用户 Bearer Token
|
||||||
AuthHeaderValue string `yaml:"auth_header_value,omitempty"` // 鉴权 header 值,需与请求中该 header 一致
|
AuthHeaderValue string `yaml:"auth_header_value,omitempty"` // 全局服务凭证,仅 allow_global_access=true 时接受
|
||||||
|
AllowGlobalAccess bool `yaml:"allow_global_access,omitempty"` // 静态服务密钥是否映射为全局服务身份(默认关闭)
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenAIConfig struct {
|
type OpenAIConfig struct {
|
||||||
@@ -1396,9 +1397,10 @@ func persistMCPAuth(path string, mcp *MCPConfig) error {
|
|||||||
return os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0644)
|
return os.WriteFile(path, []byte(strings.Join(lines, "\n")), 0644)
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnsureMCPAuth 在 MCP 启用且 auth_header_value 为空时,自动生成随机密钥并写回配置
|
// EnsureMCPAuth only provisions the privileged static service credential when
|
||||||
|
// global service access was explicitly enabled.
|
||||||
func EnsureMCPAuth(path string, cfg *Config) error {
|
func EnsureMCPAuth(path string, cfg *Config) error {
|
||||||
if !cfg.MCP.Enabled || strings.TrimSpace(cfg.MCP.AuthHeaderValue) != "" {
|
if !cfg.MCP.Enabled || !cfg.MCP.AllowGlobalAccess || strings.TrimSpace(cfg.MCP.AuthHeaderValue) != "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
token, err := generateRandomToken()
|
token, err := generateRandomToken()
|
||||||
@@ -1422,8 +1424,9 @@ func PrintMCPConfigJSON(mcp MCPConfig) {
|
|||||||
hostForURL = "localhost"
|
hostForURL = "localhost"
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("http://%s:%d/mcp", hostForURL, mcp.Port)
|
url := fmt.Sprintf("http://%s:%d/mcp", hostForURL, mcp.Port)
|
||||||
headers := map[string]string{}
|
headers := map[string]string{"Authorization": "Bearer <USER_SESSION_TOKEN>"}
|
||||||
if mcp.AuthHeader != "" {
|
if mcp.AllowGlobalAccess && mcp.AuthHeader != "" {
|
||||||
|
delete(headers, "Authorization")
|
||||||
headers[mcp.AuthHeader] = mcp.AuthHeaderValue
|
headers[mcp.AuthHeader] = mcp.AuthHeaderValue
|
||||||
}
|
}
|
||||||
serverEntry := map[string]interface{}{
|
serverEntry := map[string]interface{}{
|
||||||
@@ -1683,8 +1686,8 @@ func Default() *Config {
|
|||||||
Output: "stdout",
|
Output: "stdout",
|
||||||
},
|
},
|
||||||
MCP: MCPConfig{
|
MCP: MCPConfig{
|
||||||
Enabled: true,
|
Enabled: false,
|
||||||
Host: "0.0.0.0",
|
Host: "127.0.0.1",
|
||||||
Port: 8081,
|
Port: 8081,
|
||||||
},
|
},
|
||||||
OpenAI: OpenAIConfig{
|
OpenAI: OpenAIConfig{
|
||||||
|
|||||||
Reference in new issue
Block a user