added proper logging to the mcp agent mode

This commit is contained in:
Luxferre
2026-03-22 12:46:02 +02:00
parent 3a6aa7a8fc
commit 7647be8bf6
3 changed files with 27 additions and 5 deletions
+16 -1
View File
@@ -25,6 +25,8 @@ func main() {
log.SetOutput(os.Stderr)
}
sidekick.GlobalLogger = log.Printf
tmpl, _ := sidekick.LoadPrompts("prompts.toml")
sidekick.InitMCPServers(cfg.MCPServers)
@@ -38,7 +40,14 @@ func main() {
}
}
mCfg := cfg.Models[aCfg.ModelID]
pool[id] = sidekick.NewSidekick(aCfg, mCfg, nil)
agent := sidekick.NewSidekick(aCfg, mCfg, nil)
if aCfg.LogIntermediate {
agentID := id
agent.IntermediateHandler = func(msg string) {
log.Printf("[Agent %s] %s\n", agentID, msg)
}
}
pool[id] = agent
}
entryAgent := "coordinator"
@@ -79,9 +88,12 @@ func main() {
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
msg, err := request.RequireString("message")
if err != nil {
log.Printf("Received invalid 'query' request: missing message argument")
return nil, fmt.Errorf("message argument is required and must be a string: %v", err)
}
log.Printf("Received 'query' request (message length: %d)", len(msg))
var inCtx []sidekick.Message
args := request.GetArguments()
@@ -113,9 +125,12 @@ func main() {
responseStr, err := agent.Run(ctx, inCtx, pool)
if err != nil {
log.Printf("Agent run failed: %v", err)
return nil, fmt.Errorf("agent run failed: %w", err)
}
log.Printf("Sending response (length: %d)", len(responseStr))
// Add the final response to the history structure to be returned
outHistory := append(inCtx, sidekick.Message{
Role: sidekick.MessageRole("assistant"),
+4 -4
View File
@@ -37,7 +37,7 @@ port = 8080
model_id = "default"
enable_shell_exec = true
streaming = false
log_intermediate = false
log_intermediate = true
system_prompt = "You are the Lead Architect. You oversee the software development lifecycle, plan features, and delegate implementation to specialized subagents."
description = "Lead Architect and project coordinator"
max_iterations = 15
@@ -54,7 +54,7 @@ port = 8080
model_id = "default"
enable_shell_exec = true
streaming = false
log_intermediate = false
log_intermediate = true
system_prompt = "You are a Senior Software Engineer specializing in implementation. Your goal is to write clean, efficient, and well-documented code based on the architect's instructions."
description = "Senior Developer focused on implementation and refactoring"
max_iterations = 10
@@ -69,7 +69,7 @@ port = 8080
role = "SPECIALIST"
model_id = "fast"
streaming = false
log_intermediate = false
log_intermediate = true
system_prompt = "You are a Quality Assurance Specialist and Code Reviewer. Your role is to analyze code for potential bugs, security vulnerabilities, and style violations."
description = "Code Reviewer and Quality Assurance specialist"
max_iterations = 8
@@ -85,7 +85,7 @@ port = 8080
model_id = "fast"
enable_shell_exec = true
streaming = false
log_intermediate = false
log_intermediate = true
system_prompt = "You are a Test Engineer. Your primary responsibility is to write and execute tests to ensure software reliability and correctness."
description = "Test Engineer focused on automated testing and verification"
max_iterations = 10
+7
View File
@@ -54,6 +54,9 @@ func (w *mcpGoClientWrapper) Close() error {
// Global server configurations
var mcpServers map[string]MCPServerConfig
// GlobalLogger is an optional logger for MCP connections
var GlobalLogger func(format string, v ...interface{})
// InitMCPServers sets up the global registry for MCP factories
func InitMCPServers(servers map[string]MCPServerConfig) {
mcpServers = servers
@@ -66,6 +69,10 @@ var defaultMCPFactory MCPClientFactory = func(toolset string) (MCPClientInterfac
return nil, fmt.Errorf("unknown MCP server: %s", toolset)
}
if GlobalLogger != nil {
GlobalLogger("Initializing MCP connection to %s via %s", toolset, cfg.Transport)
}
var c *client.Client
var err error