compare_prices
Analyze product prices across multiple supermarkets to identify the lowest price, compare store differences, calculate potential savings, and make informed purchasing decisions.
Instructions
Compare prices for a product across all supermarkets and find the best deal.
This tool analyzes prices and provides:
Lowest price and which supermarket has it
Highest price for comparison
Average price across all stores
Potential savings
Price differences between stores
Perfect for making informed buying decisions and finding the best deals.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| maxResults | No | Number of results to analyze per store (default: 5) | |
| productName | Yes | Product name to compare (e.g., "arroz tio pelon") |
Implementation Reference
- src/tools/comparePrice.ts:39-161 (handler)The executeComparePrice function is the core handler for the 'compare_prices' tool. It searches for products across supermarkets, collects prices, computes lowest/highest/average prices, savings, and returns a formatted summary and structured comparison data.export async function executeComparePrice( client: SuperPrecioApiClient, args: { productName: string; maxResults?: number } ) { if (!args) { throw new Error('Missing required arguments'); } const { productName, maxResults = 5 } = args; const response = await client.searchProducts({ search: productName, maxResults, order: 'OrderByPriceASC', // Sort by price ascending to find best deals }); // Collect all products with prices const allProducts: Array<{ market: string; logo: string; price: number; name: string; link: string; img: string; }> = []; response.allData.forEach((marketProducts, idx) => { const market = response.markets[idx]; if (marketProducts && marketProducts.length > 0) { marketProducts.forEach((product) => { allProducts.push({ market: market.name, logo: market.logo, price: product.price, name: product.desc, link: product.link, img: product.img, }); }); } }); if (allProducts.length === 0) { return { content: [ { type: 'text', text: `No products found for "${productName}". Try a different search term.`, }, ], }; } // Find lowest and highest prices const sortedByPrice = [...allProducts].sort((a, b) => a.price - b.price); const lowest = sortedByPrice[0]; const highest = sortedByPrice[sortedByPrice.length - 1]; // Calculate average const averagePrice = allProducts.reduce((sum, p) => sum + p.price, 0) / allProducts.length; // Calculate savings const savings = highest.price - lowest.price; const savingsPercent = ((savings / highest.price) * 100).toFixed(1); const comparison: ProductComparison = { productName, markets: allProducts.map((p) => ({ market: p.market, logo: p.logo, price: p.price, link: p.link, img: p.img, })), lowestPrice: { market: lowest.market, price: lowest.price, savings: savings, }, highestPrice: { market: highest.market, price: highest.price, }, averagePrice: parseFloat(averagePrice.toFixed(2)), }; const summary = ` Price Comparison for "${productName}" ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🏆 BEST DEAL: ${lowest.market} $${lowest.price.toLocaleString('es-AR')} 💰 POTENTIAL SAVINGS: $${savings.toLocaleString('es-AR')} (${savingsPercent}%) vs. highest price at ${highest.market} 📊 AVERAGE PRICE: $${averagePrice.toLocaleString('es-AR')} 📍 FOUND IN ${response.columns} SUPERMARKETS Price Breakdown: ${sortedByPrice .map( (p, i) => `${i + 1}. ${p.market}: $${p.price.toLocaleString('es-AR')} ${i === 0 ? '🏆 BEST' : ''}` ) .join('\n')} `; return { content: [ { type: 'text', text: summary, }, { type: 'text', text: JSON.stringify(comparison, null, 2), }, ], }; }
- src/tools/comparePrice.ts:8-37 (schema)The comparePriceTool object defines the tool's metadata: name 'compare_prices', detailed description, and inputSchema specifying required 'productName' and optional 'maxResults' parameters with validation.export const comparePriceTool = { name: 'compare_prices', description: `Compare prices for a product across all supermarkets and find the best deal. This tool analyzes prices and provides: - Lowest price and which supermarket has it - Highest price for comparison - Average price across all stores - Potential savings - Price differences between stores Perfect for making informed buying decisions and finding the best deals.`, inputSchema: { type: 'object', properties: { productName: { type: 'string', description: 'Product name to compare (e.g., "arroz tio pelon")', }, maxResults: { type: 'number', description: 'Number of results to analyze per store (default: 5)', minimum: 1, maximum: 20, default: 5, }, }, required: ['productName'], }, };
- src/index.ts:89-116 (registration)In the MCP server's listToolsRequestHandler, the comparePriceTool is registered by being included in the array of available tools returned to clients.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ // V1 Tools searchProductsTool, searchByCodeTool, comparePriceTool, getBestDealsTool, sendNotificationTool, subscribeDeviceTool, // V2 Tools - Shopping Lists createShoppingListTool, addItemsToListTool, getShoppingListsTool, optimizeShoppingListTool, removeShoppingListTool, // V2 Tools - Price Alerts setPriceAlertTool, getMyAlertsTool, removePriceAlertTool, // V2 Tools - Location findNearbySupermarketsTool, ], }; });
- src/index.ts:131-132 (registration)In the MCP server's CallToolRequestHandler switch statement, the 'compare_prices' case dispatches execution to the executeComparePrice handler function.case 'compare_prices': return await executeComparePrice(apiClient, args as any);
- src/index.ts:31-31 (registration)Import statement in the main server file that brings in the tool schema (comparePriceTool) and handler (executeComparePrice) from the implementation file.import { comparePriceTool, executeComparePrice } from './tools/comparePrice.js';