Table of Contents

Class HttpClientTransportOptions

Namespace
ModelContextProtocol.Client
Assembly
ModelContextProtocol.Core.dll

Provides options for configuring HttpClientTransport instances.

public sealed class HttpClientTransportOptions
Inheritance
HttpClientTransportOptions
Inherited Members

Properties

AdditionalHeaders

Gets or sets custom HTTP headers to include in requests to the SSE server.

public IDictionary<string, string>? AdditionalHeaders { get; set; }

Property Value

IDictionary<string, string>

Remarks

Use this property to specify custom HTTP headers that should be sent with each request to the server.

ConnectionTimeout

Gets or sets a timeout used to establish the initial connection to the SSE server.

public TimeSpan ConnectionTimeout { get; set; }

Property Value

TimeSpan

The timeout used to establish the initial connection to the SSE server. The default is 30 seconds.

Remarks

This timeout controls how long the client waits for:

  • The initial HTTP connection to be established with the SSE server.
  • The endpoint event to be received, which indicates the message endpoint URL.
If the timeout expires before the connection is established, a TimeoutException is thrown.

DefaultReconnectionInterval

Gets or sets the default interval at which the client attempts reconnection after an SSE stream is disconnected.

public TimeSpan DefaultReconnectionInterval { get; set; }

Property Value

TimeSpan

Remarks

The default value is 1 second.

If the server sends a message specifying a different reconnection interval, that new value will be used for all subsequent reconnection attempts for that stream.

Endpoint

Gets or sets the base address of the server for SSE connections.

public required Uri Endpoint { get; set; }

Property Value

Uri

Exceptions

ArgumentNullException

The value is null.

ArgumentException

The value is not an absolute URI, or does not use the HTTP or HTTPS scheme.

KnownSessionId

Gets or sets a session identifier that should be reused when connecting to a Streamable HTTP server.

public string? KnownSessionId { get; set; }

Property Value

string

Remarks

When non-null, the transport assumes the server already created the session and will include the specified session identifier in every HTTP request. This allows reconnecting to an existing session created in a previous process. This option is only supported by the Streamable HTTP transport mode.

Clients should pair this with ResumeSessionAsync(IClientTransport, ResumeClientSessionOptions, McpClientOptions?, ILoggerFactory?, CancellationToken) to skip the initialization handshake when rehydrating a previously negotiated session.

MaxReconnectionAttempts

Gets or sets the maximum number of consecutive reconnection attempts when an SSE stream is disconnected.

public int MaxReconnectionAttempts { get; set; }

Property Value

int

The maximum number of reconnection attempts. The default is 2.

Remarks

When an SSE stream is disconnected (e.g., due to a network issue), the client will attempt to reconnect using the Last-Event-ID header to resume from where it left off. This property controls how many reconnection attempts are made before giving up.

Name

Gets or sets a transport identifier used for logging purposes.

public string? Name { get; set; }

Property Value

string

OAuth

Gets sor sets the authorization provider to use for authentication.

public ClientOAuthOptions? OAuth { get; set; }

Property Value

ClientOAuthOptions

OwnsSession

Gets or sets a value indicating whether this transport endpoint is responsible for ending the session on dispose.

public bool OwnsSession { get; set; }

Property Value

bool

Remarks

When true (default), the transport sends a DELETE request that informs the server the session is complete. Set this to false when creating a transport used solely to bootstrap session information that will later be resumed elsewhere.

TransportMode

Gets or sets the transport mode to use for the connection.

public HttpTransportMode TransportMode { get; set; }

Property Value

HttpTransportMode

The transport mode to use for the connection. The default is AutoDetect.

Remarks

When set to AutoDetect (the default), the client will first attempt to use Streamable HTTP transport and automatically fall back to SSE transport if the server doesn't support it.

See Also