-
-
Notifications
You must be signed in to change notification settings - Fork 634
Expand file tree
/
Copy pathAiFunctionHelper.cs
More file actions
33 lines (28 loc) · 939 Bytes
/
AiFunctionHelper.cs
File metadata and controls
33 lines (28 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Text.Json;
using ModelContextProtocol.Client;
namespace BotSharp.Core.MCP.Helpers;
internal static class AiFunctionHelper
{
public static FunctionDef MapToFunctionDef(McpClientTool tool)
{
if (tool == null)
{
throw new ArgumentNullException(nameof(tool));
}
var properties = tool.JsonSchema.GetProperty("properties");
var required = tool.JsonSchema.GetProperty("required");
var funDef = new FunctionDef
{
Name = tool.Name,
Description = tool.Description ?? string.Empty,
Type = "function",
Parameters = new FunctionParametersDef
{
Type = "object",
Properties = JsonDocument.Parse(properties.GetRawText()),
Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
}
};
return funDef;
}
}