Skip to content

Commit 1b6872b

Browse files
committed
Tweak how McpClientTool.InvokeAsync exposes some content
Enhanced `InvokeCoreAsync` in `McpClientTool.cs` to handle non-text content by converting it to `AIContent` when possible. This enables richer content handling for downstream `IChatClients` while maintaining fallback serialization for unsupported cases.
1 parent 66c084c commit 1b6872b

File tree

3 files changed

+419
-2
lines changed

3 files changed

+419
-2
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
<System9Version>9.0.10</System9Version>
55
<System10Version>10.0.0-rc.2.25502.107</System10Version>
6-
<MicrosoftExtensionsAIVersion>9.10.1</MicrosoftExtensionsAIVersion>
6+
<MicrosoftExtensionsAIVersion>9.10.2</MicrosoftExtensionsAIVersion>
77
</PropertyGroup>
88

99
<!-- Product dependencies netstandard -->
@@ -60,7 +60,7 @@
6060
<PrivateAssets>all</PrivateAssets>
6161
</PackageVersion>
6262
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
63-
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.1-preview.1.25521.4" />
63+
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.2-preview.1.25552.1" />
6464
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(System9Version)" />
6565
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(System9Version)" />
6666
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(System9Version)" />

src/ModelContextProtocol.Core/Client/McpClientTool.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ internal McpClientTool(
9191
AIFunctionArguments arguments, CancellationToken cancellationToken)
9292
{
9393
CallToolResult result = await CallAsync(arguments, _progress, JsonSerializerOptions, cancellationToken).ConfigureAwait(false);
94+
95+
// If any non-text content is present, try to convert all of the contents to AIContent.
96+
// If we can, return those AIContent instances instead of serializing them.
97+
// This then permits richer handling of the content by downstream IChatClients.
98+
if (result.Content.Any(static c => c is not TextContentBlock))
99+
{
100+
var aiContents = result.Content.Select(c => c.ToAIContent()).ToArray();
101+
if (aiContents.All(static c => c is not null))
102+
{
103+
return aiContents;
104+
}
105+
}
106+
94107
return JsonSerializer.SerializeToElement(result, McpJsonUtilities.JsonContext.Default.CallToolResult);
95108
}
96109

0 commit comments

Comments
 (0)