Skip to content

Commit 71d8452

Browse files
committed
Fix hanging client int test for windows stdio
1 parent 32c5766 commit 71d8452

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

client/internal/mcp/client.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package mcp
44
import (
55
"context"
66
"fmt"
7+
"io"
78
"os"
89
"os/exec"
910
"path/filepath"
@@ -101,6 +102,15 @@ func (c *Client) connectStdio(ctx context.Context) error {
101102
if err != nil {
102103
return fmt.Errorf("failed to create stdio MCP client: %w", err)
103104
}
105+
106+
// Drain the server's stderr in a background goroutine to prevent the
107+
// subprocess from blocking on a full pipe buffer. On Windows the default
108+
// pipe buffer is ~4 KB; once it fills, any write to stderr blocks the
109+
// entire Node.js event loop, causing all subsequent tool calls to hang.
110+
if stderr, ok := mcpclient.GetStderr(client); ok {
111+
go func() { _, _ = io.Copy(io.Discard, stderr) }()
112+
}
113+
104114
c.inner = client
105115
c.serverCmd = spawnedCmd
106116

0 commit comments

Comments
 (0)