setPriceAlert.ts•3.03 kB
/**
* MCP Tool: Set Price Alert
* Create a personalized price alert for a product
*/
import type { SuperPrecioApiClient } from '../client/superPrecioApi.js';
export const setPriceAlertTool = {
name: 'set_price_alert',
description: `Set a personalized price alert for a product.
Get notified when a product reaches your target price!
Features:
- Monitor any product by name or barcode
- Set your desired price target
- Automatic price checking across all supermarkets
- Get alerts when price drops below your target
Perfect for:
- Waiting for sales on expensive items
- Tracking price drops
- Budget-conscious shopping
- Never missing a good deal
Example: "Alert me when Coca Cola 2.25L drops below $800"`,
inputSchema: {
type: 'object',
properties: {
productName: {
type: 'string',
description: 'Product name to monitor (e.g., "Coca Cola 2.25L", "Arroz integral")',
},
targetPrice: {
type: 'number',
description: 'Target price in pesos - alert when product reaches or goes below this price',
minimum: 0.01,
},
barcode: {
type: 'string',
description: 'Optional barcode/EAN for exact product matching',
},
userId: {
type: 'number',
description: 'Optional user ID to associate this alert with',
},
notifyEnabled: {
type: 'boolean',
description: 'Enable push notifications when alert triggers (default: true)',
default: true,
},
},
required: ['productName', 'targetPrice'],
},
};
export async function executeSetPriceAlert(
client: SuperPrecioApiClient,
args: {
productName: string;
targetPrice: number;
barcode?: string;
userId?: number;
notifyEnabled?: boolean;
}
) {
const response = await client.createPriceAlert(args);
if (!response.success) {
return {
content: [
{
type: 'text',
text: `Failed to create price alert: ${response.message || 'Unknown error'}`,
},
],
isError: true,
};
}
const alert = response.data;
const summary = `
🔔 Price Alert Created Successfully!
📦 Product: ${alert.productName}
${alert.barcode ? `🏷️ Barcode: ${alert.barcode}` : ''}
🎯 Target Price: $${alert.targetPrice.toLocaleString('es-AR')}
🆔 Alert ID: ${alert.id}
${alert.notifyEnabled ? '✅ Notifications: Enabled' : '🔕 Notifications: Disabled'}
📅 Created: ${new Date(alert.createdAt).toLocaleDateString('es-AR')}
What happens now:
1. We'll search for this product across all supermarkets
2. When the price drops to $${alert.targetPrice} or below, you'll be notified
3. Use get_my_alerts to check the status anytime
4. Use remove_price_alert to cancel this alert
💡 Tip: Run check_alert_status periodically to see current prices!
`;
return {
content: [
{
type: 'text',
text: summary,
},
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
};
}