Extract Tasks into the ModelContextProtocol.Extensions.Tasks extension package (#1693)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
This commit is contained in:
parent
ffc557f920
commit
2ca96f548b
1 changed files with 2559 additions and 1895 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using ModelContextProtocol.Extensions.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModelContextProtocol.Client;
|
||||
using ModelContextProtocol.Protocol;
|
||||
|
|
@ -10,7 +11,7 @@ namespace ModelContextProtocol.Tests.Server;
|
|||
|
||||
/// <summary>
|
||||
/// Pins the behavior when a client signals the SEP-2575 tasks opt-in via <c>_meta</c> but the server
|
||||
/// has neither an <see cref="McpServerOptions.TaskStore"/> nor a <see cref="McpServerHandlers.CallToolWithTaskHandler"/>
|
||||
/// has neither <see cref="McpTasksBuilderExtensions.WithTasks(IMcpServerBuilder, IMcpTaskStore)"/> nor a <see cref="McpServerHandlers.CallToolWithAlternateHandler"/>
|
||||
/// configured. The expected behavior is a silent synchronous fallback: the server returns the normal
|
||||
/// <see cref="CallToolResult"/> with no <c>Task</c> envelope and no exception.
|
||||
/// </summary>
|
||||
|
|
@ -25,7 +26,7 @@ public class McpServerTasksNoStoreTests : ClientServerTestBase
|
|||
|
||||
protected override void ConfigureServices(ServiceCollection services, IMcpServerBuilder mcpServerBuilder)
|
||||
{
|
||||
// Intentionally do NOT configure TaskStore or CallToolWithTaskHandler.
|
||||
// Intentionally do NOT configure TaskStore or CallToolWithAlternateHandler.
|
||||
mcpServerBuilder.WithTools<NoStoreTools>();
|
||||
}
|
||||
|
||||
|
|
@ -35,8 +36,8 @@ public class McpServerTasksNoStoreTests : ClientServerTestBase
|
|||
await using var client = await CreateMcpClientForServer();
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
|
||||
// CallToolRawAsync always writes the SEP-2575 tasks opt-in into _meta.
|
||||
var augmented = await client.CallToolRawAsync(
|
||||
// CallToolAsTaskAsync always writes the SEP-2575 tasks opt-in into _meta.
|
||||
var augmented = await client.CallToolAsTaskAsync(
|
||||
new CallToolRequestParams { Name = "sync-tool" }, ct);
|
||||
|
||||
// With no task store configured, the server must complete synchronously and return
|
||||
|
|
@ -54,8 +55,8 @@ public class McpServerTasksNoStoreTests : ClientServerTestBase
|
|||
await using var client = await CreateMcpClientForServer();
|
||||
var ct = TestContext.Current.CancellationToken;
|
||||
|
||||
var result = await client.CallToolAsync(
|
||||
new CallToolRequestParams { Name = "sync-tool" }, ct);
|
||||
var result = await client.CallToolWithPollingAsync(
|
||||
new CallToolRequestParams { Name = "sync-tool" }, cancellationToken: ct);
|
||||
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal("sync result", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
|
||||
|
|
|
|||
Loading…
Reference in a new issue