Skip to content
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
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
20 changes: 20 additions & 0 deletions src/ModelContextProtocol.Core/Client/McpClientTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ internal McpClientTool(
AIFunctionArguments arguments, CancellationToken cancellationToken)
{
CallToolResult result = await CallAsync(arguments, _progress, JsonSerializerOptions, cancellationToken).ConfigureAwait(false);

// We want to translate the result content into AIContent, using AIContent as the exchange types, so
// that downstream IChatClients can specialize handling based on the content (e.g. sending image content
// back to the AI service as a multi-modal tool response). However, when there is additional information
// carried by the CallToolResult outside of its ContentBlocks, just returning AIContent from those ContentBlocks
// would lose that information. So, we only do the translation if there is no additional information to preserve.
if (result.IsError is not true &&
result.StructuredContent is null &&
result.Meta is not { Count: > 0 })
{
switch (result.Content.Count)
{
case 1 when result.Content[0].ToAIContent() is { } aiContent:
return aiContent;

case > 1 when result.Content.Select(c => c.ToAIContent()).ToArray() is { } aiContents && aiContents.All(static c => c is not null):
return aiContents;
}
}

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

Expand Down
Loading
Loading