send_notification
Send push notifications to specific devices or broadcast alerts to all users for price drops, deals, and important updates using Firebase Cloud Messaging.
Instructions
Send a push notification to a specific device or broadcast to all subscribed devices.
This tool can:
Send personalized notifications to specific devices
Broadcast alerts to all users
Include custom data (like product links, images, etc.)
Notify about price drops, deals, or important updates
Note: Requires Firebase Cloud Messaging setup on the Superprecio server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | Notification title | |
| message | Yes | Notification body/message | |
| deviceToken | No | Optional: specific device token to send to. If not provided, broadcasts to all devices. | |
| data | No | Optional: additional data to include (e.g., product URL, image URL) |
Implementation Reference
- src/tools/sendNotification.ts:42-105 (handler)Core handler function that implements the send_notification tool logic. Handles input validation, conditional API calls for targeted or broadcast notifications, response formatting, and error handling.export async function executeSendNotification( client: SuperPrecioApiClient, args: { title: string; message: string; deviceToken?: string; data?: Record<string, any>; } ) { if (!args) { throw new Error('Missing required arguments'); } const { title, message, deviceToken, data } = args; try { let result; if (deviceToken) { // Send to specific device result = await client.sendNotification({ token: deviceToken, title, body: message, data, }); return { content: [ { type: 'text', text: `Notification sent successfully to device!\n\nTitle: ${title}\nMessage: ${message}`, }, ], }; } else { // Broadcast to all devices result = await client.broadcastNotification({ title, body: message, data, }); return { content: [ { type: 'text', text: `Notification broadcast successfully to all devices!\n\nTitle: ${title}\nMessage: ${message}\n\nResult: ${JSON.stringify(result, null, 2)}`, }, ], }; } } catch (error: any) { return { content: [ { type: 'text', text: `Failed to send notification: ${error.message}`, }, ], isError: true, }; } }
- src/tools/sendNotification.ts:7-40 (schema)Defines the tool metadata, description, and input schema for validation of send_notification parameters.export const sendNotificationTool = { name: 'send_notification', description: `Send a push notification to a specific device or broadcast to all subscribed devices. This tool can: - Send personalized notifications to specific devices - Broadcast alerts to all users - Include custom data (like product links, images, etc.) - Notify about price drops, deals, or important updates Note: Requires Firebase Cloud Messaging setup on the Superprecio server.`, inputSchema: { type: 'object', properties: { title: { type: 'string', description: 'Notification title', }, message: { type: 'string', description: 'Notification body/message', }, deviceToken: { type: 'string', description: 'Optional: specific device token to send to. If not provided, broadcasts to all devices.', }, data: { type: 'object', description: 'Optional: additional data to include (e.g., product URL, image URL)', }, }, required: ['title', 'message'], }, };
- src/index.ts:97-97 (registration)Registration of sendNotificationTool in the array of tools returned by the MCP listTools handler.sendNotificationTool,
- src/index.ts:137-138 (registration)Dispatch/execution routing for the send_notification tool in the MCP callTool request handler.case 'send_notification': return await executeSendNotification(apiClient, args as any);
- src/client/superPrecioApi.ts:123-135 (helper)Underlying API client method for sending notifications to a specific device token, called by the tool handler.async sendNotification(data: { token: string; title: string; body: string; data?: Record<string, any>; }): Promise<any> { try { const response = await this.client.post('/notifications/send', data); return response.data; } catch (error) { throw this.handleError(error); } }