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:
parent
9348d33b75
commit
e8685b3022
1 changed files with 11 additions and 1 deletions
|
|
@ -90,9 +90,16 @@ type StdioTransport struct{}
|
||||||
|
|
||||||
// Connect implements the [Transport] interface.
|
// Connect implements the [Transport] interface.
|
||||||
func (*StdioTransport) Connect(context.Context) (Connection, error) {
|
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
|
// An IOTransport is a [Transport] that communicates over separate
|
||||||
// io.ReadCloser and io.WriteCloser using newline-delimited JSON.
|
// io.ReadCloser and io.WriteCloser using newline-delimited JSON.
|
||||||
type IOTransport struct {
|
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
|
// An InMemoryTransport is a [Transport] that communicates over an in-memory
|
||||||
// network connection, using newline-delimited JSON.
|
// network connection, using newline-delimited JSON.
|
||||||
|
//
|
||||||
|
// InMemoryTransports should be constructed using [NewInMemoryTransports],
|
||||||
|
// which returns two transports connected to each other.
|
||||||
type InMemoryTransport struct {
|
type InMemoryTransport struct {
|
||||||
rwc io.ReadWriteCloser
|
rwc io.ReadWriteCloser
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue