Fix MCP subprocess env: start from os.Environ(), append extras

The loop was calling append(os.Environ(), ...) on each iteration,
discarding all but the last extra env var. Start cmd.Env from
os.Environ() once, then append each configured key=value pair.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Levi Neely 2026-04-01 00:51:32 +02:00
parent 6c38a1147c
commit d64e49e893
1 changed files with 2 additions and 1 deletions

View File

@ -21,8 +21,9 @@ func NewSTDIOTransport(command string, args []string, env map[string]string) *ST
// Connect launches the subprocess and returns a connected Client.
func (t *STDIOTransport) Connect() (*Client, error) {
cmd := exec.Command(t.command, t.args...)
cmd.Env = os.Environ()
for k, v := range t.env {
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", k, v))
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
}
stdin, err := cmd.StdinPipe()