diff --git a/Directory.Packages.props b/Directory.Packages.props index 91fe2944..1a8a7353 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -19,8 +19,7 @@ - - + @@ -110,8 +109,7 @@ - - + diff --git a/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs b/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs index 8a409f67..a3121f91 100644 --- a/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs +++ b/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs @@ -1,4 +1,5 @@ using BotSharp.Abstraction.Functions.Models; +using ModelContextProtocol.Client; using ModelContextProtocol.Protocol.Types; using System; using System.Collections.Generic; @@ -8,15 +9,15 @@ namespace BotSharp.Core.MCP; internal static class AIFunctionUtilities { - public static FunctionDef MapToFunctionDef(Tool tool) + public static FunctionDef MapToFunctionDef(McpClientTool tool) { if (tool == null) { throw new ArgumentNullException(nameof(tool)); } - var properties = tool.InputSchema.GetProperty("properties"); - var required = tool.InputSchema.GetProperty("required"); + var properties = tool.JsonSchema.GetProperty("properties"); + var required = tool.JsonSchema.GetProperty("required"); FunctionDef funDef = new FunctionDef { diff --git a/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj b/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj index 94aba37c..5f513dd9 100644 --- a/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj +++ b/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj @@ -10,7 +10,6 @@ - diff --git a/src/Infrastructure/BotSharp.MCP/Functions/McpToolAdapter.cs b/src/Infrastructure/BotSharp.MCP/Functions/McpToolAdapter.cs index 60cfb531..56150aa5 100644 --- a/src/Infrastructure/BotSharp.MCP/Functions/McpToolAdapter.cs +++ b/src/Infrastructure/BotSharp.MCP/Functions/McpToolAdapter.cs @@ -15,11 +15,11 @@ namespace BotSharp.Core.Mcp.Functions; public class McpToolAdapter : IFunctionCallback { - private readonly Tool _tool; + private readonly McpClientTool _tool; private readonly MCPClientManager _clientManager; private readonly IServiceProvider _serviceProvider; - public McpToolAdapter(IServiceProvider provider, Tool tool, MCPClientManager client) + public McpToolAdapter(IServiceProvider provider, McpClientTool tool, MCPClientManager client) { _serviceProvider = provider ?? throw new ArgumentNullException(nameof(provider)); _tool = tool ?? throw new ArgumentNullException(nameof(tool)); diff --git a/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs b/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs index 84039cfb..8b866f49 100644 --- a/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs +++ b/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs @@ -55,9 +55,9 @@ public class MCPToolAgentHook : AgentHookBase var mcpClient = await mcpClientManager.GetMcpClientAsync(item.ServerId); if (mcpClient != null) { - var tools = await mcpClient.ListToolsAsync().ToListAsync(); + var tools = await mcpClient.ListToolsAsync(); var toolnames = item.Functions.Select(x => x.Name).ToList(); - foreach (var tool in tools.Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))) + foreach (var tool in tools.ToList().Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))) { var funDef = AIFunctionUtilities.MapToFunctionDef(tool); functionDefs.Add(funDef); diff --git a/src/Infrastructure/BotSharp.MCP/McpPlugin.cs b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs index f95965ac..f84e7531 100644 --- a/src/Infrastructure/BotSharp.MCP/McpPlugin.cs +++ b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs @@ -45,7 +45,7 @@ public class McpPlugin : IBotSharpPlugin private async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server) { var client = await clientManager.GetMcpClientAsync(server.Id); - var tools = await client.ListToolsAsync().ToListAsync(); + var tools = await client.ListToolsAsync(); foreach (var tool in tools) { diff --git a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs index 6e49658d..58170dfa 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/Controllers/AgentController.cs @@ -175,10 +175,10 @@ public class AgentController : ControllerBase } [HttpGet("/agent/mcp/tools")] - public async Task> GetMCPTools(string serverId) + public async Task> GetMCPTools(string serverId) { var client = await _clientManager.GetMcpClientAsync(serverId); - var tools = await client.ListToolsAsync().ToListAsync(); + var tools = await client.ListToolsAsync(); return tools.Where(x => !string.IsNullOrWhiteSpace(x.Name)) .OrderBy(x => x.Name).ToList();