createShoppingList.ts•3.49 kB
/**
* MCP Tool: Create Shopping List
* Creates a new shopping list with optional items
*/
import type { SuperPrecioApiClient } from '../client/superPrecioApi.js';
export const createShoppingListTool = {
name: 'create_shopping_list',
description: `Create a new shopping list to organize your purchases.
You can create an empty list and add items later, or create a list with items right away.
This is useful for planning your shopping and then optimizing which supermarket to buy from.
Features:
- Create named lists (e.g., "Weekly groceries", "Party supplies")
- Add optional description
- Include initial items with quantities
- Link to user ID (optional)`,
inputSchema: {
type: 'object',
properties: {
name: {
type: 'string',
description: 'Name of the shopping list (e.g., "Weekly groceries", "Monthly shopping")',
},
description: {
type: 'string',
description: 'Optional description of what this list is for',
},
userId: {
type: 'number',
description: 'Optional user ID to associate this list with',
},
items: {
type: 'array',
description: 'Optional initial items to add to the list',
items: {
type: 'object',
properties: {
productName: {
type: 'string',
description: 'Product name (e.g., "Leche descremada", "Arroz integral")',
},
barcode: {
type: 'string',
description: 'Optional product barcode/EAN for exact matching',
},
quantity: {
type: 'number',
description: 'Quantity needed (default: 1)',
minimum: 1,
},
notes: {
type: 'string',
description: 'Optional notes (e.g., "1 liter", "2kg bag")',
},
},
required: ['productName'],
},
},
},
required: ['name'],
},
};
export async function executeCreateShoppingList(
client: SuperPrecioApiClient,
args: {
name: string;
description?: string;
userId?: number;
items?: Array<{
productName: string;
barcode?: string;
quantity?: number;
notes?: string;
}>;
}
) {
const response = await client.createShoppingList(args);
if (!response.success) {
return {
content: [
{
type: 'text',
text: `Failed to create shopping list: ${response.message || 'Unknown error'}`,
},
],
isError: true,
};
}
const list = response.data;
const itemCount = list.items?.length || 0;
const summary = `
✅ Shopping List Created Successfully!
📝 Name: ${list.name}
${list.description ? `📄 Description: ${list.description}` : ''}
🆔 List ID: ${list.id}
🛒 Items: ${itemCount} ${itemCount === 1 ? 'item' : 'items'}
📅 Created: ${new Date(list.createdAt).toLocaleDateString('es-AR')}
${itemCount > 0 ? `
Items in list:
${list.items.map((item: any, i: number) => `${i + 1}. ${item.productName} (x${item.quantity})`).join('\n')}
` : 'No items yet. Use add_items_to_list to add products.'}
Next steps:
- Use add_items_to_list to add more products
- Use optimize_shopping_list to find the best supermarket for this list
`;
return {
content: [
{
type: 'text',
text: summary,
},
{
type: 'text',
text: JSON.stringify(response.data, null, 2),
},
],
};
}