Class McpClientFactory
- Namespace
- ModelContextProtocol.Client
- Assembly
- ModelContextProtocol.dll
Provides factory methods for creating Model Context Protocol (MCP) clients.
public static class McpClientFactory
- Inheritance
-
McpClientFactory
- Inherited Members
Remarks
This factory class is the primary way to instantiate IMcpClient instances that connect to MCP servers. It handles the creation and connection of appropriate implementations through the supplied transport.
Methods
CreateAsync(IClientTransport, McpClientOptions?, ILoggerFactory?, CancellationToken)
Creates an IMcpClient, connecting it to the specified server.
public static Task<IMcpClient> CreateAsync(IClientTransport clientTransport, McpClientOptions? clientOptions = null, ILoggerFactory? loggerFactory = null, CancellationToken cancellationToken = default)
Parameters
clientTransport
IClientTransportThe transport instance used to communicate with the server.
clientOptions
McpClientOptionsA client configuration object which specifies client capabilities and protocol version. If null, details based on the current process will be employed.
loggerFactory
ILoggerFactoryA logger factory for creating loggers for clients.
cancellationToken
CancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- Task<IMcpClient>
An IMcpClient that's connected to the specified server.
Exceptions
- ArgumentNullException
clientTransport
is null.- ArgumentNullException
clientOptions
is null.