using System.Diagnostics.CodeAnalysis;
using ModelContextProtocol.Protocol;
namespace ModelContextProtocol.Server;
///
/// Represents an instance of a Model Context Protocol (MCP) server that connects to and communicates with an MCP client.
///
public abstract partial class McpServer : McpSession
{
///
/// Initializes a new instance of the class.
///
[Experimental(Experimentals.Extensibility_DiagnosticId, UrlFormat = Experimentals.Extensibility_Url)]
protected McpServer()
{
}
///
/// Gets the capabilities supported by the client.
///
///
///
/// On protocol revisions that use the initialize handshake (2025-11-25 and earlier), these
/// capabilities are established once during initialization and are session-scoped: they are available both
/// on the root and on the server exposed to request handlers.
///
///
/// On the 2026-07-28 revision and later (SEP-2575) there is no initialize handshake; the client
/// declares its capabilities per-request in _meta, and the server MUST NOT infer them from previous
/// requests. In that mode this property is only meaningful on the request-scoped server accessed via
/// the Server property of the passed to a handler; on the
/// root (for example one constructed manually over a
/// ) it is .
/// It is also in stateless transport mode, where server-to-client requests are
/// unsupported.
///
///
/// Server implementations can check these capabilities to determine which features
/// are available when interacting with the client.
///
///
public abstract ClientCapabilities? ClientCapabilities { get; }
///
/// Gets the version and implementation information of the connected client.
///
///
///
/// This property contains identification information about the client that has connected to this server,
/// including its name and version.
///
///
/// On protocol revisions that use the initialize handshake (2025-11-25 and earlier) this
/// information is provided once during initialization and is session-scoped. On the 2026-07-28
/// revision and later it is carried per-request in _meta, so read it from the request-scoped server
/// accessed via the Server property of the passed to a handler
/// rather than from the root .
///
///
/// Server implementations can use this information for logging, tracking client versions,
/// or implementing client-specific behaviors.
///
///
public abstract Implementation? ClientInfo { get; }
///
/// Gets the options used to construct this server.
///
///
/// These options define the server's capabilities, protocol version, and other configuration
/// settings that were used to initialize the server.
///
public abstract McpServerOptions ServerOptions { get; }
///
/// Gets the service provider for the server.
///
public abstract IServiceProvider? Services { get; }
/// Gets the last logging level set by the client, or if it's never been set.
[Obsolete(Obsoletions.DeprecatedLogging_Message, DiagnosticId = Obsoletions.Deprecated_DiagnosticId, UrlFormat = Obsoletions.Deprecated_Url)]
public abstract LoggingLevel? LoggingLevel { get; }
///
/// Gets a value indicating whether the connected client supports Multi Round-Trip Requests (MRTR).
///
///
///
/// When this property returns , tool handlers can throw
/// to return an
/// with and/or
/// to the client.
///
///
/// When this property returns , tool handlers should provide a fallback
/// experience (for example, returning a text message explaining that the client does not support
/// the required feature) instead of throwing .
///
///
public virtual bool IsMrtrSupported => false;
///
/// Runs the server, listening for and handling client requests.
///
public abstract Task RunAsync(CancellationToken cancellationToken = default);
}