Skip to content

Commit 4b43455

Browse files
Copilotjeffhandley
andauthored
Fix tests for McpTask double-wrapping: provide DI services at tool creation time
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/0b57604e-d75a-4879-a7ed-139c8e03ec6b Co-authored-by: jeffhandley <1031940+jeffhandley@users.noreply.github.com>
1 parent d53360d commit 4b43455

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/ModelContextProtocol.Tests/Server/ToolTaskSupportTests.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,11 @@ public async Task Tool_ReturningMcpTask_BypassesSdkTaskWrapping()
666666
// Arrange - Server with task store and a tool that creates and returns its own McpTask
667667
var taskStore = new InMemoryMcpTaskStore();
668668

669+
// Build a service provider so the tool can resolve IMcpTaskStore at creation time
670+
var toolServices = new ServiceCollection();
671+
toolServices.AddSingleton<IMcpTaskStore>(taskStore);
672+
var toolServiceProvider = toolServices.BuildServiceProvider();
673+
669674
await using var fixture = new ClientServerFixture(
670675
LoggerFactory,
671676
configureServer: builder =>
@@ -684,7 +689,8 @@ public async Task Tool_ReturningMcpTask_BypassesSdkTaskWrapping()
684689
{
685690
Name = "self-managing-tool",
686691
Description = "A tool that creates and returns its own McpTask",
687-
Execution = new ToolExecution { TaskSupport = ToolTaskSupport.Optional }
692+
Execution = new ToolExecution { TaskSupport = ToolTaskSupport.Optional },
693+
Services = toolServiceProvider
688694
})]);
689695
},
690696
configureServices: services =>
@@ -716,6 +722,11 @@ public async Task Tool_ReturningMcpTask_WithoutTaskMetadata_ReturnsTaskDirectly(
716722
// Arrange - Server with task store and a tool that returns McpTask
717723
var taskStore = new InMemoryMcpTaskStore();
718724

725+
// Build a service provider so the tool can resolve IMcpTaskStore at creation time
726+
var toolServices = new ServiceCollection();
727+
toolServices.AddSingleton<IMcpTaskStore>(taskStore);
728+
var toolServiceProvider = toolServices.BuildServiceProvider();
729+
719730
await using var fixture = new ClientServerFixture(
720731
LoggerFactory,
721732
configureServer: builder =>
@@ -733,7 +744,8 @@ public async Task Tool_ReturningMcpTask_WithoutTaskMetadata_ReturnsTaskDirectly(
733744
{
734745
Name = "self-managing-tool",
735746
Description = "A tool that creates and returns its own McpTask",
736-
Execution = new ToolExecution { TaskSupport = ToolTaskSupport.Optional }
747+
Execution = new ToolExecution { TaskSupport = ToolTaskSupport.Optional },
748+
Services = toolServiceProvider
737749
})]);
738750
},
739751
configureServices: services =>

0 commit comments

Comments
 (0)