-
Notifications
You must be signed in to change notification settings - Fork 739
Fix missing resultType on complete result responses #1684
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -384,6 +384,7 @@ private void ConfigureInitialize(McpServerOptions options) | |
| Instructions = options.ServerInstructions, | ||
| ServerInfo = options.ServerInfo ?? DefaultImplementation, | ||
| Capabilities = ServerCapabilities ?? new(), | ||
| ResultType = "complete", | ||
| }; | ||
| }, | ||
| McpJsonUtilities.JsonContext.Default.InitializeRequestParams, | ||
|
|
@@ -414,6 +415,7 @@ private void ConfigureDiscover(McpServerOptions options) | |
| // their "do not cache" behavior while satisfying the wire requirement. | ||
| TimeToLive = TimeSpan.Zero, | ||
| CacheScope = CacheScope.Private, | ||
| ResultType = "complete", | ||
| }); | ||
| }, | ||
| McpJsonUtilities.JsonContext.Default.DiscoverRequestParams, | ||
|
|
@@ -458,7 +460,7 @@ private void ConfigureSubscriptions(McpServerOptions options) | |
|
|
||
| await SendSubscriptionAckAsync(statelessSubscription, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| return new EmptyResult(); | ||
| return EmptyResult.Instance; | ||
| } | ||
|
|
||
| // Filter the requested notifications against what the server actually supports. | ||
|
|
@@ -498,7 +500,7 @@ private void ConfigureSubscriptions(McpServerOptions options) | |
| _activeSubscriptions.TryRemove(jsonRpcRequest.Id, out _); | ||
| } | ||
|
|
||
| return new EmptyResult(); | ||
| return EmptyResult.Instance; | ||
| }, | ||
| McpJsonUtilities.JsonContext.Default.SubscriptionsListenRequestParams, | ||
| McpJsonUtilities.JsonContext.Default.EmptyResult); | ||
|
|
@@ -1664,6 +1666,21 @@ private void SetHandler<TParams, TResult>( | |
| }; | ||
| } | ||
|
|
||
| if (typeof(Result).IsAssignableFrom(typeof(TResult))) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This misses custom |
||
| { | ||
| var innerHandler = handler; | ||
| handler = async (request, cancellationToken) => | ||
| { | ||
| var result = await innerHandler(request, cancellationToken).ConfigureAwait(false); | ||
| if (result is Result protocolResult && protocolResult.ResultType is null) | ||
| { | ||
| protocolResult.ResultType = "complete"; | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
| } | ||
|
|
||
| _requestHandlers.Set(method, | ||
| (request, jsonRpcRequest, cancellationToken) => | ||
| InvokeHandlerAsync(handler, request, jsonRpcRequest, cancellationToken), | ||
|
|
@@ -1678,6 +1695,25 @@ private void SetTaskAugmentedHandler<TParams, TResult>( | |
| JsonTypeInfo<CreateTaskResult> taskResultTypeInfo) | ||
| where TResult : Result | ||
| { | ||
| var innerHandler = handler; | ||
| handler = async (request, cancellationToken) => | ||
| { | ||
| var result = await innerHandler(request, cancellationToken).ConfigureAwait(false); | ||
| if (result.IsTask) | ||
| { | ||
| if (result.TaskCreated is { ResultType: null } taskCreated) | ||
| { | ||
| taskCreated.ResultType = "task"; | ||
| } | ||
| } | ||
| else if (result.Result is { ResultType: null } immediateResult) | ||
| { | ||
| immediateResult.ResultType = "complete"; | ||
| } | ||
|
|
||
| return result; | ||
| }; | ||
|
|
||
| _requestHandlers.SetTaskAugmented(method, | ||
| (request, jsonRpcRequest, cancellationToken) => | ||
| InvokeHandlerAsync(handler, request, jsonRpcRequest, cancellationToken), | ||
|
|
||
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.
I don't think we want to lock into these semantics. The spec says that client should treat null as complete but that is a behavior that shouldn't leak into the model IMO.