Reorganize folders, samples, minor bug fix (#14)
Reorganize folders Samples Casing fixes
This commit is contained in:
parent
e51c78e5e4
commit
3e35efe79c
1 changed files with 501 additions and 20 deletions
32
samples/anthropic/tools/ToolsConsole/McpToolExtensions.cs
Normal file
32
samples/anthropic/tools/ToolsConsole/McpToolExtensions.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
using Anthropic.SDK.Common;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
public static class McpToolExtensions
|
||||
{
|
||||
public static IList<Anthropic.SDK.Common.Tool> ToAnthropicTools(this IEnumerable<McpDotNet.Protocol.Types.Tool> tools)
|
||||
{
|
||||
List<Anthropic.SDK.Common.Tool> result = new();
|
||||
foreach (var tool in tools)
|
||||
{
|
||||
var function = tool.InputSchema == null
|
||||
? new Function(tool.Name, tool.Description)
|
||||
: new Function(tool.Name, tool.Description, JsonSerializer.Serialize(tool.InputSchema));
|
||||
result.Add(function);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Dictionary<string, object>? ToMCPArguments(this JsonNode jsonNode)
|
||||
{
|
||||
if (jsonNode == null)
|
||||
return null;
|
||||
|
||||
// Convert JsonNode to Dictionary<string, object>
|
||||
return jsonNode.AsObject()
|
||||
.ToDictionary(
|
||||
prop => prop.Key,
|
||||
prop => JsonSerializer.Deserialize<object>(prop.Value)!
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue