From 7647be8bf6fea0de1a898ae0899c39bd343dacea Mon Sep 17 00:00:00 2001 From: Luxferre Date: Sun, 22 Mar 2026 12:46:02 +0200 Subject: [PATCH] added proper logging to the mcp agent mode --- cmd/sidekick-mcp/main.go | 17 ++++++++++++++++- config.toml | 8 ++++---- mcp.go | 7 +++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/cmd/sidekick-mcp/main.go b/cmd/sidekick-mcp/main.go index 9896202..58b92a3 100644 --- a/cmd/sidekick-mcp/main.go +++ b/cmd/sidekick-mcp/main.go @@ -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"), diff --git a/config.toml b/config.toml index e8e2d66..a80bba9 100644 --- a/config.toml +++ b/config.toml @@ -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 diff --git a/mcp.go b/mcp.go index 9dd1fda..e71aeff 100644 --- a/mcp.go +++ b/mcp.go @@ -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