-
Notifications
You must be signed in to change notification settings - Fork 555
Extend progress notification support #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
stephentoub
merged 2 commits into
modelcontextprotocol:main
from
Tyler-R-Kendrick:progress-tokens
Apr 1, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using ModelContextProtocol.Protocol.Messages; | ||
|
|
||
| namespace ModelContextProtocol; | ||
|
|
||
| /// <summary>Represents a client or server MCP endpoint.</summary> | ||
| public interface IMcpEndpoint : IAsyncDisposable | ||
| { | ||
| /// <summary>Sends a generic JSON-RPC request to the connected endpoint.</summary> | ||
| /// <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<TResult> SendRequestAsync<TResult>(JsonRpcRequest request, CancellationToken cancellationToken = default) where TResult : class; | ||
|
|
||
| /// <summary>Sends a message to the connected endpoint.</summary> | ||
| /// <param name="message">The message.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| Task SendMessageAsync(IJsonRpcMessage message, CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Adds a handler for server notifications of a specific method. | ||
| /// </summary> | ||
| /// <param name="method">The notification method to handle.</param> | ||
| /// <param name="handler">The async handler function to process notifications.</param> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Each method may have multiple handlers. Adding a handler for a method that already has one | ||
| /// will not replace the existing handler. | ||
| /// </para> | ||
| /// <para> | ||
| /// <see cref="NotificationMethods"> provides constants for common notification methods.</see> | ||
| /// </para> | ||
| /// </remarks> | ||
| void AddNotificationHandler(string method, Func<JsonRpcNotification, Task> handler); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| using ModelContextProtocol.Protocol.Messages; | ||
| using ModelContextProtocol.Utils; | ||
|
|
||
| namespace ModelContextProtocol; | ||
|
|
||
| /// <summary>Provides extension methods for interacting with an <see cref="IMcpEndpoint"/>.</summary> | ||
| public static class McpEndpointExtensions | ||
| { | ||
| /// <summary>Notifies the connected endpoint of progress.</summary> | ||
| /// <param name="endpoint">The endpoint issueing the notification.</param> | ||
| /// <param name="progressToken">The <see cref="ProgressToken"/> identifying the operation.</param> | ||
| /// <param name="progress">The progress update to send.</param> | ||
| /// <param name="cancellationToken">A token to cancel the operation.</param> | ||
| /// <returns>A task representing the completion of the operation.</returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="endpoint"/> is <see langword="null"/>.</exception> | ||
| public static Task NotifyProgressAsync( | ||
| this IMcpEndpoint endpoint, | ||
| ProgressToken progressToken, | ||
| ProgressNotificationValue progress, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| Throw.IfNull(endpoint); | ||
|
|
||
| return endpoint.SendMessageAsync(new JsonRpcNotification() | ||
| { | ||
| Method = NotificationMethods.ProgressNotification, | ||
| Params = new ProgressNotification() | ||
| { | ||
| ProgressToken = progressToken, | ||
| Progress = progress, | ||
| }, | ||
| }, cancellationToken); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/ModelContextProtocol/Protocol/Types/PaginatedRequest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace ModelContextProtocol.Protocol.Types; | ||
|
|
||
| /// <summary> | ||
| /// Used as a base class for paginated requests. | ||
| /// <see href="https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.json">See the schema for details</see> | ||
| /// </summary> | ||
| public class PaginatedRequestParams : RequestParams | ||
| { | ||
| /// <summary> | ||
| /// An opaque token representing the current pagination position. | ||
| /// If provided, the server should return results starting after this cursor. | ||
| /// </summary> | ||
| [System.Text.Json.Serialization.JsonPropertyName("cursor")] | ||
| public string? Cursor { get; init; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.