UNPKG

@tomaspavlin/rohlik-mcp

Version:

MCP server for controlling Rohlik.cz grocery shopping website

62 lines 2.47 kB
import { z } from "zod"; export function createOrderHistoryTool(createRohlikAPI) { return { name: "get_order_history", definition: { title: "Get Order History", description: "Get your past delivered orders", inputSchema: { limit: z.number().min(1).max(100).default(10).describe("Maximum number of orders to return (1-100, default: 10)") } }, handler: async (args) => { const { limit = 10 } = args; try { const api = createRohlikAPI(); const orderHistory = await api.getOrderHistory(limit); if (!orderHistory || (Array.isArray(orderHistory) && orderHistory.length === 0)) { return { content: [ { type: "text", text: "No order history found." } ] }; } const formatOrder = (order, index) => { const orderDate = order.deliveredAt || order.createdAt || 'Unknown date'; const totalPrice = order.totalPrice || order.price || 'Unknown price'; const orderNumber = order.orderNumber || order.id || `Order ${index + 1}`; const status = order.status || 'Delivered'; return `${index + 1}. ${orderNumber} Date: ${orderDate} Total: ${totalPrice} CZK Status: ${status}`; }; const orders = Array.isArray(orderHistory) ? orderHistory : [orderHistory]; const output = `📋 ORDER HISTORY (${orders.length} orders):\n\n${orders.map(formatOrder).join('\n\n')}`; return { content: [ { type: "text", text: output } ] }; } catch (error) { return { content: [ { type: "text", text: error instanceof Error ? error.message : String(error) } ], isError: true }; } } }; } //# sourceMappingURL=order-history.js.map