Extract Tasks into ModelContextProtocol.Extensions.Tasks (typed seams)#26
Open
jeffhandley wants to merge 3 commits into
Open
Extract Tasks into ModelContextProtocol.Extensions.Tasks (typed seams)#26jeffhandley wants to merge 3 commits into
jeffhandley wants to merge 3 commits into
Conversation
- Add ResultOrAlternate<TResult> replacing task-specific types in server pipeline - Add McpServerRequestHandler for custom request handler registration (seam #1) - Add McpServerOptions.RequestHandlers property with wiring in McpServerImpl - Rename CallToolWithTaskHandler/Filters to CallToolWithAlternateHandler/Filters - Rename SetTaskAugmented to SetWithAlternate (remove tasks/get guard) - Rename InvokeToolAsTask to InvokeToolWithAlternate - Rename BuildInitialTaskToolFilter to BuildInitialAlternateToolFilter - Make McpClient.ResolveInputRequestsAsync public (seam #4) - Update test references to use new names - Adapt TaskHandlerConfigurationValidationTests for removed guard Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Create src/ModelContextProtocol.Extensions.Tasks/ with csproj, JSON context, server builder extensions, client extension methods - Move task protocol DTOs (CreateTaskResult, GetTaskResult, UpdateTask*, CancelTask*, McpTaskStatus, TaskStatusNotificationParams) to extension - Move server types (IMcpTaskStore, InMemoryMcpTaskStore, McpTaskInfo, InputResponseReceivedEventArgs) to extension - Move task constants (RequestMethods.Tasks*, NotificationMethods.TaskStatus*, MetaKeys.RelatedTask, McpExtensions.Tasks) into TasksProtocol static class - Delete McpTaskExecutionContext, ResultOrCreatedTask from Core - Remove ~18 task [JsonSerializable] entries from McpJsonUtilities - Remove McpServerOptions.TaskStore and McpClientOptions.MaxConsecutiveStuckPolls - Remove task client methods from McpClient (CallToolRawAsync, PollTaskToCompletion, GetTaskAsync, UpdateTaskAsync, CancelTaskAsync, GetMetaWithTaskCapability, ThrowIfTasksNotSupported) - Remove task server methods/handlers (GetTaskHandler, UpdateTaskHandler, CancelTaskHandler, ConfigureTasks, InvokeToolAsTask, task cancellation sources) - Add Tasks_DiagnosticId (MCPEXP001) to Experimentals.cs - Extension WithTasks(store) registers request handlers via seam #1, alternate filter via seam #2, interceptor via seam #3 - Extension client methods: CallToolAsTaskAsync, CallToolWithPollingAsync, GetTaskAsync, UpdateTaskAsync, CancelTaskAsync - Manually serialize/deserialize InputResponses in UpdateTaskAsync to handle internal Core property visibility across assembly boundary - Update test project and TasksExtension sample to reference new package - Update all task test files with new using and extension API Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Restore the inline-result branch comment on the !raw.IsTask path - Restore the CompletedTaskResult JsonElement deserialization comment - Restore the RunReport sleep-vs-real-work comment Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Extracts the SEP-2663 Tasks feature out of
ModelContextProtocol.Coreinto a newbolt-on package,
ModelContextProtocol.Extensions.Tasks, mirroring the existingModelContextProtocol.Extensions.Apps. After this change Core has no compile-timeknowledge of Tasks; the extension references the main package and adds Tasks behavior
entirely from the side.
Unlike Apps -- which was pure additive metadata over existing public APIs -- Tasks was
woven into Core's request-dispatch pipeline (task-augmented
tools/call, AsyncLocalredirection of
sampling/elicitation/roots, and transparent client polling). To makea clean side bolt-on possible, Core gains a small set of generic, reusable public seams
(no Tasks-specific surface, no
InternalsVisibleTo).New public Core API surface (the seams)
Protocol-version gating reuses existing public surface rather than adding a new
draft-detection API: the extension links
McpHttpHeaders.July2026ProtocolVersion/IsJuly2026OrLaterProtocolVersionand floors on the July 2026 (or later) revision thatintroduces tasks.
What moves to the extension
All Tasks-specific types and machinery move to
ModelContextProtocol.Extensions.Tasks:CreateTaskResult,GetTaskRequestParams/Result,UpdateTaskRequestParams/Result,CancelTaskRequestParams/Result,TaskStatusNotificationParams,McpTaskStatus,ResultOrCreatedTask.IMcpTaskStore,InMemoryMcpTaskStore,McpTaskExecutionContext,McpTaskInfo,InputResponseReceivedEventArgs.tools/callwrapper, thesampling/elicitation/rootsAsyncLocal redirection, and the client transparent-polling loop -- re-expressed
on top of the generic Core seams above.
tasks/*request methods,notifications/tasks/status, thetaskresultdiscriminator, the
RelatedTaskmeta key, and thetasksextension capabilitystring -- all owned by the extension.
[JsonSerializable]registrations move to the extension's JSON context.Public entry points become extension methods, mirroring Apps:
builder.WithTasks(...)for servers andclient.GetTaskAsync(...)/CancelTaskAsync/UpdateTaskAsyncfor clients.Design rationale (typed seams)
ResultOrAlternate<TResult>andMcpServerRequestHandlerare generic and reusable beyond Tasks, so Core exposes ageneral extensibility primitive rather than a Tasks-shaped one.
InterceptOutgoingRequests(...)returning anIDisposablescope rather than apublic mutable static
AsyncLocal, keeping the redirection lifetime explicit.InternalsVisibleTo. The extension depends only on public Core API, exactlylike Apps.
Breaking changes
This is a preview SDK and the change is intentionally breaking:
ModelContextProtocol(.Core)into the newModelContextProtocol.Extensions.Taskspackage; consumers add a package referenceand a
using.TaskStorewiring and client task operations are now extension methods(
WithTasks(...),client.GetTaskAsync(...), etc.) rather than Core members.ExperimentalAttributefrom official Extensions/Tasks/MRTR APIs and alignMCPEXP001usage modelcontextprotocol/csharp-sdk#1642, the moved Tasks APIs are non-experimental (no[Experimental]).Validation
dotnet buildclean (0/0) across net10.0/net9.0/net8.0/netstandard2.0 withTreatWarningsAsErrors=true.