Add ToolAnnotations support (#124)
* Add ToolAnnotations support * Address feedback
This commit is contained in:
parent
2c1672cc1a
commit
62e92fa154
2 changed files with 645 additions and 394 deletions
|
|
@ -469,7 +469,7 @@ public static class McpClientExtensions
|
|||
{
|
||||
message.Contents.Add(new TextContent(sm.Content.Text));
|
||||
}
|
||||
else if (sm.Content is { Type: "image", MimeType: not null, Data: not null })
|
||||
else if (sm.Content is { Type: "image" or "audio", MimeType: not null, Data: not null })
|
||||
{
|
||||
message.Contents.Add(new DataContent(Convert.FromBase64String(sm.Content.Data), sm.Content.MimeType));
|
||||
}
|
||||
|
|
@ -512,11 +512,11 @@ public static class McpClientExtensions
|
|||
{
|
||||
foreach (var lmc in lastMessage.Contents)
|
||||
{
|
||||
if (lmc is DataContent dc && dc.HasTopLevelMediaType("image"))
|
||||
if (lmc is DataContent dc && (dc.HasTopLevelMediaType("image") || dc.HasTopLevelMediaType("audio")))
|
||||
{
|
||||
content = new()
|
||||
{
|
||||
Type = "image",
|
||||
Type = dc.HasTopLevelMediaType("image") ? "image" : "audio",
|
||||
MimeType = dc.MediaType,
|
||||
Data = dc.GetBase64Data(),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,22 +9,24 @@ namespace ModelContextProtocol.Client;
|
|||
public sealed class McpClientTool : AIFunction
|
||||
{
|
||||
private readonly IMcpClient _client;
|
||||
private readonly Tool _tool;
|
||||
|
||||
internal McpClientTool(IMcpClient client, Tool tool)
|
||||
{
|
||||
_client = client;
|
||||
_tool = tool;
|
||||
ProtocolTool = tool;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Name => _tool.Name;
|
||||
/// <summary>Gets the protocol <see cref="Tool"/> type for this instance.</summary>
|
||||
public Tool ProtocolTool { get; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override string Description => _tool.Description ?? string.Empty;
|
||||
public override string Name => ProtocolTool.Name;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override JsonElement JsonSchema => _tool.InputSchema;
|
||||
public override string Description => ProtocolTool.Description ?? string.Empty;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override JsonElement JsonSchema => ProtocolTool.InputSchema;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override JsonSerializerOptions JsonSerializerOptions => McpJsonUtilities.DefaultOptions;
|
||||
|
|
@ -37,7 +39,7 @@ public sealed class McpClientTool : AIFunction
|
|||
arguments as IReadOnlyDictionary<string, object?> ??
|
||||
arguments.ToDictionary();
|
||||
|
||||
CallToolResponse result = await _client.CallToolAsync(_tool.Name, argDict, cancellationToken).ConfigureAwait(false);
|
||||
CallToolResponse result = await _client.CallToolAsync(ProtocolTool.Name, argDict, cancellationToken).ConfigureAwait(false);
|
||||
return JsonSerializer.SerializeToElement(result, McpJsonUtilities.JsonContext.Default.CallToolResponse);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue