feat: use directory packages

This commit is contained in:
geffzhang 2025-03-18 09:49:36 +08:00
parent 7f6104f6a8
commit bf6b30d3ce
8 changed files with 135 additions and 59 deletions

View file

@ -127,9 +127,11 @@ 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}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.MCP", "src\Infrastructure\BotSharp.MCP\BotSharp.MCP.csproj", "{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{AD91B4ED-0623-4710-913E-6D7C893E76EF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.PizzaBot.MCPServer", "tests\BotSharp.PizzaBot.MCPServer\BotSharp.PizzaBot.MCPServer.csproj", "{8D2AD45F-836A-516F-DE6A-71443CEBB18A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Realtime", "src\Infrastructure\BotSharp.Core.Realtime\BotSharp.Core.Realtime.csproj", "{781F1465-365C-0F22-1775-25025DAFA4C7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -523,6 +525,30 @@ 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
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.ActiveCfg = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Debug|x64.Build.0 = Debug|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|Any CPU.Build.0 = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.ActiveCfg = Release|Any CPU
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C}.Release|x64.Build.0 = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.ActiveCfg = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Debug|x64.Build.0 = Debug|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|Any CPU.Build.0 = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.ActiveCfg = Release|Any CPU
{8D2AD45F-836A-516F-DE6A-71443CEBB18A}.Release|x64.Build.0 = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.ActiveCfg = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Debug|x64.Build.0 = Debug|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|Any CPU.Build.0 = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.ActiveCfg = Release|Any CPU
{781F1465-365C-0F22-1775-25025DAFA4C7}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -584,6 +610,9 @@ 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}
{684781D5-3DD4-6A0B-B53F-0A362CD6BB0C} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
{8D2AD45F-836A-516F-DE6A-71443CEBB18A} = {32FAFFFE-A4CB-4FEE-BF7C-84518BBC6DCC}
{781F1465-365C-0F22-1775-25025DAFA4C7} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}

View file

@ -6,6 +6,7 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="EntityFramework" Version="6.4.4" />
<PackageVersion Include="mcpdotnet" Version="1.1.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCoreVersion)" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
@ -13,6 +14,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
@ -20,6 +22,7 @@
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="Rougamo.Fody" Version="4.0.4" />
<PackageVersion Include="Aspects.Cache" Version="2.0.4" />
@ -106,6 +109,7 @@
<PackageVersion Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageVersion Include="MSTest.TestFramework" Version="3.1.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="BotSharp.Logger" Version="$(BotSharpVersion)" />

View file

@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="mcpdotnet" Version="1.1.0.1" />
<PackageReference Include="mcpdotnet" />
</ItemGroup>
<ItemGroup>

View file

@ -2,6 +2,7 @@ using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Functions;
using BotSharp.Abstraction.Utilities;
using McpDotNet.Client;
using McpDotNet.Protocol.Types;
using Microsoft.Extensions.DependencyInjection;
@ -49,8 +50,8 @@ public class McpToolFunction : IFunctionCallback
var json = string.Join("\n", result.Content
.Where(c => c.Type == "text")
.Select(c => c.Text));
message.Content = json;
message.Data = JsonSerializer.Deserialize(json,typeof(object));
message.Content = json.JsonContent();
return true;
}

View file

@ -0,0 +1,41 @@
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Settings;
using BotSharp.Abstraction.Agents;
using BotSharp.Abstraction.Conversations;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Infrastructures.Enums;
using BotSharp.Abstraction.Translation;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.Json;
namespace BotSharp.MCP.Hooks;
public class MCPResponseHook : ConversationHookBase
{
private readonly IServiceProvider _services;
private readonly IConversationStateService _states;
private const string AIAssistant = BuiltInAgentId.AIAssistant;
public MCPResponseHook(IServiceProvider services,
IConversationStateService states)
{
_services = services;
_states = states;
}
public override async Task OnResponseGenerated(RoleDialogModel message)
{
var agentService = _services.GetRequiredService<IAgentService>();
var agent = await agentService.LoadAgent(message.CurrentAgentId);
if(agent.McpTools.Any(item => item.Functions.Any(x=> x.Name == message.FunctionName)))
{
message.Data = JsonSerializer.Deserialize(message.Content, typeof(object));
}
await base.OnResponseGenerated(message);
}
}

View file

@ -8,9 +8,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="mcpdotnet" Version="1.0.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="mcpdotnet" />
<PackageReference Include="Microsoft.Extensions.Hosting"/>
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Serilog.Extensions.Logging" />
<PackageReference Include="Serilog.Sinks.File" />
</ItemGroup>
</Project>

View file

@ -1,3 +1,4 @@
using McpDotNet.Protocol.Messages;
using McpDotNet.Protocol.Transport;
using McpDotNet.Protocol.Types;
using McpDotNet.Server;
@ -20,26 +21,38 @@ namespace BotSharp.PizzaBot.MCPServer
ServerInfo = new Implementation() { Name = "PizzaServer", Version = "1.0.0" },
Capabilities = new ServerCapabilities()
{
Tools = new(),
Resources = new(),
Prompts = new(),
//Tools = ConfigureTools(),
},
ProtocolVersion = "2024-11-05"
ProtocolVersion = "2024-11-05",
ServerInstructions = "This is a test server with only stub functionality"
};
var loggerFactory = CreateLoggerFactory();
McpServerFactory factory = new McpServerFactory(new StdioServerTransport("PizzaServer", loggerFactory), options, loggerFactory,
"This is a test server with only stub functionality");
McpServerFactory factory = new McpServerFactory(new StdioServerTransport("PizzaServer", loggerFactory), options, loggerFactory);
IMcpServer server = factory.CreateServer();
ConfigureTools(server);
Console.WriteLine("Server object created, registering handlers.");
#region Tools
Console.WriteLine("Server initialized.");
await server.StartAsync();
Console.WriteLine("Server started.");
// Run until process is stopped by the client (parent process)
while (true)
{
await Task.Delay(1000);
}
}
private static void ConfigureTools(IMcpServer server)
{
server.ListToolsHandler = (request, cancellationToken) =>
{
return Task.FromResult(new ListToolsResult()
{
Tools =
[
Tools = [
new Tool()
{
Name = "make_payment",
@ -94,13 +107,13 @@ namespace BotSharp.PizzaBot.MCPServer
server.CallToolHandler = async (request, cancellationToken) =>
{
if (request.Name == "make_payment")
if (request.Params.Name == "make_payment")
{
if (request.Arguments is null || !request.Arguments.TryGetValue("order_number", out var order_number))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("order_number", out var order_number))
{
throw new McpServerException("Missing required argument 'order_number'");
}
if (request.Arguments is null || !request.Arguments.TryGetValue("total_amount", out var total_amount))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("total_amount", out var total_amount))
{
throw new McpServerException("Missing required argument 'total_amount'");
}
@ -114,16 +127,16 @@ namespace BotSharp.PizzaBot.MCPServer
return new CallToolResponse()
{
Content = [new Content() { Text = jsonMessage , Type = "text" }]
Content = [new Content() { Text = jsonMessage, Type = "text" }]
};
}
else if(request.Name == "get_pizza_prices")
else if (request.Params.Name == "get_pizza_prices")
{
if (request.Arguments is null || !request.Arguments.TryGetValue("pizza_type", out var pizza_type))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("pizza_type", out var pizza_type))
{
throw new McpServerException("Missing required argument 'pizza_type'");
}
if (request.Arguments is null || !request.Arguments.TryGetValue("quantity", out var quantity))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("quantity", out var quantity))
{
throw new McpServerException("Missing required argument 'quantity'");
}
@ -139,17 +152,17 @@ namespace BotSharp.PizzaBot.MCPServer
Content = [new Content() { Text = jsonMessage, Type = "text" }]
};
}
else if (request.Name == "place_an_order")
else if (request.Params.Name == "place_an_order")
{
if (request.Arguments is null || !request.Arguments.TryGetValue("pizza_type", out var pizza_type))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("pizza_type", out var pizza_type))
{
throw new McpServerException("Missing required argument 'pizza_type'");
}
if (request.Arguments is null || !request.Arguments.TryGetValue("quantity", out var quantity))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("quantity", out var quantity))
{
throw new McpServerException("Missing required argument 'quantity'");
}
if (request.Arguments is null || !request.Arguments.TryGetValue("unit_price", out var unit_price))
if (request.Params.Arguments is null || !request.Params.Arguments.TryGetValue("unit_price", out var unit_price))
{
throw new McpServerException("Missing required argument 'unit_price'");
}
@ -166,22 +179,9 @@ namespace BotSharp.PizzaBot.MCPServer
}
else
{
throw new McpServerException($"Unknown tool: {request.Name}");
throw new McpServerException($"Unknown tool: {request.Params.Name}");
}
};
#endregion
Console.WriteLine("Server initialized.");
await server.StartAsync();
Console.WriteLine("Server started.");
// Run until process is stopped by the client (parent process)
while (true)
{
await Task.Delay(1000);
}
}
private static ILoggerFactory CreateLoggerFactory()

View file

@ -20,6 +20,6 @@
}
]
}
]
],
"labels": [ "experiment" ]
}