From 49047aebe8040dcd125341d2b9981524543c4fe9 Mon Sep 17 00:00:00 2001 From: Konstantin Alikhanov Date: Wed, 1 Oct 2025 00:24:07 +0400 Subject: [PATCH] Add IOTransport for separate reader/writer (#376) This commit adds ability to create a mcp.Transport with specific io.ReadCloser and io.WriteCloser. Ii is needed when you need create an mcp.Client for mcp.Server launched in separate process and you need to communicate with it with it's own stdin/stdout. --- mcp/transport.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mcp/transport.go b/mcp/transport.go index b13d69c..111887b 100644 --- a/mcp/transport.go +++ b/mcp/transport.go @@ -93,6 +93,18 @@ func (*StdioTransport) Connect(context.Context) (Connection, error) { return newIOConn(rwc{os.Stdin, os.Stdout}), nil } +// An IOTransport is a [Transport] that communicates over separate +// io.ReadCloser and io.WriteCloser using newline-delimited JSON. +type IOTransport struct { + Reader io.ReadCloser + Writer io.WriteCloser +} + +// Connect implements the [Transport] interface. +func (t *IOTransport) Connect(context.Context) (Connection, error) { + return newIOConn(rwc{t.Reader, t.Writer}), nil +} + // An InMemoryTransport is a [Transport] that communicates over an in-memory // network connection, using newline-delimited JSON. type InMemoryTransport struct {