Skip to content

Make McpClientFactory accept an IClientTransport directly instead of McpServerConfig #190

@eiriktsarpalis

Description

@eiriktsarpalis

each transport implementation should define its own options object if necessary

That sounds reasonable.

Originally posted by @stephentoub in #181

Spinning off this conversation into a new issue. What I have in mind roughly is change the McpClientFactory signature to be the following:

public static class McpClientFactory
{
    public static async Task<IMcpClient> CreateAsync(
        IClientTransport transport,
        McpClientOptions? clientOptions = null,
        ILoggerFactory? loggerFactory = null,
        CancellationToken cancellationToken = default);
}

Then exposing bespoke configuration options for individual transports

public record StdioClientTransportOptions
{
     public string Executable { get; init; }
     public IReadOnlyList<string> Arguments { get; init; }
     /* etc etc */
}

public class StdioClientTransport : IClientTransport
{
     public StdioClientTransport(StdioClientTransportOptions options, ....); // No McpServerConfig argument anymore
}

This seems perfectly doable, the only blocker in my view is that ITransport instances are currently stateful. For this to work best we need to be able to offload all their state in session objects created by the client factory. cc @halter73

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions