using ModelContextProtocol.Client;
using ModelContextProtocol.Protocol;
using ModelContextProtocol.Server;
namespace ModelContextProtocol;
///
/// Represents a client or server Model Context Protocol (MCP) session.
///
///
///
/// The MCP session provides the core communication functionality used by both clients and servers:
///
/// - Sending JSON-RPC requests and receiving responses.
/// - Sending notifications to the connected session.
/// - Registering handlers for receiving notifications.
///
///
///
/// serves as the base interface for both and
/// interfaces, providing the common functionality needed for MCP protocol
/// communication. Most applications will use these more specific interfaces rather than working with
/// directly.
///
///
/// All MCP sessions should be properly disposed after use as they implement .
///
///
public abstract partial class McpSession : IAsyncDisposable
{
/// Gets an identifier associated with the current MCP session.
///
/// Typically populated in transports supporting multiple sessions, such as Streamable HTTP or SSE.
/// Can return if the session hasn't initialized or if the transport doesn't
/// support multiple sessions (as is the case with STDIO).
///
public abstract string? SessionId { get; }
///
/// Gets the negotiated protocol version for the current MCP session.
///
///
/// Returns the protocol version negotiated during session initialization,
/// or if initialization hasn't yet occurred.
///
public abstract string? NegotiatedProtocolVersion { get; }
///
/// Sends a JSON-RPC request to the connected session and waits for a response.
///
/// The JSON-RPC request to send.
/// The to monitor for cancellation requests. The default is .
/// A task containing the session's response.
/// The transport is not connected, or another error occurred during request processing.
/// An error occurred during request processing.
///
/// This method provides low-level access to send raw JSON-RPC requests. For most use cases,
/// consider using the strongly-typed methods that provide a more convenient API.
///
public abstract Task SendRequestAsync(JsonRpcRequest request, CancellationToken cancellationToken = default);
///
/// Sends a JSON-RPC message to the connected session.
///
///
/// The JSON-RPC message to send. This can be any type that implements JsonRpcMessage, such as
/// JsonRpcRequest, JsonRpcResponse, JsonRpcNotification, or JsonRpcError.
///
/// The to monitor for cancellation requests. The default is .
/// A task that represents the asynchronous send operation.
/// The transport is not connected.
/// is .
///
///
/// This method provides low-level access to send any JSON-RPC message. For specific message types,
/// consider using the higher-level methods such as or methods
/// on this class that provide a simpler API.
///
///
/// The method serializes the message and transmits it using the underlying transport mechanism.
///
///
public abstract Task SendMessageAsync(JsonRpcMessage message, CancellationToken cancellationToken = default);
/// Registers a handler to be invoked when a notification for the specified method is received.
/// The notification method.
/// The handler to be invoked.
/// An that will remove the registered handler when disposed.
/// or is .
/// is empty or composed entirely of whitespace.
public abstract IAsyncDisposable RegisterNotificationHandler(string method, Func handler);
///
public abstract ValueTask DisposeAsync();
}