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

38 lines
1.1 KiB
C#
Raw Normal View History

using BotSharp.Abstraction.Functions.Models;
2025-03-29 02:05:52 +00:00
using ModelContextProtocol.Client;
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
{
2025-03-29 02:05:52 +00:00
public static FunctionDef MapToFunctionDef(McpClientTool tool)
2025-02-23 14:55:35 +00:00
{
if (tool == null)
{
throw new ArgumentNullException(nameof(tool));
}
2025-03-29 02:05:52 +00:00
var properties = tool.JsonSchema.GetProperty("properties");
var required = tool.JsonSchema.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;
}
}