Class SseClientTransport
- Namespace
- ModelContextProtocol.Protocol.Transport
- Assembly
- ModelContextProtocol.dll
Provides an IClientTransport over HTTP using the Server-Sent Events (SSE) protocol.
public sealed class SseClientTransport : IClientTransport, IAsyncDisposable
- Inheritance
-
SseClientTransport
- Implements
- Inherited Members
Remarks
This transport connects to an MCP server over HTTP using SSE, allowing for real-time server-to-client communication with a standard HTTP request. Unlike the StdioClientTransport, this transport connects to an existing server rather than launching a new process.
Constructors
SseClientTransport(SseClientTransportOptions, ILoggerFactory?)
Initializes a new instance of the SseClientTransport class.
public SseClientTransport(SseClientTransportOptions transportOptions, ILoggerFactory? loggerFactory = null)
Parameters
transportOptions
SseClientTransportOptionsConfiguration options for the transport.
loggerFactory
ILoggerFactoryLogger factory for creating loggers used for diagnostic output during transport operations.
SseClientTransport(SseClientTransportOptions, HttpClient, ILoggerFactory?, bool)
Initializes a new instance of the SseClientTransport class with a provided HTTP client.
public SseClientTransport(SseClientTransportOptions transportOptions, HttpClient httpClient, ILoggerFactory? loggerFactory = null, bool ownsHttpClient = false)
Parameters
transportOptions
SseClientTransportOptionsConfiguration options for the transport.
httpClient
HttpClientThe HTTP client instance used for requests.
loggerFactory
ILoggerFactoryLogger factory for creating loggers used for diagnostic output during transport operations.
ownsHttpClient
booltrue to dispose of
httpClient
when the transport is disposed; false if the caller is retaining ownership of thehttpClient
's lifetime.
Properties
Name
Gets a transport identifier, used for logging purposes.
public string Name { get; }
Property Value
Methods
ConnectAsync(CancellationToken)
Asynchronously establishes a transport session with an MCP server and returns a transport for the duplex message stream.
public Task<ITransport> ConnectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe 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.
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.