From 82addc2f91f36cab455750cb44944fd628b9f073 Mon Sep 17 00:00:00 2001 From: tong3jie <14191774+tong3jie@users.noreply.github.com> Date: Fri, 20 Mar 2026 13:59:26 +0800 Subject: [PATCH] fix(mcp): improve error handling during MCP server connection initialization and reconnection attempts --- pkg/mcp/manager.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/mcp/manager.go b/pkg/mcp/manager.go index a2de34143..01f12f85a 100644 --- a/pkg/mcp/manager.go +++ b/pkg/mcp/manager.go @@ -143,6 +143,8 @@ func (m *Manager) LoadFromMCPConfig( "failed": len(allErrors), "total": enabledCount, }) + + // only all mcp servers was failed, then return return fmt.Errorf("all MCP servers failed to connect: %w", err) } @@ -150,8 +152,8 @@ func (m *Manager) LoadFromMCPConfig( "failed": len(allErrors), "connected": connectedCount, "total": enabledCount, + "error": err.Error(), }) - return fmt.Errorf("partial MCP initialization failure: %w", err) } logger.InfoCF(logModule, "MCP server initialization complete", map[string]any{ @@ -410,6 +412,9 @@ func (m *Manager) handleServerOffline(name string) { logger.DebugCF("mcp", "Reconnection attempt", map[string]any{"server": name, "attempt": attempt}) + if m.closed.Load() { + return + } err := m.ConnectServer(context.Background(), name, conn.Config) if err == nil { logger.InfoCF("mcp", "Reconnection successful", map[string]any{"server": name})