subscribeDevice.ts•1.61 kB
/**
* MCP Tool: Subscribe Device
* Subscribe a device to receive push notifications
*/
import type { SuperPrecioApiClient } from '../client/superPrecioApi.js';
export const subscribeDeviceTool = {
name: 'subscribe_device',
description: `Subscribe a device to receive push notifications about deals and price alerts.
This tool registers a device token with the Superprecio notification system.
Once subscribed, devices will receive:
- Price drop alerts
- Special deal notifications
- New product announcements
- Custom promotional messages
Note: Requires a valid Firebase Cloud Messaging device token.`,
inputSchema: {
type: 'object',
properties: {
deviceToken: {
type: 'string',
description: 'Firebase Cloud Messaging device token',
},
},
required: ['deviceToken'],
},
};
export async function executeSubscribeDevice(
client: SuperPrecioApiClient,
args: { deviceToken: string }
) {
const { deviceToken } = args;
try {
const result = await client.subscribeDevice(deviceToken);
return {
content: [
{
type: 'text',
text: `Device subscribed successfully!\n\nYou will now receive notifications about:\n- Price drops\n- Special deals\n- New products\n- Promotional offers\n\nDevice Token: ${deviceToken.substring(0, 20)}...\n\nResult: ${JSON.stringify(result, null, 2)}`,
},
],
};
} catch (error: any) {
return {
content: [
{
type: 'text',
text: `Failed to subscribe device: ${error.message}`,
},
],
isError: true,
};
}
}