BotSharp/tests/BotSharp.PizzaBot.MCPServer/Tools/PlaceOrder.cs
geffzhang 38d1d4fcba feat:upgrade modelcontextprotocol nuget
1、upgrade ModelContextProtocol 0.1.0-preview.5
2、Add ModelContextProtocol.AspNetCore
2025-04-04 10:58:20 +08:00

32 lines
1 KiB
C#

using ModelContextProtocol.Server;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
namespace BotSharp.PizzaBot.MCPServer.Tools;
[McpServerToolType]
public static class PlaceOrder
{
[McpServerTool(Name = "place_an_order"), Description("Place an order when user has confirmed the pizza type and quantity.")]
public static string PlaceAnOrder(
[Description("The pizza type."), Required] string pizza_type,
[Description("quantity of pizza"), Required] int quantity,
[Description("pizza unit price"),Required] double unit_price)
{
if (pizza_type is null)
{
throw new McpServerException("Missing required argument 'pizza_type'");
}
if (quantity <= 0)
{
throw new McpServerException("Missing required argument 'quantity'");
}
if (unit_price < 0)
{
throw new McpServerException("Missing required argument 'unit_price'");
}
return "The order number is P123-01: {order_number = \"P123-01\" }";
}
}