@@ -23,6 +23,7 @@ type StdioMCPClient struct {
23
23
cmd * exec.Cmd
24
24
stdin io.WriteCloser
25
25
stdout * bufio.Reader
26
+ stderr io.ReadCloser
26
27
requestID atomic.Int64
27
28
responses map [int64 ]chan RPCResponse
28
29
mu sync.RWMutex
@@ -58,9 +59,15 @@ func NewStdioMCPClient(
58
59
return nil , fmt .Errorf ("failed to create stdout pipe: %w" , err )
59
60
}
60
61
62
+ stderr , err := cmd .StderrPipe ()
63
+ if err != nil {
64
+ return nil , fmt .Errorf ("failed to create stderr pipe: %w" , err )
65
+ }
66
+
61
67
client := & StdioMCPClient {
62
68
cmd : cmd ,
63
69
stdin : stdin ,
70
+ stderr : stderr ,
64
71
stdout : bufio .NewReader (stdout ),
65
72
responses : make (map [int64 ]chan RPCResponse ),
66
73
done : make (chan struct {}),
@@ -88,9 +95,18 @@ func (c *StdioMCPClient) Close() error {
88
95
if err := c .stdin .Close (); err != nil {
89
96
return fmt .Errorf ("failed to close stdin: %w" , err )
90
97
}
98
+ if err := c .stderr .Close (); err != nil {
99
+ return fmt .Errorf ("failed to close stderr: %w" , err )
100
+ }
91
101
return c .cmd .Wait ()
92
102
}
93
103
104
+ // Stderr returns a reader for the stderr output of the subprocess.
105
+ // This can be used to capture error messages or logs from the subprocess.
106
+ func (c * StdioMCPClient ) Stderr () io.Reader {
107
+ return c .stderr
108
+ }
109
+
94
110
// OnNotification registers a handler function to be called when notifications are received.
95
111
// Multiple handlers can be registered and will be called in the order they were added.
96
112
func (c * StdioMCPClient ) OnNotification (
0 commit comments