From adfb8f4fc40f693c4530381363d68db5fc2fadf7 Mon Sep 17 00:00:00 2001 From: Jicheng Lu <103353@smsassist.com> Date: Mon, 31 Mar 2025 20:59:19 -0500 Subject: [PATCH] fix startup and use camel case --- .../Agents/AgentHookBase.cs | 2 +- .../BotSharp.Abstraction/Agents/IAgentHook.cs | 2 +- .../Agents/Models/Agent.cs | 4 +- .../Agents/Models/MCPTool.cs | 14 +++---- .../Plugins/PluginLoaderSettings.cs | 2 + .../BotSharpMCPExtensions.cs | 16 ++++---- .../Functions/McpToolAdapter.cs | 5 ++- .../AiFunctionHelper.cs} | 5 +-- .../Hooks/MCPToolAgentHook.cs | 18 +++++---- .../BotSharp.Core.MCP/MCPClientManager.cs | 26 ------------- .../Managers/McpClientManager.cs | 27 +++++++++++++ .../BotSharp.Core.MCP/Settings/MCPSettings.cs | 2 +- .../Agents/Services/AgentService.LoadAgent.cs | 2 +- .../Services/AgentService.UpdateAgent.cs | 2 +- .../BotSharp.Core/BotSharpCoreExtensions.cs | 7 +++- .../FileRepository/FileRepository.Agent.cs | 2 +- .../Agents/Request/AgentCreationModel.cs | 2 +- .../Agents/Request/AgentUpdateModel.cs | 2 +- .../ViewModels/Agents/View/AgentViewModel.cs | 4 +- .../Collections/AgentDocument.cs | 2 +- .../Models/AgentMCPToolMongoElement.cs | 12 +++--- .../Repository/MongoRepository.Agent.cs | 10 ++--- src/WebStarter/appsettings.json | 39 +++++++++++-------- 23 files changed, 112 insertions(+), 95 deletions(-) rename src/Infrastructure/BotSharp.Core.MCP/{AIFunctionUtilities.cs => Helpers/AiFunctionHelper.cs} (91%) delete mode 100644 src/Infrastructure/BotSharp.Core.MCP/MCPClientManager.cs create mode 100644 src/Infrastructure/BotSharp.Core.MCP/Managers/McpClientManager.cs diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index 1103f2f5..5c8ad126 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs @@ -60,7 +60,7 @@ public abstract class AgentHookBase : IAgentHook } - public virtual void OnAgentMCPToolLoaded(Agent agent) + public virtual void OnAgentMcpToolLoaded(Agent agent) { } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs index 624616d7..c37688ed 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/IAgentHook.cs @@ -27,7 +27,7 @@ public interface IAgentHook void OnAgentUtilityLoaded(Agent agent); - void OnAgentMCPToolLoaded(Agent agent); + void OnAgentMcpToolLoaded(Agent agent); /// /// Triggered when agent is loaded completely. diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs index fc28e571..a880a0c6 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -107,7 +107,7 @@ public class Agent /// /// Agent MCP Tools /// - public List McpTools { get; set; } = new(); + public List McpTools { get; set; } = new(); /// /// Agent rules @@ -305,7 +305,7 @@ public class Agent return this; } - public Agent SetMcps(List mcps) + public Agent SetMcpTools(List? mcps) { McpTools = mcps ?? []; return this; diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs index 4ffd4915..88e2d4b0 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs @@ -1,22 +1,22 @@ namespace BotSharp.Abstraction.Agents.Models; -public class MCPTool +public class McpTool { public string Name { get; set; } public string ServerId { get; set; } public bool Disabled { get; set; } - public IEnumerable Functions { get; set; } = []; + public IEnumerable Functions { get; set; } = []; - public MCPTool() + public McpTool() { } - public MCPTool( + public McpTool( string name, string serverId, bool disabled = false, - IEnumerable? functions = null) + IEnumerable? functions = null) { Name = name; ServerId = serverId; @@ -31,11 +31,11 @@ public class MCPTool } -public class MCPFunction +public class McpFunction { public string Name { get; set; } - public MCPFunction(string name) + public McpFunction(string name) { Name = name; } diff --git a/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs index 70564846..1a08fc5b 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Plugins/PluginLoaderSettings.cs @@ -3,4 +3,6 @@ namespace BotSharp.Abstraction.Plugins; public class PluginSettings { public string[] Assemblies { get; set; } = new string[0]; + + public string[] ExcludedFunctions { get; set; } = new string[0]; } diff --git a/src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs b/src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs index bb3605c9..0f6c3a8f 100644 --- a/src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs +++ b/src/Infrastructure/BotSharp.Core.MCP/BotSharpMCPExtensions.cs @@ -4,10 +4,11 @@ using BotSharp.Core.MCP.Hooks; using Microsoft.Extensions.Configuration; using ModelContextProtocol.Configuration; using ModelContextProtocol.Client; +using BotSharp.Core.MCP.Managers; namespace BotSharp.Core.MCP; -public static class BotSharpMCPExtensions +public static class BotSharpMcpExtensions { /// /// Add mcp @@ -17,11 +18,11 @@ public static class BotSharpMCPExtensions /// public static IServiceCollection AddBotSharpMCP(this IServiceCollection services, IConfiguration config) { - var settings = config.GetSection("MCPSettings").Get(); - services.AddScoped(provider => { return settings; }); - if (settings != null) + var settings = config.GetSection("MCPSettings").Get(); + services.AddScoped(provider => { return settings; }); + if (settings != null && !settings.McpServerConfigs.IsNullOrEmpty()) { - var clientManager = new MCPClientManager(settings); + var clientManager = new McpClientManager(settings); services.AddSingleton(clientManager); foreach (var server in settings.McpServerConfigs) @@ -31,13 +32,14 @@ public static class BotSharpMCPExtensions .GetAwaiter() .GetResult(); } + // Register hooks - services.AddScoped(); + services.AddScoped(); } return services; } - private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server, MCPClientManager clientManager) + private static async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server, McpClientManager clientManager) { var client = await clientManager.GetMcpClientAsync(server.Id); var tools = await client.ListToolsAsync(); diff --git a/src/Infrastructure/BotSharp.Core.MCP/Functions/McpToolAdapter.cs b/src/Infrastructure/BotSharp.Core.MCP/Functions/McpToolAdapter.cs index 1a99838d..2d4fdc70 100644 --- a/src/Infrastructure/BotSharp.Core.MCP/Functions/McpToolAdapter.cs +++ b/src/Infrastructure/BotSharp.Core.MCP/Functions/McpToolAdapter.cs @@ -1,4 +1,5 @@ using System.Text.Json; +using BotSharp.Core.MCP.Managers; using ModelContextProtocol.Client; namespace BotSharp.Core.MCP.Functions; @@ -6,10 +7,10 @@ namespace BotSharp.Core.MCP.Functions; public class McpToolAdapter : IFunctionCallback { private readonly McpClientTool _tool; - private readonly MCPClientManager _clientManager; + private readonly McpClientManager _clientManager; private readonly IServiceProvider _services; - public McpToolAdapter(IServiceProvider services, McpClientTool tool, MCPClientManager client) + public McpToolAdapter(IServiceProvider services, McpClientTool tool, McpClientManager client) { _services = services ?? throw new ArgumentNullException(nameof(services)); _tool = tool ?? throw new ArgumentNullException(nameof(tool)); diff --git a/src/Infrastructure/BotSharp.Core.MCP/AIFunctionUtilities.cs b/src/Infrastructure/BotSharp.Core.MCP/Helpers/AiFunctionHelper.cs similarity index 91% rename from src/Infrastructure/BotSharp.Core.MCP/AIFunctionUtilities.cs rename to src/Infrastructure/BotSharp.Core.MCP/Helpers/AiFunctionHelper.cs index a0da03ff..d6f1cb5b 100644 --- a/src/Infrastructure/BotSharp.Core.MCP/AIFunctionUtilities.cs +++ b/src/Infrastructure/BotSharp.Core.MCP/Helpers/AiFunctionHelper.cs @@ -1,10 +1,9 @@ using System.Text.Json; - using ModelContextProtocol.Client; -namespace BotSharp.Core.MCP; +namespace BotSharp.Core.MCP.Helpers; -internal static class AIFunctionUtilities +internal static class AiFunctionHelper { public static FunctionDef MapToFunctionDef(McpClientTool tool) { diff --git a/src/Infrastructure/BotSharp.Core.MCP/Hooks/MCPToolAgentHook.cs b/src/Infrastructure/BotSharp.Core.MCP/Hooks/MCPToolAgentHook.cs index 6b0a060a..40a59e2b 100644 --- a/src/Infrastructure/BotSharp.Core.MCP/Hooks/MCPToolAgentHook.cs +++ b/src/Infrastructure/BotSharp.Core.MCP/Hooks/MCPToolAgentHook.cs @@ -1,17 +1,19 @@ +using BotSharp.Core.MCP.Helpers; +using BotSharp.Core.MCP.Managers; using ModelContextProtocol.Client; namespace BotSharp.Core.MCP.Hooks; -public class MCPToolAgentHook : AgentHookBase +public class McpToolAgentHook : AgentHookBase { public override string SelfId => string.Empty; - public MCPToolAgentHook(IServiceProvider services, AgentSettings settings) + public McpToolAgentHook(IServiceProvider services, AgentSettings settings) : base(services, settings) { } - public override void OnAgentMCPToolLoaded(Agent agent) + public override void OnAgentMcpToolLoaded(Agent agent) { if (agent.Type == AgentType.Routing) { @@ -24,7 +26,7 @@ public class MCPToolAgentHook : AgentHookBase agent.SecondaryFunctions ??= []; - var functions = GetMCPContent(agent).Result; + var functions = GetMcpContent(agent).Result; foreach (var fn in functions) { if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase))) @@ -34,11 +36,11 @@ public class MCPToolAgentHook : AgentHookBase } } - private async Task> GetMCPContent(Agent agent) + private async Task> GetMcpContent(Agent agent) { var functionDefs = new List(); - var mcpClientManager = _services.GetRequiredService(); - var mcps = agent.McpTools; + var mcpClientManager = _services.GetRequiredService(); + var mcps = agent.McpTools.Where(x => !x.Disabled); foreach (var item in mcps) { var mcpClient = await mcpClientManager.GetMcpClientAsync(item.ServerId); @@ -48,7 +50,7 @@ public class MCPToolAgentHook : AgentHookBase var toolnames = item.Functions.Select(x => x.Name).ToList(); foreach (var tool in tools.Where(x => toolnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))) { - var funDef = AIFunctionUtilities.MapToFunctionDef(tool); + var funDef = AiFunctionHelper.MapToFunctionDef(tool); functionDefs.Add(funDef); } } diff --git a/src/Infrastructure/BotSharp.Core.MCP/MCPClientManager.cs b/src/Infrastructure/BotSharp.Core.MCP/MCPClientManager.cs deleted file mode 100644 index d511edae..00000000 --- a/src/Infrastructure/BotSharp.Core.MCP/MCPClientManager.cs +++ /dev/null @@ -1,26 +0,0 @@ -using BotSharp.Core.MCP.Settings; -using ModelContextProtocol.Client; - -namespace BotSharp.Core.MCP; - -public class MCPClientManager : IDisposable -{ - - private readonly MCPSettings mcpSettings; - - public MCPClientManager(MCPSettings settings) - { - mcpSettings = settings; - } - - public async Task GetMcpClientAsync(string serverId) - { - return await McpClientFactory.CreateAsync(mcpSettings.McpServerConfigs - .Where(x=> x.Name == serverId).First(), mcpSettings.McpClientOptions); - } - - public void Dispose() - { - - } -} diff --git a/src/Infrastructure/BotSharp.Core.MCP/Managers/McpClientManager.cs b/src/Infrastructure/BotSharp.Core.MCP/Managers/McpClientManager.cs new file mode 100644 index 00000000..523e4b00 --- /dev/null +++ b/src/Infrastructure/BotSharp.Core.MCP/Managers/McpClientManager.cs @@ -0,0 +1,27 @@ +using BotSharp.Core.MCP.Settings; +using ModelContextProtocol.Client; + +namespace BotSharp.Core.MCP.Managers; + +public class McpClientManager : IDisposable +{ + + private readonly McpSettings mcpSettings; + + public McpClientManager(McpSettings settings) + { + mcpSettings = settings; + } + + public async Task GetMcpClientAsync(string serverId) + { + return await McpClientFactory.CreateAsync( + mcpSettings.McpServerConfigs.Where(x=> x.Name == serverId).First(), + mcpSettings.McpClientOptions); + } + + public void Dispose() + { + + } +} diff --git a/src/Infrastructure/BotSharp.Core.MCP/Settings/MCPSettings.cs b/src/Infrastructure/BotSharp.Core.MCP/Settings/MCPSettings.cs index fd2cc961..09884f2b 100644 --- a/src/Infrastructure/BotSharp.Core.MCP/Settings/MCPSettings.cs +++ b/src/Infrastructure/BotSharp.Core.MCP/Settings/MCPSettings.cs @@ -3,7 +3,7 @@ using ModelContextProtocol.Configuration; namespace BotSharp.Core.MCP.Settings; -public class MCPSettings +public class McpSettings { public McpClientOptions McpClientOptions { get; set; } public List McpServerConfigs { get; set; } = new(); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index a62f4970..d3ceea8b 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -74,7 +74,7 @@ public partial class AgentService if(!agent.McpTools.IsNullOrEmpty()) { - hook.OnAgentMCPToolLoaded(agent); + hook.OnAgentMcpToolLoaded(agent); } hook.OnAgentLoaded(agent); diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs index dd8743d4..387cdfd5 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -107,7 +107,7 @@ public partial class AgentService .SetResponses(foundAgent.Responses) .SetSamples(foundAgent.Samples) .SetUtilities(foundAgent.Utilities) - .SetMcps(foundAgent.McpTools) + .SetMcpTools(foundAgent.McpTools) .SetKnowledgeBases(foundAgent.KnowledgeBases) .SetRules(foundAgent.Rules) .SetLlmConfig(foundAgent.LlmConfig); diff --git a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs index 6b10ad81..cd85e358 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs +++ b/src/Infrastructure/BotSharp.Core/BotSharpCoreExtensions.cs @@ -135,6 +135,8 @@ public static class BotSharpCoreExtensions { var pluginSettings = new PluginSettings(); config.Bind("PluginLoader", pluginSettings); + var excludedFunctions = pluginSettings.ExcludedFunctions ?? []; + services.AddScoped(provider => { var settingService = provider.GetRequiredService(); @@ -161,8 +163,9 @@ public static class BotSharpCoreExtensions // Register function callback var functions = assembly.GetTypes() - .Where(x => x.IsClass) - .Where(x => x.GetInterface(nameof(IFunctionCallback)) != null) + .Where(x => x.IsClass + && x.GetInterface(nameof(IFunctionCallback)) != null + && !excludedFunctions.Contains(x.Name)) .ToArray(); foreach (var function in functions) diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 4da61828..5ccc7088 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -194,7 +194,7 @@ namespace BotSharp.Core.Repository File.WriteAllText(agentFile, json); } - private void UpdateAgentMcpTools(string agentId, List mcptools) + private void UpdateAgentMcpTools(string agentId, List mcptools) { if (mcptools == null) return; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs index 81ec1bc7..8265ebe4 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentCreationModel.cs @@ -55,7 +55,7 @@ public class AgentCreationModel public int? MaxMessageCount { get; set; } public List Utilities { get; set; } = new(); - public List McpTools { get; set; } = new(); + public List McpTools { get; set; } = new(); public List RoutingRules { get; set; } = new(); public List KnowledgeBases { get; set; } = new(); public List Rules { get; set; } = new(); diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs index 9f2925e5..5dad68b2 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/Request/AgentUpdateModel.cs @@ -42,7 +42,7 @@ public class AgentUpdateModel /// /// McpTools /// - public List? McpTools { get; set; } + public List? McpTools { get; set; } /// /// knowledge bases diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs index a7091054..8a9a790c 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/View/AgentViewModel.cs @@ -24,7 +24,9 @@ public class AgentViewModel [JsonPropertyName("merge_utility")] public bool MergeUtility { get; set; } public List Utilities { get; set; } - public List McpTools { get; set; } + + [JsonPropertyName("mcp_tools")] + public List McpTools { get; set; } [JsonPropertyName("knowledge_bases")] public List KnowledgeBases { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index a0d99e0d..ae628456 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs @@ -18,7 +18,7 @@ public class AgentDocument : MongoBase public List Responses { get; set; } public List Samples { get; set; } public List Utilities { get; set; } - public List McpTools { get; set; } + public List McpTools { get; set; } public List KnowledgeBases { get; set; } public List Profiles { get; set; } public List Labels { get; set; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs index a14e2fad..99c39fce 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs @@ -3,16 +3,16 @@ using BotSharp.Abstraction.Agents.Models; namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] -public class AgentMCPToolMongoElement +public class AgentMcpToolMongoElement { public string Name { get; set; } public string ServerId { get; set; } public bool Disabled { get; set; } public List Functions { get; set; } = []; - public static AgentMCPToolMongoElement ToMongoElement(MCPTool tool) + public static AgentMcpToolMongoElement ToMongoElement(McpTool tool) { - return new AgentMCPToolMongoElement + return new AgentMcpToolMongoElement { Name = tool.Name, ServerId = tool.ServerId, @@ -21,14 +21,14 @@ public class AgentMCPToolMongoElement }; } - public static MCPTool ToDomainElement(AgentMCPToolMongoElement tool) + public static McpTool ToDomainElement(AgentMcpToolMongoElement tool) { - return new MCPTool + return new McpTool { Name = tool.Name, ServerId = tool.ServerId, Disabled = tool.Disabled, - Functions = tool.Functions?.Select(x => new MCPFunction(x.Name))?.ToList() ?? [], + Functions = tool.Functions?.Select(x => new McpFunction(x.Name))?.ToList() ?? [], }; } } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index ba4b3fde..75b2d470 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -264,11 +264,11 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } - private void UpdateAgentMcpTools(string agentId, List mcps) + private void UpdateAgentMcpTools(string agentId, List mcps) { if (mcps == null) return; - var elements = mcps?.Select(x => AgentMCPToolMongoElement.ToMongoElement(x))?.ToList() ?? []; + var elements = mcps?.Select(x => AgentMcpToolMongoElement.ToMongoElement(x))?.ToList() ?? []; var filter = Builders.Filter.Eq(x => x.Id, agentId); var update = Builders.Update @@ -346,7 +346,7 @@ public partial class MongoRepository .Set(x => x.Responses, agent.Responses.Select(r => AgentResponseMongoElement.ToMongoElement(r)).ToList()) .Set(x => x.Samples, agent.Samples) .Set(x => x.Utilities, agent.Utilities.Select(u => AgentUtilityMongoElement.ToMongoElement(u)).ToList()) - .Set(x => x.McpTools, agent.McpTools.Select(u => AgentMCPToolMongoElement.ToMongoElement(u)).ToList()) + .Set(x => x.McpTools, agent.McpTools.Select(u => AgentMcpToolMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.KnowledgeBases, agent.KnowledgeBases.Select(u => AgentKnowledgeBaseMongoElement.ToMongoElement(u)).ToList()) .Set(x => x.Rules, agent.Rules.Select(e => AgentRuleMongoElement.ToMongoElement(e)).ToList()) .Set(x => x.LlmConfig, AgentLlmConfigMongoElement.ToMongoElement(agent.LlmConfig)) @@ -527,7 +527,7 @@ public partial class MongoRepository Responses = x.Responses?.Select(r => AgentResponseMongoElement.ToMongoElement(r))?.ToList() ?? [], RoutingRules = x.RoutingRules?.Select(r => RoutingRuleMongoElement.ToMongoElement(r))?.ToList() ?? [], Utilities = x.Utilities?.Select(u => AgentUtilityMongoElement.ToMongoElement(u))?.ToList() ?? [], - McpTools = x.McpTools?.Select(u => AgentMCPToolMongoElement.ToMongoElement(u))?.ToList() ?? [], + McpTools = x.McpTools?.Select(u => AgentMcpToolMongoElement.ToMongoElement(u))?.ToList() ?? [], KnowledgeBases = x.KnowledgeBases?.Select(k => AgentKnowledgeBaseMongoElement.ToMongoElement(k))?.ToList() ?? [], Rules = x.Rules?.Select(e => AgentRuleMongoElement.ToMongoElement(e))?.ToList() ?? [], CreatedTime = x.CreatedDateTime, @@ -622,7 +622,7 @@ public partial class MongoRepository Responses = agentDoc.Responses?.Select(r => AgentResponseMongoElement.ToDomainElement(r))?.ToList() ?? [], RoutingRules = agentDoc.RoutingRules?.Select(r => RoutingRuleMongoElement.ToDomainElement(agentDoc.Id, agentDoc.Name, r))?.ToList() ?? [], Utilities = agentDoc.Utilities?.Select(u => AgentUtilityMongoElement.ToDomainElement(u))?.ToList() ?? [], - McpTools = agentDoc.McpTools?.Select(u => AgentMCPToolMongoElement.ToDomainElement(u))?.ToList() ?? [], + McpTools = agentDoc.McpTools?.Select(u => AgentMcpToolMongoElement.ToDomainElement(u))?.ToList() ?? [], KnowledgeBases = agentDoc.KnowledgeBases?.Select(x => AgentKnowledgeBaseMongoElement.ToDomainElement(x))?.ToList() ?? [], Rules = agentDoc.Rules?.Select(e => AgentRuleMongoElement.ToDomainElement(e))?.ToList() ?? [] }; diff --git a/src/WebStarter/appsettings.json b/src/WebStarter/appsettings.json index 6bab2cb3..60aca7d3 100644 --- a/src/WebStarter/appsettings.json +++ b/src/WebStarter/appsettings.json @@ -171,23 +171,25 @@ "Model": "gpt-4o-mini" } }, - //"MCPSettings": { - // "McpClientOptions": { - // "ClientInfo": { - // "Name": "SimpleToolsBotsharp", - // "Version": "1.0.0" - // } - // }, - // "McpServerConfigs": [ - // { - // "Id": "PizzaServer", - // "Name": "PizzaServer", - // "TransportType": "sse", - // "TransportOptions": [], - // "Location": "http://localhost:58905/sse" - // } - // ] - //}, + + "MCPSettings": { + "McpClientOptions": { + "ClientInfo": { + "Name": "SimpleToolsBotsharp", + "Version": "1.0.0" + } + }, + "McpServerConfigs": [ + { + "Id": "PizzaServer", + "Name": "PizzaServer", + "TransportType": "sse", + "TransportOptions": [], + "Location": "http://localhost:58905/sse" + } + ] + }, + "Conversation": { "DataDir": "conversations", "ShowVerboseLog": false, @@ -440,6 +442,9 @@ "BotSharp.Plugin.EmailHandler", "BotSharp.Plugin.AudioHandler", "BotSharp.Plugin.TencentCos" + ], + "ExcludedFunctions": [ + "McpToolAdapter" ] } }