diff --git a/BotSharp.sln b/BotSharp.sln index d4890be1..d82f930c 100644 --- a/BotSharp.sln +++ b/BotSharp.sln @@ -127,6 +127,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -519,6 +521,14 @@ Global {AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|Any CPU.Build.0 = Release|Any CPU {AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.ActiveCfg = Release|Any CPU {AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = Release|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Debug|x64.ActiveCfg = Debug|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Debug|x64.Build.0 = Debug|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Release|Any CPU.Build.0 = Release|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Release|x64.ActiveCfg = Release|Any CPU + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5}.Release|x64.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -580,6 +590,7 @@ Global {F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749} {AFD64412-4D6A-452E-82A2-79E5D8842E29} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749} {AF329442-B48E-4B48-A18A-1C869D1BA6F5} = {D5293208-2BEF-42FC-A64C-5954F61720BA} + {8ED8EEF4-06DD-45F5-AA91-BD2395E901B5} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19} diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/AgentHookBase.cs index 295d3bc2..1103f2f5 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 OnAgentCPLoaded(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 59920408..624616d7 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 OnAgentCPLoaded(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 da57d33b..fc28e571 100644 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/Agent.cs @@ -95,18 +95,19 @@ public class Agent public List Labels { get; set; } = new(); /// - /// Merge mcps from entry agent + /// Merge Utility from entry agent /// public bool MergeUtility { get; set; } /// - /// Agent mcps + /// Agent Utility /// public List Utilities { get; set; } = new(); + /// - /// Agent MCP + /// Agent MCP Tools /// - public List Acps { get; set; } = new(); + public List McpTools { get; set; } = new(); /// /// Agent rules @@ -161,7 +162,7 @@ public class Agent Responses = agent.Responses, Samples = agent.Samples, Utilities = agent.Utilities, - Acps = agent.Acps, + McpTools = agent.McpTools, Knowledges = agent.Knowledges, IsPublic = agent.IsPublic, Disabled = agent.Disabled, @@ -304,9 +305,9 @@ public class Agent return this; } - public Agent SetMcps(List mcps) + public Agent SetMcps(List mcps) { - Acps = mcps ?? []; + McpTools = mcps ?? []; return this; } } diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs deleted file mode 100644 index 735e7dc8..00000000 --- a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/AgentCP.cs +++ /dev/null @@ -1,65 +0,0 @@ -namespace BotSharp.Abstraction.Agents.Models; - -public class AgentCP -{ - public string Name { get; set; } - - public string ServerId { get; set; } - - public bool Disabled { get; set; } - - public IEnumerable Functions { get; set; } = []; - public IEnumerable Templates { get; set; } = []; - - public AgentCP() - { - - } - - public AgentCP( - string name, - IEnumerable? functions = null, - IEnumerable? templates = null) - { - Name = name; - Functions = functions ?? []; - Templates = templates ?? []; - } - - public override string ToString() - { - return Name; - } -} - - -public class ACPFunction : MCPBase -{ - public ACPFunction() - { - - } - - public ACPFunction(string name) - { - Name = name; - } -} - -public class ACPTemplate : MCPBase -{ - public ACPTemplate() - { - - } - - public ACPTemplate(string name) - { - Name = name; - } -} - -public class MCPBase -{ - public string Name { get; set; } -} \ No newline at end of file diff --git a/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs new file mode 100644 index 00000000..fc8fbb62 --- /dev/null +++ b/src/Infrastructure/BotSharp.Abstraction/Agents/Models/MCPTool.cs @@ -0,0 +1,41 @@ +namespace BotSharp.Abstraction.Agents.Models; + +public class MCPTool +{ + public string Name { get; set; } + + public string ServerId { get; set; } + + public bool Disabled { get; set; } + + public IEnumerable Functions { get; set; } = []; + + public MCPTool() + { + + } + + public MCPTool( + string name, + IEnumerable? functions = null) + { + Name = name; + Functions = functions ?? []; + } + + public override string ToString() + { + return Name; + } +} + + +public class MCPFunction +{ + public string Name { get; set; } + + public MCPFunction() + { + + } +} diff --git a/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs b/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs index bcb15bd3..5ab0ea03 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Hooks/BasicAgentHook.cs @@ -1,6 +1,3 @@ -using BotSharp.Core.Mcp; -using BotSharp.Core.MCP; - namespace BotSharp.Core.Agents.Hooks; public class BasicAgentHook : AgentHookBase @@ -41,36 +38,7 @@ public class BasicAgentHook : AgentHookBase agent.SecondaryInstructions.Add(prompt); } } - - public override void OnAgentCPLoaded(Agent agent) - { - if (agent.Type == AgentType.Routing) - return; - - var conv = _services.GetRequiredService(); - var isConvMode = conv.IsConversationMode(); - if (!isConvMode) return; - - agent.SecondaryFunctions ??= []; - agent.SecondaryInstructions ??= []; - agent.Acps ??= []; - - var (functions, templates) = GetACPContent(agent); - - foreach (var fn in functions) - { - if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase))) - { - agent.SecondaryFunctions.Add(fn); - } - } - - foreach (var prompt in templates) - { - agent.SecondaryInstructions.Add(prompt); - } - } - + private (IEnumerable, IEnumerable) GetUtilityContent(Agent agent) { @@ -114,30 +82,5 @@ public class BasicAgentHook : AgentHookBase .Distinct().ToList(); return (functionNames, templateNames); - } - - private (IEnumerable, IEnumerable) GetACPContent(Agent agent) - { - List functionDefs = new List(); - IEnumerable templates = new List(); - var mcpClientManager = _services.GetRequiredService(); - var mcps = agent.Acps; - foreach (var item in mcps) - { - var ua = mcpClientManager.Factory.GetClientAsync(item.ServerId).Result; - if (ua != null) - { - var tools = ua.ListToolsAsync().Result; - var funcnames = item.Functions.Select(x => x.Name).ToList(); - foreach (var tool in tools.Tools.Where(x=> funcnames.Contains(x.Name,StringComparer.OrdinalIgnoreCase))) - { - var funDef = AIFunctionUtilities.MapToFunctionDef(tool); - functionDefs.Add(funDef); - } - } - } - - return (functionDefs, templates); - } - + } } diff --git a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs index 70722c6a..7fd94340 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.LoadAgent.cs @@ -72,9 +72,9 @@ public partial class AgentService hook.OnAgentUtilityLoaded(agent); } - if(agent.Acps != null) + if(agent.McpTools != null) { - hook.OnAgentCPLoaded(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 30a621c4..7e9da19c 100644 --- a/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs +++ b/src/Infrastructure/BotSharp.Core/Agents/Services/AgentService.UpdateAgent.cs @@ -40,7 +40,7 @@ public partial class AgentService record.Responses = agent.Responses ?? []; record.Samples = agent.Samples ?? []; record.Utilities = agent.Utilities ?? []; - record.Acps = agent.Acps ?? []; + record.McpTools = agent.McpTools ?? []; record.KnowledgeBases = agent.KnowledgeBases ?? []; record.Rules = agent.Rules ?? []; if (agent.LlmConfig != null && !agent.LlmConfig.IsInherit) @@ -107,7 +107,7 @@ public partial class AgentService .SetResponses(foundAgent.Responses) .SetSamples(foundAgent.Samples) .SetUtilities(foundAgent.Utilities) - .SetMcps(foundAgent.Acps) + .SetMcps(foundAgent.McpTools) .SetKnowledgeBases(foundAgent.KnowledgeBases) .SetRules(foundAgent.Rules) .SetLlmConfig(foundAgent.LlmConfig); diff --git a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj index 0d684675..37eee3ac 100644 --- a/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj +++ b/src/Infrastructure/BotSharp.Core/BotSharp.Core.csproj @@ -195,7 +195,6 @@ - diff --git a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs index 8b7b547a..ae401508 100644 --- a/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs +++ b/src/Infrastructure/BotSharp.Core/Repository/FileRepository/FileRepository.Agent.cs @@ -61,7 +61,7 @@ namespace BotSharp.Core.Repository UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); break; case AgentField.Acp: - UpdateAgentCP(agent.Id, agent.Acps); + UpdateAgentMcpTools(agent.Id, agent.McpTools); break; case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); @@ -194,15 +194,15 @@ namespace BotSharp.Core.Repository File.WriteAllText(agentFile, json); } - private void UpdateAgentCP(string agentId, List mcps) + private void UpdateAgentMcpTools(string agentId, List mcptools) { - if (mcps == null) return; + if (mcptools == null) return; var (agent, agentFile) = GetAgentFromFile(agentId); if (agent == null) return; - agent.Acps = mcps; + agent.McpTools = mcptools; agent.UpdatedDateTime = DateTime.UtcNow; var json = JsonSerializer.Serialize(agent, _options); File.WriteAllText(agentFile, json); @@ -377,7 +377,7 @@ namespace BotSharp.Core.Repository agent.Profiles = inputAgent.Profiles; agent.Labels = inputAgent.Labels; agent.Utilities = inputAgent.Utilities; - agent.Acps = inputAgent.Acps; + agent.McpTools = inputAgent.McpTools; agent.KnowledgeBases = inputAgent.KnowledgeBases; agent.RoutingRules = inputAgent.RoutingRules; agent.Rules = inputAgent.Rules; diff --git a/src/Infrastructure/BotSharp.Core/MCP/AIFunctionUtilities.cs b/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs similarity index 95% rename from src/Infrastructure/BotSharp.Core/MCP/AIFunctionUtilities.cs rename to src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs index 9c40eaa1..e86cbf92 100644 --- a/src/Infrastructure/BotSharp.Core/MCP/AIFunctionUtilities.cs +++ b/src/Infrastructure/BotSharp.MCP/AIFunctionUtilities.cs @@ -1,3 +1,4 @@ +using BotSharp.Abstraction.Functions.Models; using McpDotNet.Protocol.Types; using System; using System.Collections.Generic; diff --git a/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj b/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj new file mode 100644 index 00000000..c171a732 --- /dev/null +++ b/src/Infrastructure/BotSharp.MCP/BotSharp.MCP.csproj @@ -0,0 +1,18 @@ + + + + $(TargetFramework) + $(LangVersion) + $(BotSharpVersion) + $(GeneratePackageOnBuild) + $(SolutionDir)packages + + + + + + + + + + diff --git a/src/Infrastructure/BotSharp.Core/MCP/Functions/McpAIFunction.cs b/src/Infrastructure/BotSharp.MCP/Functions/McpToolFunction.cs similarity index 93% rename from src/Infrastructure/BotSharp.Core/MCP/Functions/McpAIFunction.cs rename to src/Infrastructure/BotSharp.MCP/Functions/McpToolFunction.cs index b7d36b2f..5df8fb07 100644 --- a/src/Infrastructure/BotSharp.Core/MCP/Functions/McpAIFunction.cs +++ b/src/Infrastructure/BotSharp.MCP/Functions/McpToolFunction.cs @@ -1,15 +1,21 @@ +using BotSharp.Abstraction.Conversations.Models; using BotSharp.Abstraction.Functions; using McpDotNet.Client; using McpDotNet.Protocol.Types; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text.Json; +using System.Threading.Tasks; namespace BotSharp.Core.Mcp.Functions; -public class McpAIFunction : IFunctionCallback +public class McpToolFunction : IFunctionCallback { private readonly Tool _tool; private readonly IMcpClient _client; - public McpAIFunction(Tool tool, IMcpClient client) + public McpToolFunction(Tool tool, IMcpClient client) { _tool = tool ?? throw new ArgumentNullException(nameof(tool)); _client = client ?? throw new ArgumentNullException(nameof(client)); diff --git a/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs b/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs new file mode 100644 index 00000000..a4ac94b7 --- /dev/null +++ b/src/Infrastructure/BotSharp.MCP/Hooks/MCPToolAgentHook.cs @@ -0,0 +1,71 @@ +using BotSharp.Abstraction.Agents; +using BotSharp.Abstraction.Agents.Enums; +using BotSharp.Abstraction.Agents.Models; +using BotSharp.Abstraction.Agents.Settings; +using BotSharp.Abstraction.Conversations; +using BotSharp.Abstraction.Functions.Models; +using BotSharp.Core.Mcp; +using BotSharp.Core.MCP; +using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace BotSharp.MCP.Hooks; + +public class MCPToolAgentHook : AgentHookBase +{ + public override string SelfId => string.Empty; + + public MCPToolAgentHook(IServiceProvider services, AgentSettings settings) + : base(services, settings) + { + } + + public override void OnAgentMCPToolLoaded(Agent agent) + { + if (agent.Type == AgentType.Routing) + return; + + var conv = _services.GetRequiredService(); + var isConvMode = conv.IsConversationMode(); + if (!isConvMode) return; + + agent.SecondaryFunctions ??= []; + agent.SecondaryInstructions ??= []; + agent.McpTools ??= []; + + var functions = GetMCPContent(agent); + + foreach (var fn in functions) + { + if (!agent.SecondaryFunctions.Any(x => x.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase))) + { + agent.SecondaryFunctions.Add(fn); + } + } + } + + private IEnumerable GetMCPContent(Agent agent) + { + List functionDefs = new List(); + var mcpClientManager = _services.GetRequiredService(); + var mcps = agent.McpTools; + foreach (var item in mcps) + { + var ua = mcpClientManager.Factory.GetClientAsync(item.ServerId).Result; + if (ua != null) + { + var tools = ua.ListToolsAsync().Result; + var funcnames = item.Functions.Select(x => x.Name).ToList(); + foreach (var tool in tools.Tools.Where(x => funcnames.Contains(x.Name, StringComparer.OrdinalIgnoreCase))) + { + var funDef = AIFunctionUtilities.MapToFunctionDef(tool); + functionDefs.Add(funDef); + } + } + } + + return functionDefs; + } +} diff --git a/src/Infrastructure/BotSharp.Core/MCP/MCPClientManager.cs b/src/Infrastructure/BotSharp.MCP/MCPClientManager.cs similarity index 93% rename from src/Infrastructure/BotSharp.Core/MCP/MCPClientManager.cs rename to src/Infrastructure/BotSharp.MCP/MCPClientManager.cs index bd115942..bbe70205 100644 --- a/src/Infrastructure/BotSharp.Core/MCP/MCPClientManager.cs +++ b/src/Infrastructure/BotSharp.MCP/MCPClientManager.cs @@ -1,5 +1,7 @@ using BotSharp.Core.Mcp.Settings; using McpDotNet.Client; +using Microsoft.Extensions.Logging; +using System; namespace BotSharp.Core.Mcp; diff --git a/src/Infrastructure/BotSharp.Core/MCP/McpPlugin.cs b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs similarity index 88% rename from src/Infrastructure/BotSharp.Core/MCP/McpPlugin.cs rename to src/Infrastructure/BotSharp.MCP/McpPlugin.cs index 7ab8d249..c54a7050 100644 --- a/src/Infrastructure/BotSharp.Core/MCP/McpPlugin.cs +++ b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs @@ -1,7 +1,10 @@ using BotSharp.Abstraction.Functions; +using BotSharp.Abstraction.Plugins; using BotSharp.Core.Mcp.Functions; using BotSharp.Core.Mcp.Settings; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; namespace BotSharp.Core.Mcp; @@ -33,7 +36,7 @@ public class McpPlugin : IBotSharpPlugin { services.AddScoped(provider => { - var func = new McpAIFunction(tool, client); + var func = new McpToolFunction(tool, client); return func; }); } diff --git a/src/Infrastructure/BotSharp.Core/MCP/Settings/MCPSettings.cs b/src/Infrastructure/BotSharp.MCP/Settings/MCPSettings.cs similarity index 87% rename from src/Infrastructure/BotSharp.Core/MCP/Settings/MCPSettings.cs rename to src/Infrastructure/BotSharp.MCP/Settings/MCPSettings.cs index 6b3c4c5b..34e408e3 100644 --- a/src/Infrastructure/BotSharp.Core/MCP/Settings/MCPSettings.cs +++ b/src/Infrastructure/BotSharp.MCP/Settings/MCPSettings.cs @@ -1,5 +1,6 @@ using McpDotNet.Client; using McpDotNet.Configuration; +using System.Collections.Generic; namespace BotSharp.Core.Mcp.Settings; diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs index 6432b355..81ec1bc7 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentCreationModel.cs @@ -55,7 +55,7 @@ public class AgentCreationModel public int? MaxMessageCount { get; set; } public List Utilities { get; set; } = new(); - public List Acps { 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(); @@ -74,7 +74,7 @@ public class AgentCreationModel Responses = Responses, Samples = Samples, Utilities = Utilities, - Acps = Acps, + McpTools = McpTools, IsPublic = IsPublic, Type = Type, Disabled = Disabled, diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs index c5295891..9f2925e5 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentUpdateModel.cs @@ -40,9 +40,9 @@ public class AgentUpdateModel public List? Utilities { get; set; } /// - /// Acps + /// McpTools /// - public List? Acps { get; set; } + public List? McpTools { get; set; } /// /// knowledge bases @@ -108,7 +108,7 @@ public class AgentUpdateModel Functions = Functions ?? [], Responses = Responses ?? [], Utilities = Utilities ?? [], - Acps = Acps ?? [], + McpTools = McpTools ?? [], KnowledgeBases = KnowledgeBases ?? [], Rules = Rules ?? [], LlmConfig = LlmConfig ?? new() diff --git a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs index 934322cb..db3af34c 100644 --- a/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs +++ b/src/Infrastructure/BotSharp.OpenAPI/ViewModels/Agents/AgentViewModel.cs @@ -24,7 +24,7 @@ public class AgentViewModel [JsonPropertyName("merge_utility")] public bool MergeUtility { get; set; } public List Utilities { get; set; } - public List Acps { get; set; } + public List Acps { get; set; } [JsonPropertyName("knowledge_bases")] public List KnowledgeBases { get; set; } @@ -87,7 +87,7 @@ public class AgentViewModel Responses = agent.Responses ?? [], Samples = agent.Samples ?? [], Utilities = agent.Utilities ?? [], - Acps = agent.Acps ?? [], + Acps = agent.McpTools ?? [], KnowledgeBases = agent.KnowledgeBases ?? [], IsPublic= agent.IsPublic, Disabled = agent.Disabled, diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Collections/AgentDocument.cs index 6be40cf6..bf5330e3 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 Mcps { 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/AgentCPMongoElement.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs similarity index 54% rename from src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentCPMongoElement.cs rename to src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs index eb149736..dae4c665 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentCPMongoElement.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Models/AgentMCPToolMongoElement.cs @@ -8,64 +8,64 @@ using System.Threading.Tasks; namespace BotSharp.Plugin.MongoStorage.Models; [BsonIgnoreExtraElements(Inherited = true)] -public class AgentCPMongoElement +public class AgentMCPToolMongoElement { public string Name { get; set; } public string ServerId { get; set; } public bool Disabled { get; set; } - public List Functions { get; set; } = []; - public List Templates { get; set; } = []; + public List Functions { get; set; } = []; + public List Templates { get; set; } = []; - public static AgentCPMongoElement ToMongoElement(AgentCP utility) + public static AgentMCPToolMongoElement ToMongoElement(MCPTool utility) { - return new AgentCPMongoElement + return new AgentMCPToolMongoElement { Name = utility.Name, Disabled = utility.Disabled, - Functions = utility.Functions?.Select(x => new AcpFunctionMongoElement(x.Name))?.ToList() ?? [], - Templates = utility.Templates?.Select(x => new AcpTemplateMongoElement(x.Name))?.ToList() ?? [] + Functions = utility.Functions?.Select(x => new McpFunctionMongoElement(x.Name))?.ToList() ?? [], + Templates = utility.Templates?.Select(x => new McpTemplateMongoElement(x.Name))?.ToList() ?? [] }; } - public static AgentCP ToDomainElement(AgentCPMongoElement utility) + public static MCPTool ToDomainElement(AgentMCPToolMongoElement utility) { - return new AgentCP + return new MCPTool { Name = utility.Name, Disabled = utility.Disabled, - Functions = utility.Functions?.Select(x => new ACPFunction(x.Name))?.ToList() ?? [], + Functions = utility.Functions?.Select(x => new MCPFunction(x.Name))?.ToList() ?? [], Templates = utility.Templates?.Select(x => new ACPTemplate(x.Name))?.ToList() ?? [] }; } } -public class AcpFunctionMongoElement +public class McpFunctionMongoElement { public string Name { get; set; } - public AcpFunctionMongoElement() + public McpFunctionMongoElement() { } - public AcpFunctionMongoElement(string name) + public McpFunctionMongoElement(string name) { Name = name; } } -public class AcpTemplateMongoElement +public class McpTemplateMongoElement { public string Name { get; set; } - public AcpTemplateMongoElement() + public McpTemplateMongoElement() { } - public AcpTemplateMongoElement(string name) + public McpTemplateMongoElement(string name) { Name = name; } diff --git a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs index 98fee01a..069845ef 100644 --- a/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs +++ b/src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.Agent.cs @@ -62,7 +62,7 @@ public partial class MongoRepository UpdateAgentUtilities(agent.Id, agent.MergeUtility, agent.Utilities); break; case AgentField.Acp: - UpdateAgentMcps(agent.Id, agent.Acps); + UpdateAgentMcps(agent.Id, agent.McpTools); break; case AgentField.KnowledgeBase: UpdateAgentKnowledgeBases(agent.Id, agent.KnowledgeBases); @@ -264,15 +264,15 @@ public partial class MongoRepository _dc.Agents.UpdateOne(filter, update); } - private void UpdateAgentMcps(string agentId, List mcps) + private void UpdateAgentMcps(string agentId, List mcps) { if (mcps == null) return; - var elements = mcps?.Select(x => AgentCPMongoElement.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 - .Set(x => x.Mcps, elements) + .Set(x => x.McpTools, elements) .Set(x => x.UpdatedTime, DateTime.UtcNow); _dc.Agents.UpdateOne(filter, 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.Mcps, agent.Acps.Select(u => AgentCPMongoElement.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() ?? [], - Mcps = x.Acps?.Select(u => AgentCPMongoElement.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() ?? [], - Acps = agentDoc.Mcps?.Select(u => AgentCPMongoElement.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() ?? [] };