get_items_by_category
Retrieve all menu items from a specified category to quickly access and organize coffee shop offerings by type.
Instructions
Get all menu items from a specific category
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | The category name to filter by |
Implementation Reference
- server.js:1068-1090 (handler)The main handler function that fetches the menu data, filters items by the given category (case-insensitive), and returns a structured JSON response with the category name, item count, and matching items.async getItemsByCategory(category) { const menuData = await this.fetchMenuData(); const categoryItems = menuData.items.filter( item => item.category.toLowerCase() === category.toLowerCase() ); return { content: [ { type: 'text', text: JSON.stringify( { category, itemCount: categoryItems.length, items: categoryItems, }, null, 2 ), }, ], }; }
- server.js:76-85 (schema)Defines the input schema for the tool, specifying that a 'category' string parameter is required.inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'The category name to filter by', }, }, required: ['category'], },
- server.js:73-86 (registration)Registers the tool in the MCP ListToolsRequestSchema response, including name, description, and input schema.{ name: 'get_items_by_category', description: 'Get all menu items from a specific category', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'The category name to filter by', }, }, required: ['category'], }, },
- server.js:109-110 (registration)Dispatches calls to the getItemsByCategory handler in the MCP CallToolRequestSchema switch statement.case 'get_items_by_category': return await this.getItemsByCategory(args.category);
- server.js:183-192 (registration)Registers an HTTP REST API endpoint (/api/menu/category/:category) that calls the getItemsByCategory handler and returns JSON.this.app.get('/api/menu/category/:category', async (req, res) => { try { const { category } = req.params; const result = await this.getItemsByCategory(category); const categoryData = JSON.parse(result.content[0].text); res.json(categoryData); } catch (error) { res.status(500).json({ error: error.message }); } });