using ModelContextProtocol.Authentication; namespace ModelContextProtocol.Client; /// /// Provides options for configuring instances. /// public sealed class HttpClientTransportOptions { /// /// Gets or sets the base address of the server for SSE connections. /// /// The value is . /// The value is not an absolute URI, or does not use the HTTP or HTTPS scheme. public required Uri Endpoint { get; set { if (value is null) { throw new ArgumentNullException(nameof(value), "Endpoint cannot be null."); } if (!value.IsAbsoluteUri) { throw new ArgumentException("Endpoint must be an absolute URI.", nameof(value)); } if (value.Scheme != Uri.UriSchemeHttp && value.Scheme != Uri.UriSchemeHttps) { throw new ArgumentException("Endpoint must use HTTP or HTTPS scheme.", nameof(value)); } field = value; } } /// /// Gets or sets the transport mode to use for the connection. /// /// /// The transport mode to use for the connection. The default is . /// /// /// When set to (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. /// /// Streamable HTTP transport specification. /// HTTP with SSE transport specification. public HttpTransportMode TransportMode { get; set; } = HttpTransportMode.AutoDetect; /// /// Gets or sets a transport identifier used for logging purposes. /// public string? Name { get; set; } /// /// Gets or sets a timeout used to establish the initial connection to the SSE server. /// /// /// The timeout used to establish the initial connection to the SSE server. The default is 30 seconds. /// /// /// 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 is thrown. /// public TimeSpan ConnectionTimeout { get; set; } = TimeSpan.FromSeconds(30); /// /// Gets or sets custom HTTP headers to include in requests to the SSE server. /// /// /// Use this property to specify custom HTTP headers that should be sent with each request to the server. /// public IDictionary? AdditionalHeaders { get; set; } /// /// Gets or sets a session identifier that should be reused when connecting to a Streamable HTTP server. /// /// /// /// When non-, 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 /// /// to skip the initialization handshake when rehydrating a previously negotiated session. /// /// public string? KnownSessionId { get; set; } /// /// Gets or sets a value indicating whether this transport endpoint is responsible for ending the session on dispose. /// /// /// When (default), the transport sends a DELETE request that informs the server the session is /// complete. Set this to when creating a transport used solely to bootstrap session information /// that will later be resumed elsewhere. /// public bool OwnsSession { get; set; } = true; /// /// Gets sor sets the authorization provider to use for authentication. /// public ClientOAuthOptions? OAuth { get; set; } /// /// Gets or sets the maximum number of consecutive reconnection attempts when an SSE stream is disconnected. /// /// /// The maximum number of reconnection attempts. The default is 2. /// /// /// 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. /// public int MaxReconnectionAttempts { get; set; } = 2; /// /// Gets or sets the default interval at which the client attempts reconnection after an SSE stream is disconnected. /// /// ///

/// 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. ///

///
public TimeSpan DefaultReconnectionInterval { get; set; } = TimeSpan.FromSeconds(1); }