Remove special-casing of string enumerables in McpServerTool (#699)
We special-case string enumerables, translating them to an array of text content blocks, but other enumerables just get serialized, and there's a reasonable expectation that returning a string[] would produce a JSON array of strings. Just delete the special-casing.
This commit is contained in:
parent
329f848db6
commit
70960e1f1b
3 changed files with 3 additions and 11 deletions
|
|
@ -270,12 +270,6 @@ internal sealed partial class AIFunctionMcpServerTool : McpServerTool
|
||||||
StructuredContent = structuredContent,
|
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<AIContent> contentItems => ConvertAIContentEnumerableToCallToolResult(contentItems, structuredContent),
|
||||||
|
|
||||||
IEnumerable<ContentBlock> contents => new()
|
IEnumerable<ContentBlock> contents => new()
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,7 @@ public partial class McpServerBuilderExtensionsToolsTests : ClientServerTestBase
|
||||||
|
|
||||||
Assert.NotNull(result.Content);
|
Assert.NotNull(result.Content);
|
||||||
Assert.NotEmpty(result.Content);
|
Assert.NotEmpty(result.Content);
|
||||||
Assert.Equal("hello Peter", (result.Content[0] as TextContentBlock)?.Text);
|
Assert.Equal("""["hello Peter","hello2 Peter"]""", (result.Content[0] as TextContentBlock)?.Text);
|
||||||
Assert.Equal("hello2 Peter", (result.Content[1] as TextContentBlock)?.Text);
|
|
||||||
|
|
||||||
result = await client.CallToolAsync(
|
result = await client.CallToolAsync(
|
||||||
"SecondCustomTool",
|
"SecondCustomTool",
|
||||||
|
|
|
||||||
|
|
@ -356,9 +356,8 @@ public partial class McpServerToolTests
|
||||||
var result = await tool.InvokeAsync(
|
var result = await tool.InvokeAsync(
|
||||||
new RequestContext<CallToolRequestParams>(mockServer.Object),
|
new RequestContext<CallToolRequestParams>(mockServer.Object),
|
||||||
TestContext.Current.CancellationToken);
|
TestContext.Current.CancellationToken);
|
||||||
Assert.Equal(2, result.Content.Count);
|
Assert.Single(result.Content);
|
||||||
Assert.Equal("42", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
|
Assert.Equal("""["42","43"]""", Assert.IsType<TextContentBlock>(result.Content[0]).Text);
|
||||||
Assert.Equal("43", Assert.IsType<TextContentBlock>(result.Content[1]).Text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue