-
Notifications
You must be signed in to change notification settings - Fork 843
Lazy index docs in MCP tools and report progress #14341
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Aspire.Cli.Mcp; | ||
|
|
||
| /// <summary> | ||
| /// Interface for sending MCP notifications. | ||
| /// </summary> | ||
| internal interface IMcpNotifier | ||
| { | ||
| /// <summary> | ||
| /// Sends a notification to the MCP client. | ||
| /// </summary> | ||
| /// <param name="method">The notification method name.</param> | ||
| /// <param name="cancellationToken">The cancellation token.</param> | ||
| /// <returns>A task representing the asynchronous operation.</returns> | ||
| Task SendNotificationAsync(string method, CancellationToken cancellationToken = default); | ||
|
|
||
| Task SendNotificationAsync<TParams>(string method, TParams parameters, CancellationToken cancellationToken = default); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using ModelContextProtocol.Server; | ||
|
|
||
| namespace Aspire.Cli.Mcp; | ||
|
|
||
| /// <summary> | ||
| /// Implementation of <see cref="IMcpNotifier"/> that wraps an <see cref="McpServer"/>. | ||
| /// </summary> | ||
| internal sealed class McpServerNotifier(McpServer server) : IMcpNotifier | ||
| { | ||
| /// <inheritdoc /> | ||
| public Task SendNotificationAsync(string method, CancellationToken cancellationToken = default) | ||
| { | ||
| return server.SendNotificationAsync(method, cancellationToken); | ||
| } | ||
|
|
||
| /// <inheritdoc /> | ||
| public Task SendNotificationAsync<TParams>(string method, TParams parameters, CancellationToken cancellationToken = default) | ||
| { | ||
| return server.SendNotificationAsync(method, parameters, cancellationToken: cancellationToken); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Text.Json; | ||
| using ModelContextProtocol.Protocol; | ||
|
|
||
| namespace Aspire.Cli.Mcp.Tools; | ||
|
|
||
| /// <summary> | ||
| /// Provides context for executing MCP tools. | ||
| /// </summary> | ||
| internal sealed class CallToolContext | ||
| { | ||
| /// <summary> | ||
| /// Gets the MCP notifier for sending notifications. | ||
| /// </summary> | ||
| public required IMcpNotifier Notifier { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the MCP client instance to use for communicating with the dashboard. | ||
| /// </summary> | ||
| public required ModelContextProtocol.Client.McpClient? McpClient { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the arguments passed to the tool. | ||
| /// </summary> | ||
| public required IReadOnlyDictionary<string, JsonElement>? Arguments { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the progress token for reporting progress updates, if provided by the client. | ||
| /// </summary> | ||
| public required ProgressToken? ProgressToken { get; init; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Aspire.Cli.Mcp.Docs; | ||
| using ModelContextProtocol; | ||
| using ModelContextProtocol.Protocol; | ||
|
|
||
| namespace Aspire.Cli.Mcp.Tools; | ||
|
|
||
| /// <summary> | ||
| /// Helper methods for documentation tool operations. | ||
| /// </summary> | ||
| internal static class DocsToolHelper | ||
| { | ||
| /// <summary> | ||
| /// Ensures the documentation index is ready, sending progress notifications if indexing is needed. | ||
| /// </summary> | ||
| public static async ValueTask EnsureIndexedWithNotificationsAsync( | ||
| IDocsIndexService docsIndexService, | ||
| ProgressToken? progressToken, | ||
| IMcpNotifier notifier, | ||
| CancellationToken cancellationToken) | ||
|
Comment on lines
+18
to
+22
|
||
| { | ||
| if (docsIndexService.IsIndexed) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| if (progressToken != null) | ||
| { | ||
| await notifier.SendNotificationAsync( | ||
| NotificationMethods.ProgressNotification, | ||
| new ProgressNotificationParams | ||
| { | ||
| ProgressToken = progressToken.Value, | ||
| Progress = new ProgressNotificationValue | ||
| { | ||
| Message = "Indexing Aspire docs...", | ||
| Progress = 1 | ||
| } | ||
| }, cancellationToken).ConfigureAwait(false); | ||
| } | ||
|
|
||
| await docsIndexService.EnsureIndexedAsync(cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (progressToken != null) | ||
| { | ||
| await notifier.SendNotificationAsync( | ||
| NotificationMethods.ProgressNotification, | ||
| new ProgressNotificationParams | ||
| { | ||
| ProgressToken = progressToken.Value, | ||
| Progress = new ProgressNotificationValue | ||
| { | ||
| Message = "Aspire docs indexed", | ||
| Progress = 2 | ||
| } | ||
| }, cancellationToken).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second
SendNotificationAsyncmethod overload is missing XML documentation. According to the custom guidelines (CodingGuidelineID: 1000002), all internal APIs should have at least a brief summary tag. Please add documentation for this method including param and returns tags.