Skip to content

Commit 49047ae

Browse files
authored
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.
1 parent 069aae1 commit 49047ae

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

mcp/transport.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ func (*StdioTransport) Connect(context.Context) (Connection, error) {
9393
return newIOConn(rwc{os.Stdin, os.Stdout}), nil
9494
}
9595

96+
// An IOTransport is a [Transport] that communicates over separate
97+
// io.ReadCloser and io.WriteCloser using newline-delimited JSON.
98+
type IOTransport struct {
99+
Reader io.ReadCloser
100+
Writer io.WriteCloser
101+
}
102+
103+
// Connect implements the [Transport] interface.
104+
func (t *IOTransport) Connect(context.Context) (Connection, error) {
105+
return newIOConn(rwc{t.Reader, t.Writer}), nil
106+
}
107+
96108
// An InMemoryTransport is a [Transport] that communicates over an in-memory
97109
// network connection, using newline-delimited JSON.
98110
type InMemoryTransport struct {

0 commit comments

Comments
 (0)