Vectrum
Sign In

mcp: reap a server that failed the handshake before reading its stderr

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Jjonicommitted 1 parent 03b5fe4commit8fbd588

Showing 1 changed file with 8 additions and 2 deletions.

+8−2internal/mcp/connect.goView File
@@ -13,8 +13,8 @@ import (
1313 "syscall"
1414 "time"
1515
16- "codey/internal/config"
17- "codey/internal/tools"
16+ "github.com/johannSo/codey/internal/config"
17+ "github.com/johannSo/codey/internal/tools"
1818 )
1919
2020 // clientVersion is what initialize reports as clientInfo.version. It is
@@ -173,6 +173,12 @@ func start(ctx context.Context, dir, name string, spec config.MCPServer) (*clien
173173 defer cancel()
174174 infos, err := handshake(ctx, c)
175175 if err != nil {
176+ // Stderr is copied in by exec on a goroutine that only Wait is sure
177+ // to have seen finish: the stdout EOF that failed the handshake can
178+ // arrive first, and read now the tail would be missing the very line
179+ // that explains the exit. Close kills and reaps the process; the
180+ // caller's later Close is a no-op.
181+ _ = c.Close()
176182 if s := strings.TrimSpace(stderr.String()); s != "" {
177183 err = fmt.Errorf("%w\nserver stderr:\n%s", err, s)
178184 }