Table of Contents

Interface IClientTransport

Namespace
ModelContextProtocol.Protocol.Transport
Assembly
ModelContextProtocol.dll

Represents a transport mechanism for Model Context Protocol (MCP) client-to-server communication.

public interface IClientTransport

Remarks

The IClientTransport interface abstracts the communication layer between MCP clients and servers, allowing different transport protocols to be used interchangeably.

When creating an IMcpClient, McpClientFactory is typically used, and is provided with the IClientTransport based on expected server configuration.

Properties

Name

Gets a transport identifier, used for logging purposes.

string Name { get; }

Property Value

string

Methods

ConnectAsync(CancellationToken)

Asynchronously establishes a transport session with an MCP server and returns a transport for the duplex message stream.

Task<ITransport> ConnectAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

The CancellationToken to monitor for cancellation requests. The default is None.

Returns

Task<ITransport>

Returns an interface for the duplex message stream.

Remarks

This method is responsible for initializing the connection to the server using the specific transport mechanism implemented by the derived class. The returned ITransport interface provides methods to send and receive messages over the established connection.

The lifetime of the returned ITransport instance is typically managed by the ModelContextProtocol.Client.McpClient that uses this transport. When the client is disposed, it will dispose the transport session as well.

This method is used by McpClientFactory to initialize the connection.

Exceptions

McpTransportException

The transport connection could not be established.