Refactor transports to help enable graceful shutdown (#142)
- This also paves the way for better multi-session support - We should definitely rethink names for the transport API - For now, I kept the names similar as possible, so we can focus on the API shape Co-authored-by: Stephen Toub <stoub@microsoft.com>
This commit is contained in:
parent
d47c834fa9
commit
2ab9db0878
1 changed files with 2015 additions and 1847 deletions
|
|
@ -8,11 +8,6 @@ namespace ModelContextProtocol.Server;
|
|||
/// </summary>
|
||||
public interface IMcpServer : IAsyncDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the server has been initialized.
|
||||
/// </summary>
|
||||
bool IsInitialized { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the capabilities supported by the client.
|
||||
/// </summary>
|
||||
|
|
@ -48,23 +43,23 @@ public interface IMcpServer : IAsyncDisposable
|
|||
void AddNotificationHandler(string method, Func<JsonRpcNotification, Task> handler);
|
||||
|
||||
/// <summary>
|
||||
/// Starts the server and begins listening for client requests.
|
||||
/// Runs the server, listening for and handling client requests.
|
||||
/// </summary>
|
||||
Task StartAsync(CancellationToken cancellationToken = default);
|
||||
Task RunAsync(CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a generic JSON-RPC request to the client.
|
||||
/// NB! This is a temporary method that is available to send not yet implemented feature messages.
|
||||
/// NB! This is a temporary method that is available to send not yet implemented feature messages.
|
||||
/// Once all MCP features are implemented this will be made private, as it is purely a convenience for those who wish to implement features ahead of the library.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The expected response type.</typeparam>
|
||||
/// <typeparam name="TResult">The expected response type.</typeparam>
|
||||
/// <param name="request">The JSON-RPC request to send.</param>
|
||||
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
||||
/// <returns>A task containing the client's response.</returns>
|
||||
Task<T> SendRequestAsync<T>(JsonRpcRequest request, CancellationToken cancellationToken) where T : class;
|
||||
Task<TResult> SendRequestAsync<TResult>(JsonRpcRequest request, CancellationToken cancellationToken = default) where TResult : class;
|
||||
|
||||
/// <summary>
|
||||
/// Sends a message to the server.
|
||||
/// Sends a message to the client.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
/// <param name="cancellationToken">A token to cancel the operation.</param>
|
||||
|
|
|
|||
Loading…
Reference in a new issue