Skip to content

Remove special-casing of string enumerables in McpServerTool #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,6 @@ public override async ValueTask<CallToolResult> InvokeAsync(
StructuredContent = structuredContent,
},

IEnumerable<string> texts => new()
{
Content = [.. texts.Select(x => new TextContentBlock { Text = x ?? string.Empty })],
StructuredContent = structuredContent,
},

IEnumerable<AIContent> contentItems => ConvertAIContentEnumerableToCallToolResult(contentItems, structuredContent),

IEnumerable<ContentBlock> contents => new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,7 @@ public async Task Can_Call_Registered_Tool_With_Array_Result()

Assert.NotNull(result.Content);
Assert.NotEmpty(result.Content);
Assert.Equal("hello Peter", (result.Content[0] as TextContentBlock)?.Text);
Assert.Equal("hello2 Peter", (result.Content[1] as TextContentBlock)?.Text);
Assert.Equal("""["hello Peter","hello2 Peter"]""", (result.Content[0] as TextContentBlock)?.Text);

result = await client.CallToolAsync(
"SecondCustomTool",
Expand Down
5 changes: 2 additions & 3 deletions tests/ModelContextProtocol.Tests/Server/McpServerToolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,9 +356,8 @@ public async Task CanReturnCollectionOfStrings()
var result = await tool.InvokeAsync(
new RequestContext<CallToolRequestParams>(mockServer.Object),
TestContext.Current.CancellationToken);
Assert.Equal(2, result.Content.Count);
Assert.Equal("42", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
Assert.Equal("43", Assert.IsType<TextContentBlock>(result.Content[1]).Text);
Assert.Single(result.Content);
Assert.Equal("""["42","43"]""", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
}

[Fact]
Expand Down
Loading