using System.ComponentModel; using ModelContextProtocol.Client; using ModelContextProtocol.Protocol; using ModelContextProtocol.Server; namespace ModelContextProtocol; /// /// Represents a client or server Model Context Protocol (MCP) endpoint. /// /// /// /// The MCP endpoint provides the core communication functionality used by both clients and servers: /// /// Sending JSON-RPC requests and receiving responses. /// Sending notifications to the connected endpoint. /// 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 endpoints should be properly disposed after use as they implement . /// /// [Obsolete($"Use {nameof(McpSession)} instead. This member will be removed in a subsequent release.")] // See: https://github.com/modelcontextprotocol/csharp-sdk/issues/774 [EditorBrowsable(EditorBrowsableState.Never)] public interface IMcpEndpoint : 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). /// string? SessionId { get; } /// /// Sends a JSON-RPC request to the connected endpoint and waits for a response. /// /// The JSON-RPC request to send. /// The to monitor for cancellation requests. The default is . /// A task containing the endpoint's response. /// The transport is not connected, or another error occurs during request processing. /// An error occured during request processing. /// /// This method provides low-level access to send raw JSON-RPC requests. For most use cases, /// consider using the strongly-typed extension methods that provide a more convenient API. /// Task SendRequestAsync(JsonRpcRequest request, CancellationToken cancellationToken = default); /// /// Sends a JSON-RPC message to the connected endpoint. /// /// /// 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 extension methods /// like , /// which provide a simpler API. /// /// /// The method will serialize the message and transmit it using the underlying transport mechanism. /// /// 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. IAsyncDisposable RegisterNotificationHandler(string method, Func handler); }