UNPKG

@tomaspavlin/rohlik-mcp

Version:

MCP server for controlling Rohlik.cz grocery shopping website

83 lines • 3.44 kB
export function createAccountDataTool(createRohlikAPI) { return { name: "get_account_data", definition: { title: "Get Account Data", description: "Get comprehensive account information including delivery details, orders, announcements, cart, and more", inputSchema: {} }, handler: async () => { try { const api = createRohlikAPI(); const accountData = await api.getAccountData(); const formatSection = (title, data) => { if (!data || (Array.isArray(data) && data.length === 0)) { return `${title}: No data available`; } if (typeof data === 'object') { return `${title}: ${JSON.stringify(data, null, 2)}`; } return `${title}: ${String(data)}`; }; const sections = []; // Cart summary if (accountData.cart) { sections.push(`šŸ›’ CART SUMMARY: • Total items: ${accountData.cart.total_items} • Total price: ${accountData.cart.total_price} CZK • Can order: ${accountData.cart.can_make_order ? 'Yes' : 'No'}`); } // Delivery info if (accountData.delivery) { sections.push(formatSection("🚚 DELIVERY INFO", accountData.delivery)); } // Next delivery slot if (accountData.next_delivery_slot) { sections.push(formatSection("ā° NEXT DELIVERY SLOT", accountData.next_delivery_slot)); } // Orders if (accountData.next_order) { sections.push(formatSection("šŸ“¦ UPCOMING ORDER", accountData.next_order)); } if (accountData.last_order) { sections.push(formatSection("šŸ“‹ LAST ORDER", accountData.last_order)); } // Premium profile if (accountData.premium_profile) { sections.push(formatSection("⭐ PREMIUM PROFILE", accountData.premium_profile)); } // Announcements if (accountData.announcements) { sections.push(formatSection("šŸ“¢ ANNOUNCEMENTS", accountData.announcements)); } // Reusable bags if (accountData.bags) { sections.push(formatSection("ā™»ļø REUSABLE BAGS", accountData.bags)); } const output = sections.length > 0 ? sections.join('\n\n') : 'No account data available'; return { content: [ { type: "text", text: output } ] }; } catch (error) { return { content: [ { type: "text", text: error instanceof Error ? error.message : String(error) } ], isError: true }; } } }; } //# sourceMappingURL=account-data.js.map