BotSharp/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs

37 lines
1 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Functions.Models;
using ModelContextProtocol.Protocol.Types;
2025-02-23 14:55:35 +00:00
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace BotSharp.Core.MCP;
internal static class AIFunctionUtilities
{
public static FunctionDef MapToFunctionDef(Tool tool)
{
if (tool == null)
{
throw new ArgumentNullException(nameof(tool));
}
var properties = tool.InputSchema.GetProperty("properties");
var required = tool.InputSchema.GetProperty("required");
2025-02-23 14:55:35 +00:00
FunctionDef funDef = new FunctionDef
{
Name = tool.Name,
Description = tool.Description ?? string.Empty,
2025-02-23 14:55:35 +00:00
Type = "function",
Parameters = new FunctionParametersDef
{
Type = "object",
Properties = JsonDocument.Parse(properties.GetRawText()),
Required = JsonSerializer.Deserialize<List<string>>(required.GetRawText())
2025-02-23 14:55:35 +00:00
}
};
return funDef;
}
}