mcp: don't close stdout when shutting down the stdio transport (#562)

We need to close stdin when the stdio transport is shut down, to unblock
its read loop. However, we don't technically need to close stdout.

Fixes #548
This commit is contained in:
Robert Findley 2025-10-07 11:08:38 -04:00 • committed by GitHub
commit e8685b3022
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,9 +90,16 @@ type StdioTransport struct{}
// Connect implements the [Transport] interface.
func (*StdioTransport) Connect(context.Context) (Connection, error) {
return newIOConn(rwc{os.Stdin, os.Stdout}), nil
return newIOConn(rwc{os.Stdin, nopCloserWriter{os.Stdout}}), nil
}
// nopCloserWriter is an io.WriteCloser with a trivial Close method.
type nopCloserWriter struct {
io.Writer
}
func (nopCloserWriter) Close() error { return nil }
// An IOTransport is a [Transport] that communicates over separate
// io.ReadCloser and io.WriteCloser using newline-delimited JSON.
type IOTransport struct {
@ -107,6 +114,9 @@ func (t *IOTransport) Connect(context.Context) (Connection, error) {
// An InMemoryTransport is a [Transport] that communicates over an in-memory
// network connection, using newline-delimited JSON.
//
// InMemoryTransports should be constructed using [NewInMemoryTransports],
// which returns two transports connected to each other.
type InMemoryTransport struct {
rwc io.ReadWriteCloser
}