Skip to content

Add environment support to client #195

Closed
@CalsRanna

Description

@CalsRanna

This is the code in client.dart:

Future<ServerConnection> connectStdioServer(
    String command,
    List<String> arguments, {
    Sink<String>? protocolLogSink,
  }) async {
    final process = await Process.start(command, arguments);
    process.stderr
        .transform(utf8.decoder)
        .transform(const LineSplitter())
        .listen((line) {
          stderr.writeln('[StdErr from server $command]: $line');
        });
    final channel = StreamChannel.withCloseGuarantee(
          process.stdout,
          process.stdin,
        )
        .transform(StreamChannelTransformer.fromCodec(utf8))
        .transformStream(const LineSplitter())
        .transformSink(
          StreamSinkTransformer.fromHandlers(
            handleData: (data, sink) {
              sink.add('$data\n');
            },
          ),
        );
    final connection = connectServer(channel, protocolLogSink: protocolLogSink);
    unawaited(connection.done.then((_) => process.kill()));
    return connection;
  }

As we can see, the Process.start supportsMap<String, String>? environment, but MCPClient DOES NOT expose it. So why the environment is not supported in Client?

And the temp way to solve this is you define a new function in extension on MCPClient, and copy the code up here and add environment support yourself with importing async and stream channel packages.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions