getMyAlerts.tsβ’3.48 kB
/**
* MCP Tool: Get My Alerts
* Get all price alerts with their current status
*/
import type { SuperPrecioApiClient } from '../client/superPrecioApi.js';
export const getMyAlertsTool = {
name: 'get_my_alerts',
description: `Get all your active price alerts with their current status.
View all products you're monitoring and see:
- Current prices vs. target prices
- Which alerts have been triggered
- How close you are to your target price
- Last time prices were checked
Perfect for:
- Reviewing all your alerts
- Finding triggered alerts (good deals!)
- Managing your watchlist`,
inputSchema: {
type: 'object',
properties: {
userId: {
type: 'number',
description: 'Optional: Filter alerts by user ID',
},
isActive: {
type: 'boolean',
description: 'Optional: Filter by active/inactive alerts (default: show all)',
},
},
},
};
export async function executeGetMyAlerts(
client: SuperPrecioApiClient,
args: { userId?: number; isActive?: boolean }
) {
const response = await client.getPriceAlerts(args);
if (!response.success) {
return {
content: [
{
type: 'text',
text: `Failed to get price alerts: ${response.message || 'Unknown error'}`,
},
],
isError: true,
};
}
const alerts = response.data;
const count = response.count || 0;
if (count === 0) {
return {
content: [
{
type: 'text',
text: `
No price alerts found.
Create your first alert with set_price_alert!
Example: Alert me when Coca Cola drops below $800
`,
},
],
};
}
const triggeredCount = alerts.filter((a: any) => a.currentPrice && a.currentPrice <= a.targetPrice).length;
const summary = `
π Your Price Alerts (${count} total)
${triggeredCount > 0 ? `π ${triggeredCount} ALERT${triggeredCount === 1 ? '' : 'S'} TRIGGERED!` : ''}
βββββββββββββββββββββββββββββββββββββ
${alerts
.map((alert: any, i: number) => {
const isTriggered = alert.currentPrice && alert.currentPrice <= alert.targetPrice;
const status = isTriggered ? 'π TRIGGERED!' : alert.currentPrice ? 'π Monitoring' : 'β³ Pending check';
const priceDiff = alert.currentPrice ? (alert.currentPrice - alert.targetPrice) : null;
return `
${i + 1}. ${alert.productName} (ID: ${alert.id})
${status}
π― Target: $${alert.targetPrice.toLocaleString('es-AR')}
${alert.currentPrice ? `π΅ Current: $${alert.currentPrice.toLocaleString('es-AR')}${priceDiff !== null ? ` (${priceDiff >= 0 ? '+' : ''}$${priceDiff.toFixed(2)})` : ''}` : 'π΅ Current: Not checked yet'}
${alert.barcode ? `π·οΈ Barcode: ${alert.barcode}` : ''}
${alert.notifyEnabled ? 'π' : 'π'} Notifications ${alert.isActive ? 'β
' : 'βΈοΈ'} ${alert.isActive ? 'Active' : 'Paused'}
${alert.lastCheckedAt ? `π
Last checked: ${new Date(alert.lastCheckedAt).toLocaleDateString('es-AR')}` : ''}
`;
})
.join('\n')}
Actions you can take:
- Use check_alert_status to update current prices
- Use remove_price_alert to delete an alert
${triggeredCount > 0 ? '\nπ Good news! You have triggered alerts - great time to shop!' : ''}
`;
return {
content: [
{
type: 'text',
text: summary,
},
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
};
}