Implement MCP task support (SEP-1686) (#1170)

Co-authored-by: Stephen Halter <halter73@gmail.com>
This commit is contained in:
Eirik Tsarpalis 2026-01-28 05:21:02 +02:00 • committed by GitHub
commit 10e4f5b20f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11580 additions and 46 deletions

View file

@ -26,6 +26,17 @@ public static class McpServerServiceCollectionExtensions
services.Configure(configureOptions);
}
// Register IMcpTaskStore from options if not already registered.
// This allows users to either:
// 1. Register IMcpTaskStore directly in DI (takes precedence)
// 2. Set options.TaskStore in the configuration callback (used as fallback)
// If neither is done, resolving IMcpTaskStore will throw.
services.TryAddSingleton<IMcpTaskStore>(sp =>
{
var options = sp.GetRequiredService<IOptions<McpServerOptions>>().Value;
return options.TaskStore ?? throw new InvalidOperationException("No IMcpTaskStore has been configured. Either register an IMcpTaskStore in the service collection or set McpServerOptions.TaskStore when configuring the MCP server.");
});
return new DefaultMcpServerBuilder(services);
}
}

View file

@ -7,6 +7,8 @@
<PackageId>ModelContextProtocol</PackageId>
<Description>.NET SDK for the Model Context Protocol (MCP) with hosting and dependency injection extensions.</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!-- Suppress the experimental tasks warning -->
<NoWarn>$(NoWarn);MCPEXP001</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">