diff --git a/src/Infrastructure/BotSharp.MCP/McpPlugin.cs b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs index 3441679d..0501f819 100644 --- a/src/Infrastructure/BotSharp.MCP/McpPlugin.cs +++ b/src/Infrastructure/BotSharp.MCP/McpPlugin.cs @@ -40,7 +40,6 @@ public class McpPlugin : IBotSharpPlugin } // Register hooks services.AddScoped(); - services.AddScoped(); } private async Task RegisterFunctionCall(IServiceCollection services, McpServerConfig server) diff --git a/src/Infrastructure/BotSharp.MCP/Hooks/MCPResponseHook.cs b/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotConversationHook.cs similarity index 54% rename from src/Infrastructure/BotSharp.MCP/Hooks/MCPResponseHook.cs rename to tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotConversationHook.cs index c5470582..92083ee7 100644 --- a/src/Infrastructure/BotSharp.MCP/Hooks/MCPResponseHook.cs +++ b/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaBotConversationHook.cs @@ -1,31 +1,43 @@ using BotSharp.Abstraction.Agents; using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations.Models; -using Microsoft.Extensions.DependencyInjection; -using System; using System.Linq; using System.Text.Json; -using System.Threading.Tasks; -namespace BotSharp.MCP.Hooks; +namespace BotSharp.Plugin.PizzaBot.Hooks; -public class MCPResponseHook : ConversationHookBase +public class PizzaBotConversationHook : ConversationHookBase { private readonly IServiceProvider _services; - private readonly IConversationStateService _states; + private readonly IConversationStateService _states; - public MCPResponseHook(IServiceProvider services, + public PizzaBotConversationHook(IServiceProvider services, IConversationStateService states) { _services = services; _states = states; } + + public override async Task OnPostbackMessageReceived(RoleDialogModel message, PostbackMessageModel replyMsg) + { + if (replyMsg.FunctionName == "get_pizza_types") + { + // message.StopCompletion = true; + } + return; + } + + public override Task OnTaskCompleted(RoleDialogModel message) + { + return base.OnTaskCompleted(message); + } + public override async Task OnResponseGenerated(RoleDialogModel message) { var agentService = _services.GetRequiredService(); var state = _services.GetRequiredService(); var agent = await agentService.LoadAgent(message.CurrentAgentId); - if(agent.McpTools.Any(item => item.Functions.Any(x=> x.Name == message.FunctionName))) + if (agent.McpTools.Any(item => item.Functions.Any(x => x.Name == message.FunctionName))) { var data = JsonDocument.Parse(JsonSerializer.Serialize(message.Data)); state.SaveStateByArgs(data); @@ -33,4 +45,3 @@ public class MCPResponseHook : ConversationHookBase await base.OnResponseGenerated(message); } } - diff --git a/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaTypeConversationHook.cs b/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaTypeConversationHook.cs deleted file mode 100644 index 6fb34772..00000000 --- a/tests/BotSharp.Plugin.PizzaBot/Hooks/PizzaTypeConversationHook.cs +++ /dev/null @@ -1,21 +0,0 @@ -using BotSharp.Abstraction.Conversations; -using BotSharp.Abstraction.Conversations.Models; - -namespace BotSharp.Plugin.PizzaBot.Hooks; - -public class PizzaTypeConversationHook : ConversationHookBase -{ - public override async Task OnPostbackMessageReceived(RoleDialogModel message, PostbackMessageModel replyMsg) - { - if (replyMsg.FunctionName == "get_pizza_types") - { - // message.StopCompletion = true; - } - return; - } - - public override Task OnTaskCompleted(RoleDialogModel message) - { - return base.OnTaskCompleted(message); - } -}