Fix McpAIFunction to override Name/Description (#35)

This commit is contained in:
Stephen Toub 2025-03-07 13:48:42 -05:00 • committed by GitHub
commit e5c26d6285
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,10 @@ public class McpAIFunction : AIFunction
}
/// <inheritdoc/>
public override string ToString() => _tool.Name;
public override string Name => _tool.Name;
/// <inheritdoc/>
public override string Description => _tool.Description ?? string.Empty;
/// <inheritdoc/>
public override JsonElement JsonSchema => AIFunctionUtilities.MapToJsonElement(_tool);
@ -42,14 +45,9 @@ public class McpAIFunction : AIFunction
}
// Call the tool through mcpdotnet
var result = await _client.CallToolAsync(
_tool.Name,
argDict.Count == 0 ? [] : argDict,
cancellationToken: cancellationToken
);
var result = await _client.CallToolAsync(_tool.Name, argDict, cancellationToken);
// Extract the text content from the result
// For simplicity in this sample, we'll just concatenate all text content
// Extract the text content from the result.
return string.Join("\n", result.Content
.Where(c => c.Type == "text")
.Select(c => c.Text));