From a7a4e88fff1af11d8a675588ab7ab7cae830d222 Mon Sep 17 00:00:00 2001 From: yuchou87 Date: Thu, 19 Feb 2026 20:03:00 +0800 Subject: [PATCH] fix(agent): use fallback workspace path for MCP initialization Use cfg.WorkspacePath() as a fallback when defaultAgent is nil or its Workspace is empty. This ensures MCP servers with relative envFile paths can always resolve them correctly, even when agents haven't been fully initialized yet. Previously, workspacePath would be an empty string in these cases, causing relative envFile paths to fail to resolve. Now the fallback guarantees a valid workspace path is always provided to LoadFromMCPConfig. Addresses Copilot code review feedback. --- pkg/agent/loop.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 87b47f4ad..fc83007c2 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -140,8 +140,10 @@ func (al *AgentLoop) Run(ctx context.Context) error { mcpManager := mcp.NewManager() defaultAgent := al.registry.GetDefaultAgent() workspacePath := "" - if defaultAgent != nil { + if defaultAgent != nil && defaultAgent.Workspace != "" { workspacePath = defaultAgent.Workspace + } else { + workspacePath = al.cfg.WorkspacePath() } if err := mcpManager.LoadFromMCPConfig(ctx, al.cfg.Tools.MCP, workspacePath); err != nil {