Skip to content

Commit 16690b1

Browse files
jeffhandleyCopilot
andcommitted
Move Tasks feature into ModelContextProtocol.Extensions.Tasks
- Add TaskMethods/TaskMetaKeys consts (tasks/get|update|cancel, notification, related-task) - Add McpServerTasksExtensions: WithTasks(McpServerOptions/IMcpServerBuilder), SendTaskStatusNotificationAsync, store-backed tasks/* raw handlers gated to draft, and a tools/call wrapper that runs tasks in the background via the outgoing-request interceptor seam - Add McpClientTasksExtensions: CallToolAsTaskAsync, CallToolRawAsync, GetTaskAsync/UpdateTaskAsync/CancelTaskAsync, PollTaskToCompletionAsync - Add JsonNode to TasksJsonContext; replace internal Throw with inline null checks in ResultOrCreatedTask - Include only the attribute polyfills the Tasks DTOs need (required/init) on netstandard2.0 - Relax Result/RequestParams/NotificationParams base ctors to protected so the moved DTOs can derive across the assembly boundary - Register the new project in ModelContextProtocol.slnx Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 9011736 commit 16690b1

10 files changed

Lines changed: 830 additions & 11 deletions

File tree

ModelContextProtocol.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Project Path="src/ModelContextProtocol.AspNetCore/ModelContextProtocol.AspNetCore.csproj" />
7070
<Project Path="src/ModelContextProtocol.Core/ModelContextProtocol.Core.csproj" />
7171
<Project Path="src/ModelContextProtocol.Extensions.Apps/ModelContextProtocol.Extensions.Apps.csproj" />
72+
<Project Path="src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj" />
7273
<Project Path="src/ModelContextProtocol/ModelContextProtocol.csproj" />
7374
</Folder>
7475
<Folder Name="/tests/">

src/ModelContextProtocol.Core/Protocol/NotificationParams.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace ModelContextProtocol.Protocol;
88
/// </summary>
99
public abstract class NotificationParams
1010
{
11-
/// <summary>Prevent external derivations.</summary>
12-
private protected NotificationParams()
11+
/// <summary>Allow derivations only within the SDK and its extension packages.</summary>
12+
protected NotificationParams()
1313
{
1414
}
1515

src/ModelContextProtocol.Core/Protocol/RequestParams.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ namespace ModelContextProtocol.Protocol;
1111
/// </remarks>
1212
public abstract class RequestParams
1313
{
14-
/// <summary>Prevent external derivations.</summary>
15-
private protected RequestParams()
14+
/// <summary>Allow derivations only within the SDK and its extension packages.</summary>
15+
protected RequestParams()
1616
{
1717
}
1818

src/ModelContextProtocol.Core/Protocol/Result.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace ModelContextProtocol.Protocol;
88
/// </summary>
99
public abstract class Result
1010
{
11-
/// <summary>Prevent external derivations.</summary>
12-
private protected Result()
11+
/// <summary>Allow derivations only within the SDK and its extension packages.</summary>
12+
protected Result()
1313
{
1414
}
1515

src/ModelContextProtocol.Extensions.Tasks/Client/McpClientTasksExtensions.cs

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

src/ModelContextProtocol.Extensions.Tasks/ModelContextProtocol.Extensions.Tasks.csproj

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@
2626
<Compile Include="..\Common\Experimentals.cs" Link="Experimentals.cs" />
2727
</ItemGroup>
2828

29-
<!-- Exclude polyfills inherited from Directory.Build.props; this package only needs the ExperimentalAttribute polyfill. -->
29+
<!-- Exclude polyfills inherited from Directory.Build.props; include only the attribute polyfills these DTOs need. -->
3030
<ItemGroup>
3131
<Compile Remove="..\Common\Polyfills\**\*.cs" />
3232
<Compile Include="..\Common\Polyfills\System\Diagnostics\CodeAnalysis\ExperimentalAttribute.cs"
3333
Link="Polyfills\ExperimentalAttribute.cs" />
34+
<Compile Include="..\Common\Polyfills\System\Diagnostics\CodeAnalysis\NullableAttributes.cs"
35+
Link="Polyfills\NullableAttributes.cs" />
36+
<Compile Include="..\Common\Polyfills\System\Diagnostics\CodeAnalysis\SetsRequiredMembersAttribute.cs"
37+
Link="Polyfills\SetsRequiredMembersAttribute.cs" />
38+
<Compile Include="..\Common\Polyfills\System\Runtime\CompilerServices\CompilerFeatureRequiredAttribute.cs"
39+
Link="Polyfills\CompilerFeatureRequiredAttribute.cs" />
40+
<Compile Include="..\Common\Polyfills\System\Runtime\CompilerServices\RequiredMemberAttribute.cs"
41+
Link="Polyfills\RequiredMemberAttribute.cs" />
42+
<Compile Include="..\Common\Polyfills\System\Runtime\CompilerServices\IsExternalInit.cs"
43+
Link="Polyfills\IsExternalInit.cs" />
3444
</ItemGroup>
3545

3646
<ItemGroup>

src/ModelContextProtocol.Extensions.Tasks/Protocol/ResultOrCreatedTask.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public class ResultOrCreatedTask<TResult> where TResult : Result
3131
/// <param name="result">The standard result returned by the server.</param>
3232
public ResultOrCreatedTask(TResult result)
3333
{
34-
Throw.IfNull(result);
35-
_result = result;
34+
_result = result ?? throw new ArgumentNullException(nameof(result));
3635
}
3736

3837
/// <summary>
@@ -41,8 +40,7 @@ public ResultOrCreatedTask(TResult result)
4140
/// <param name="taskCreated">The task creation result returned by the server.</param>
4241
public ResultOrCreatedTask(CreateTaskResult taskCreated)
4342
{
44-
Throw.IfNull(taskCreated);
45-
_taskCreated = taskCreated;
43+
_taskCreated = taskCreated ?? throw new ArgumentNullException(nameof(taskCreated));
4644
}
4745

4846
/// <summary>

src/ModelContextProtocol.Extensions.Tasks/Server/McpServerTasksExtensions.cs

Lines changed: 377 additions & 0 deletions
Large diffs are not rendered by default.

src/ModelContextProtocol.Extensions.Tasks/Server/TasksJsonContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace ModelContextProtocol.Extensions.Tasks;
3636
[JsonSerializable(typeof(IDictionary<string, InputRequest>))]
3737
[JsonSerializable(typeof(IDictionary<string, InputResponse>))]
3838
[JsonSerializable(typeof(JsonObject))]
39+
[JsonSerializable(typeof(JsonNode))]
3940
[JsonSerializable(typeof(JsonElement))]
4041
[JsonSerializable(typeof(JsonRpcErrorDetail))]
4142
internal sealed partial class TasksJsonContext : JsonSerializerContext
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace ModelContextProtocol.Extensions.Tasks;
2+
3+
/// <summary>
4+
/// Provides constants for the JSON-RPC methods defined by the MCP Tasks extension (SEP-2663).
5+
/// </summary>
6+
public static class TaskMethods
7+
{
8+
/// <summary>The <c>tasks/get</c> request method, used to retrieve the current state of a task.</summary>
9+
public const string Get = "tasks/get";
10+
11+
/// <summary>The <c>tasks/update</c> request method, used to provide input responses to a task.</summary>
12+
public const string Update = "tasks/update";
13+
14+
/// <summary>The <c>tasks/cancel</c> request method, used to request cancellation of a task.</summary>
15+
public const string Cancel = "tasks/cancel";
16+
17+
/// <summary>The <c>notifications/tasks/status</c> notification method, used to push task status updates.</summary>
18+
public const string StatusNotification = "notifications/tasks/status";
19+
}
20+
21+
/// <summary>
22+
/// Provides constants for the <c>_meta</c> keys defined by the MCP Tasks extension (SEP-2663).
23+
/// </summary>
24+
public static class TaskMetaKeys
25+
{
26+
/// <summary>The <c>_meta</c> key carrying the related task identifier.</summary>
27+
public const string RelatedTask = "io.modelcontextprotocol/related-task";
28+
}

0 commit comments

Comments
 (0)