feat: use directory packages
This commit is contained in:
parent
7f6104f6a8
commit
bf6b30d3ce
33
BotSharp.sln
33
BotSharp.sln
|
|
@ -127,9 +127,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Core.Rules", "src\
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BotSharp.Plugin.DeepSeekAI", "src\Plugins\BotSharp.Plugin.DeepSeekAI\BotSharp.Plugin.DeepSeekAI.csproj", "{AF329442-B48E-4B48-A18A-1C869D1BA6F5}"
|
||||||
EndProject
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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|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.ActiveCfg = Release|Any CPU
|
||||||
{AF329442-B48E-4B48-A18A-1C869D1BA6F5}.Release|x64.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
@ -584,6 +610,9 @@ Global
|
||||||
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
{F812BAAE-5A7D-4DF7-8E71-70696B51C61F} = {E29DC6C4-5E57-48C5-BCB0-6B8F84782749}
|
||||||
{AFD64412-4D6A-452E-82A2-79E5D8842E29} = {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}
|
{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
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
SolutionGuid = {A9969D89-C98B-40A5-A12B-FC87E55B3A19}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="EntityFramework" Version="6.4.4" />
|
<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.Http.Abstractions" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageVersion Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCoreVersion)" />
|
<PackageVersion Include="Microsoft.AspNetCore.StaticFiles" Version="$(AspNetCoreVersion)" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||||
|
|
@ -13,13 +14,15 @@
|
||||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.2" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.1" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
|
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
|
||||||
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
<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="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
|
||||||
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
|
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="8.0.0" />
|
||||||
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
|
<PackageVersion Include="System.Memory.Data" Version="8.0.0" />
|
||||||
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
|
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
|
||||||
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
|
<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="Serilog.Sinks.File" Version="6.0.0" />
|
||||||
<PackageVersion Include="Rougamo.Fody" Version="4.0.4" />
|
<PackageVersion Include="Rougamo.Fody" Version="4.0.4" />
|
||||||
<PackageVersion Include="Aspects.Cache" Version="2.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.TestAdapter" Version="3.1.1" />
|
||||||
<PackageVersion Include="MSTest.TestFramework" 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.DependencyInjection" Version="8.0.1" />
|
||||||
|
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageVersion Include="BotSharp.Logger" Version="$(BotSharpVersion)" />
|
<PackageVersion Include="BotSharp.Logger" Version="$(BotSharpVersion)" />
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="mcpdotnet" Version="1.1.0.1" />
|
<PackageReference Include="mcpdotnet" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using BotSharp.Abstraction.Agents;
|
||||||
using BotSharp.Abstraction.Agents.Models;
|
using BotSharp.Abstraction.Agents.Models;
|
||||||
using BotSharp.Abstraction.Conversations.Models;
|
using BotSharp.Abstraction.Conversations.Models;
|
||||||
using BotSharp.Abstraction.Functions;
|
using BotSharp.Abstraction.Functions;
|
||||||
|
using BotSharp.Abstraction.Utilities;
|
||||||
using McpDotNet.Client;
|
using McpDotNet.Client;
|
||||||
using McpDotNet.Protocol.Types;
|
using McpDotNet.Protocol.Types;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
@ -49,8 +50,8 @@ public class McpToolFunction : IFunctionCallback
|
||||||
var json = string.Join("\n", result.Content
|
var json = string.Join("\n", result.Content
|
||||||
.Where(c => c.Type == "text")
|
.Where(c => c.Type == "text")
|
||||||
.Select(c => c.Text));
|
.Select(c => c.Text));
|
||||||
message.Content = json;
|
message.Content = json.JsonContent();
|
||||||
message.Data = JsonSerializer.Deserialize(json,typeof(object));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
41
src/Infrastructure/BotSharp.MCP/Hooks/MCPResponseHook.cs
Normal file
41
src/Infrastructure/BotSharp.MCP/Hooks/MCPResponseHook.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -8,9 +8,10 @@
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="mcpdotnet" Version="1.0.1.3" />
|
<PackageReference Include="mcpdotnet" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Hosting"/>
|
||||||
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" />
|
||||||
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
|
<PackageReference Include="Serilog.Extensions.Logging" />
|
||||||
|
<PackageReference Include="Serilog.Sinks.File" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using McpDotNet.Protocol.Messages;
|
||||||
using McpDotNet.Protocol.Transport;
|
using McpDotNet.Protocol.Transport;
|
||||||
using McpDotNet.Protocol.Types;
|
using McpDotNet.Protocol.Types;
|
||||||
using McpDotNet.Server;
|
using McpDotNet.Server;
|
||||||
|
|
@ -20,30 +21,42 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
ServerInfo = new Implementation() { Name = "PizzaServer", Version = "1.0.0" },
|
ServerInfo = new Implementation() { Name = "PizzaServer", Version = "1.0.0" },
|
||||||
Capabilities = new ServerCapabilities()
|
Capabilities = new ServerCapabilities()
|
||||||
{
|
{
|
||||||
Tools = new(),
|
//Tools = ConfigureTools(),
|
||||||
Resources = new(),
|
|
||||||
Prompts = new(),
|
|
||||||
},
|
},
|
||||||
ProtocolVersion = "2024-11-05"
|
ProtocolVersion = "2024-11-05",
|
||||||
|
ServerInstructions = "This is a test server with only stub functionality"
|
||||||
};
|
};
|
||||||
var loggerFactory = CreateLoggerFactory();
|
var loggerFactory = CreateLoggerFactory();
|
||||||
McpServerFactory factory = new McpServerFactory(new StdioServerTransport("PizzaServer", loggerFactory), options, loggerFactory,
|
McpServerFactory factory = new McpServerFactory(new StdioServerTransport("PizzaServer", loggerFactory), options, loggerFactory);
|
||||||
"This is a test server with only stub functionality");
|
|
||||||
IMcpServer server = factory.CreateServer();
|
IMcpServer server = factory.CreateServer();
|
||||||
|
ConfigureTools(server);
|
||||||
|
|
||||||
Console.WriteLine("Server object created, registering handlers.");
|
Console.WriteLine("Server object created, registering handlers.");
|
||||||
|
|
||||||
#region Tools
|
Console.WriteLine("Server initialized.");
|
||||||
server.ListToolsHandler = (request, cancellationToken) =>
|
|
||||||
|
await server.StartAsync();
|
||||||
|
|
||||||
|
Console.WriteLine("Server started.");
|
||||||
|
|
||||||
|
// Run until process is stopped by the client (parent process)
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
return Task.FromResult(new ListToolsResult()
|
await Task.Delay(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureTools(IMcpServer server)
|
||||||
|
{
|
||||||
|
server.ListToolsHandler = (request, cancellationToken) =>
|
||||||
{
|
{
|
||||||
Tools =
|
return Task.FromResult(new ListToolsResult()
|
||||||
[
|
{
|
||||||
new Tool()
|
Tools = [
|
||||||
|
new Tool()
|
||||||
{
|
{
|
||||||
Name = "make_payment",
|
Name = "make_payment",
|
||||||
Description = "call this function to make payment",
|
Description = "call this function to make payment",
|
||||||
InputSchema = new JsonSchema()
|
InputSchema = new JsonSchema()
|
||||||
{
|
{
|
||||||
Type = "object",
|
Type = "object",
|
||||||
|
|
@ -51,9 +64,9 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
{
|
{
|
||||||
["order_number"] = new JsonSchemaProperty() { Type = "string", Description = "order number." },
|
["order_number"] = new JsonSchemaProperty() { Type = "string", Description = "order number." },
|
||||||
["total_amount"] = new JsonSchemaProperty() { Type = "string", Description = "total amount." },
|
["total_amount"] = new JsonSchemaProperty() { Type = "string", Description = "total amount." },
|
||||||
},
|
},
|
||||||
Required = new List<string>() { "order_number", "total_amount" }
|
Required = new List<string>() { "order_number", "total_amount" }
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
new Tool()
|
new Tool()
|
||||||
{
|
{
|
||||||
|
|
@ -63,7 +76,7 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
{
|
{
|
||||||
Type = "object",
|
Type = "object",
|
||||||
Properties = new Dictionary<string, JsonSchemaProperty>()
|
Properties = new Dictionary<string, JsonSchemaProperty>()
|
||||||
{
|
{
|
||||||
["pizza_type"] = new JsonSchemaProperty() { Type = "string", Description = "The pizza type." },
|
["pizza_type"] = new JsonSchemaProperty() { Type = "string", Description = "The pizza type." },
|
||||||
["quantity"] = new JsonSchemaProperty() { Type = "string", Description = "quantity of pizza." },
|
["quantity"] = new JsonSchemaProperty() { Type = "string", Description = "quantity of pizza." },
|
||||||
|
|
||||||
|
|
@ -79,7 +92,7 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
{
|
{
|
||||||
Type = "object",
|
Type = "object",
|
||||||
Properties = new Dictionary<string, JsonSchemaProperty>()
|
Properties = new Dictionary<string, JsonSchemaProperty>()
|
||||||
{
|
{
|
||||||
["pizza_type"] = new JsonSchemaProperty() { Type = "string", Description = "The pizza type." },
|
["pizza_type"] = new JsonSchemaProperty() { Type = "string", Description = "The pizza type." },
|
||||||
["quantity"] = new JsonSchemaProperty() { Type = "number", Description = "quantity of pizza." },
|
["quantity"] = new JsonSchemaProperty() { Type = "number", Description = "quantity of pizza." },
|
||||||
["unit_price"] = new JsonSchemaProperty() { Type = "number", Description = "unit price" },
|
["unit_price"] = new JsonSchemaProperty() { Type = "number", Description = "unit price" },
|
||||||
|
|
@ -88,19 +101,19 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
Required = new List<string>(){"pizza_type", "quantity", "unit_price" }
|
Required = new List<string>(){"pizza_type", "quantity", "unit_price" }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
server.CallToolHandler = async (request, cancellationToken) =>
|
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'");
|
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'");
|
throw new McpServerException("Missing required argument 'total_amount'");
|
||||||
}
|
}
|
||||||
|
|
@ -113,17 +126,17 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
var jsonMessage = JsonSerializer.Serialize(message, jso);
|
var jsonMessage = JsonSerializer.Serialize(message, jso);
|
||||||
|
|
||||||
return new CallToolResponse()
|
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'");
|
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'");
|
throw new McpServerException("Missing required argument 'quantity'");
|
||||||
}
|
}
|
||||||
|
|
@ -139,23 +152,23 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
Content = [new Content() { Text = jsonMessage, Type = "text" }]
|
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'");
|
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'");
|
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'");
|
throw new McpServerException("Missing required argument 'unit_price'");
|
||||||
}
|
}
|
||||||
dynamic message = new ExpandoObject();
|
dynamic message = new ExpandoObject();
|
||||||
message.order_number = "P123-01";
|
message.order_number = "P123-01";
|
||||||
message.Content = "The order number is P123-01";
|
message.Content = "The order number is P123-01";
|
||||||
// Serialize the message to JSON
|
// Serialize the message to JSON
|
||||||
var jso = new JsonSerializerOptions() { WriteIndented = true };
|
var jso = new JsonSerializerOptions() { WriteIndented = true };
|
||||||
var jsonMessage = JsonSerializer.Serialize(message, jso);
|
var jsonMessage = JsonSerializer.Serialize(message, jso);
|
||||||
|
|
@ -166,22 +179,9 @@ namespace BotSharp.PizzaBot.MCPServer
|
||||||
}
|
}
|
||||||
else
|
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()
|
private static ILoggerFactory CreateLoggerFactory()
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,6 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
"labels": [ "experiment" ]
|
"labels": [ "experiment" ]
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue