Skip to content
Open
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
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<System9Version>9.0.10</System9Version>
<System10Version>10.0.0-rc.2.25502.107</System10Version>
<MicrosoftExtensionsAIVersion>9.10.1</MicrosoftExtensionsAIVersion>
<MicrosoftExtensionsAIVersion>9.10.2</MicrosoftExtensionsAIVersion>
</PropertyGroup>

<!-- Product dependencies netstandard -->
Expand Down Expand Up @@ -60,7 +60,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageVersion>
<PackageVersion Include="GitHubActionsTestLogger" Version="2.4.1" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.1-preview.1.25521.4" />
<PackageVersion Include="Microsoft.Extensions.AI.OpenAI" Version="9.10.2-preview.1.25552.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(System9Version)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="$(System9Version)" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="$(System9Version)" />
Expand Down
13 changes: 13 additions & 0 deletions src/ModelContextProtocol.Core/Client/McpClientTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,19 @@ internal McpClientTool(
AIFunctionArguments arguments, CancellationToken cancellationToken)
{
CallToolResult result = await CallAsync(arguments, _progress, JsonSerializerOptions, cancellationToken).ConfigureAwait(false);

// If any non-text content is present, try to convert all of the contents to AIContent.
// If we can, return those AIContent instances instead of serializing them.
// This then permits richer handling of the content by downstream IChatClients.
if (result.Content.Any(static c => c is not TextContentBlock))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if we omit the condition "if any non-text content is present"?

That is, we simpy convert the content's members to AIContent, and if any of them is null, then we fall back to serializing everything to Json element.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference. I did it this way to try to minimize the differences from today for the vastly most common case today (which is just text), but I'd be ok having it always do so.

{
var aiContents = result.Content.Select(c => c.ToAIContent()).ToArray();
if (aiContents.All(static c => c is not null))
{
return aiContents;
}
}

return JsonSerializer.SerializeToElement(result, McpJsonUtilities.JsonContext.Default.CallToolResult);
}

Expand Down
Loading