get_shopping_lists
Retrieve all active shopping lists with their items to view saved lists, find specific lists for optimization, or manage multiple lists, optionally filtered by user ID.
Instructions
Get all shopping lists, optionally filtered by user.
Returns a list of all active shopping lists with their items. Useful for:
Viewing all your saved lists
Finding a specific list to optimize
Managing multiple shopping lists
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| userId | No | Optional: Filter lists by user ID |
Implementation Reference
- src/tools/getShoppingLists.ts:27-98 (handler)The handler function executeGetShoppingLists that performs the core logic: calls the API client to fetch shopping lists, handles errors, formats a user-friendly summary with list details, and returns structured content including JSON data.export async function executeGetShoppingLists( client: SuperPrecioApiClient, args: { userId?: number } ) { const response = await client.getShoppingLists(args); if (!response.success) { return { content: [ { type: 'text', text: `Failed to get shopping lists: ${response.message || 'Unknown error'}`, }, ], isError: true, }; } const lists = response.data; const count = response.count || 0; if (count === 0) { return { content: [ { type: 'text', text: ` No shopping lists found. Create your first list with create_shopping_list! `, }, ], }; } const summary = ` π Your Shopping Lists (${count} total) βββββββββββββββββββββββββββββββ ${lists .map((list: any, i: number) => { const itemCount = list.items?.length || 0; return ` ${i + 1}. ${list.name} (ID: ${list.id}) ${list.description ? `π ${list.description}` : ''} π Items: ${itemCount} π Created: ${new Date(list.createdAt).toLocaleDateString('es-AR')} ${itemCount > 0 ? ` Products: ${list.items.slice(0, 3).map((item: any) => item.productName).join(', ')}${itemCount > 3 ? '...' : ''}` : ''} `; }) .join('\n')} Actions you can take: - optimize_shopping_list - Find best supermarket for a list - add_items_to_list - Add more products - remove_shopping_list - Delete a list `; return { content: [ { type: 'text', text: summary, }, { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; }
- src/tools/getShoppingLists.ts:7-25 (schema)Tool definition including name, description, and inputSchema for validation of parameters (userId optional number).export const getShoppingListsTool = { name: 'get_shopping_lists', description: `Get all shopping lists, optionally filtered by user. Returns a list of all active shopping lists with their items. Useful for: - Viewing all your saved lists - Finding a specific list to optimize - Managing multiple shopping lists`, inputSchema: { type: 'object', properties: { userId: { type: 'number', description: 'Optional: Filter lists by user ID', }, }, }, };
- src/index.ts:150-151 (registration)Switch case in the MCP server tool handler that routes 'get_shopping_lists' calls to the execute function.case 'get_shopping_lists': return await executeGetShoppingLists(apiClient, args as any);
- src/index.ts:103-103 (registration)Inclusion of getShoppingListsTool in the list of tools returned by ListToolsRequestSchema.getShoppingListsTool,
- src/client/superPrecioApi.ts:172-179 (helper)API client method that makes the HTTP request to fetch shopping lists from the backend API, used by the tool handler.async getShoppingLists(params?: { userId?: number }): Promise<any> { try { const response = await this.client.get('/api/lists', { params }); return response.data; } catch (error) { throw this.handleError(error); } }