fix(mcp): resolve relative envFile paths against workspace directory
- Resolve relative envFile paths relative to workspace instead of CWD - Add filepath import for path operations - Pass workspace path to goroutines for path resolution - Improves portability in Docker environments where CWD may vary - Absolute envFile paths continue to work as before
This commit is contained in:
parent
77d26e5ce3
commit
a4265b3f16
1 changed files with 11 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
|
@ -128,6 +129,9 @@ func (m *Manager) LoadFromConfig(ctx context.Context, cfg *config.Config) error
|
||||||
"count": len(cfg.Tools.MCP.Servers),
|
"count": len(cfg.Tools.MCP.Servers),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Get workspace path for resolving relative envFile paths
|
||||||
|
workspacePath := cfg.WorkspacePath()
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
errs := make(chan error, len(cfg.Tools.MCP.Servers))
|
errs := make(chan error, len(cfg.Tools.MCP.Servers))
|
||||||
enabledCount := 0
|
enabledCount := 0
|
||||||
|
|
@ -143,9 +147,14 @@ func (m *Manager) LoadFromConfig(ctx context.Context, cfg *config.Config) error
|
||||||
|
|
||||||
enabledCount++
|
enabledCount++
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(name string, serverCfg config.MCPServerConfig) {
|
go func(name string, serverCfg config.MCPServerConfig, workspace string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
|
// Resolve relative envFile paths relative to workspace
|
||||||
|
if serverCfg.EnvFile != "" && !filepath.IsAbs(serverCfg.EnvFile) {
|
||||||
|
serverCfg.EnvFile = filepath.Join(workspace, serverCfg.EnvFile)
|
||||||
|
}
|
||||||
|
|
||||||
if err := m.ConnectServer(ctx, name, serverCfg); err != nil {
|
if err := m.ConnectServer(ctx, name, serverCfg); err != nil {
|
||||||
logger.ErrorCF("mcp", "Failed to connect to MCP server",
|
logger.ErrorCF("mcp", "Failed to connect to MCP server",
|
||||||
map[string]interface{}{
|
map[string]interface{}{
|
||||||
|
|
@ -154,7 +163,7 @@ func (m *Manager) LoadFromConfig(ctx context.Context, cfg *config.Config) error
|
||||||
})
|
})
|
||||||
errs <- fmt.Errorf("failed to connect to server %s: %w", name, err)
|
errs <- fmt.Errorf("failed to connect to server %s: %w", name, err)
|
||||||
}
|
}
|
||||||
}(name, serverCfg)
|
}(name, serverCfg, workspacePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue