BotSharp/tests/BotSharp.PizzaBot.MCPServer/Tools/PizzaPrices.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2025-04-15 16:28:37 +00:00
using ModelContextProtocol;
using ModelContextProtocol.Server;
2025-03-19 03:07:31 +00:00
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
2025-03-19 03:07:31 +00:00
using System.Dynamic;
using System.Text.Json;
namespace BotSharp.PizzaBot.MCPServer.Tools;
[McpServerToolType]
2025-03-19 03:07:31 +00:00
public static class PizzaPrices
{
[McpServerTool(Name = "get_pizza_prices"), Description("call this function to get pizza unit price.")]
2025-03-19 03:07:31 +00:00
public static string GetPizzaPrices(
[Description("The pizza type."), Required] string pizza_type,
[Description("quantity of pizza"), Required] int quantity)
{
if (pizza_type is null)
{
2025-04-15 16:28:37 +00:00
throw new McpException("Missing required argument 'pizza_type'");
2025-03-19 03:07:31 +00:00
}
if (quantity <= 0)
{
2025-04-15 16:28:37 +00:00
throw new McpException("Missing required argument 'quantity'");
2025-03-19 03:07:31 +00:00
}
double unit_price = 0;
if (pizza_type.ToString() == "Pepperoni Pizza")
{
unit_price = 3.2 * (int)quantity;
}
else if (pizza_type.ToString() == "Cheese Pizza")
{
unit_price = 3.5 * (int)quantity; ;
}
else if (pizza_type.ToString() == "Margherita Pizza")
{
unit_price = 3.8 * (int)quantity; ;
}
dynamic message = new ExpandoObject();
message.unit_price = unit_price;
var jso = new JsonSerializerOptions() { WriteIndented = true };
var jsonMessage = JsonSerializer.Serialize(message, jso);
return jsonMessage;
}
}