47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using McpDotNet.Server;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel;
|
|
using System.Dynamic;
|
|
using System.Text.Json;
|
|
|
|
namespace BotSharp.PizzaBot.MCPServer.Tools;
|
|
|
|
[McpToolType]
|
|
public static class PizzaPrices
|
|
{
|
|
[McpTool(name: "get_pizza_prices"), Description("call this function to get pizza unit price.")]
|
|
public static string GetPizzaPrices(
|
|
[Description("The pizza type."), Required] string pizza_type,
|
|
[Description("quantity of pizza"), Required] int quantity)
|
|
{
|
|
if (pizza_type is null)
|
|
{
|
|
throw new McpServerException("Missing required argument 'pizza_type'");
|
|
}
|
|
if (quantity <= 0)
|
|
{
|
|
throw new McpServerException("Missing required argument 'quantity'");
|
|
}
|
|
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;
|
|
}
|
|
}
|