mcp_howtocook_getRecipesByCategory
Find recipes by category to solve meal planning challenges. Filter Chinese recipes by food type like seafood, breakfast, meat dishes, or staples to get cooking inspiration.
Instructions
根据分类查询菜谱,可选分类有:
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes | 菜谱分类名称,如水产、早餐、荤菜、主食等 |
Implementation Reference
- src/tools/getRecipesByCategory.ts:14-26 (handler)Handler function that filters the recipes list by the input category, maps each to a simplified version using simplifyRecipe helper, and returns the JSON stringified list in the MCP text content format.async ({ category }: { category: string }) => { const filteredRecipes = recipes.filter((recipe) => recipe.category === category); // 返回简化版的菜谱数据 const simplifiedRecipes = filteredRecipes.map(simplifyRecipe); return { content: [ { type: "text", text: JSON.stringify(simplifiedRecipes, null, 2), }, ], }; }
- Zod schema defining the single input parameter 'category' as an enum of available categories.{ category: z.enum(categories as [string, ...string[]]) .describe('菜谱分类名称,如水产、早餐、荤菜、主食等') },
- src/tools/getRecipesByCategory.ts:7-27 (registration)The server.tool() call within registerGetRecipesByCategoryTool that registers the tool name, dynamic description with categories, input schema, and inline handler on the MCP server.server.tool( "mcp_howtocook_getRecipesByCategory", `根据分类查询菜谱,可选分类有: ${categories.join(', ')}`, { category: z.enum(categories as [string, ...string[]]) .describe('菜谱分类名称,如水产、早餐、荤菜、主食等') }, async ({ category }: { category: string }) => { const filteredRecipes = recipes.filter((recipe) => recipe.category === category); // 返回简化版的菜谱数据 const simplifiedRecipes = filteredRecipes.map(simplifyRecipe); return { content: [ { type: "text", text: JSON.stringify(simplifiedRecipes, null, 2), }, ], }; } );
- src/index.ts:57-57 (registration)Invocation of the registration function during server instance creation, passing the MCP server, loaded recipes data, and derived categories list.registerGetRecipesByCategoryTool(server, recipes, categories);
- src/utils/recipeUtils.ts:4-14 (helper)Helper function simplifyRecipe transforms a full Recipe into SimpleRecipe, selecting id, name, description, and ingredients (name, text_quantity only). Used in the tool handler.export function simplifyRecipe(recipe: Recipe): SimpleRecipe { return { id: recipe.id, name: recipe.name, description: recipe.description, ingredients: recipe.ingredients.map((ingredient: Ingredient) => ({ name: ingredient.name, text_quantity: ingredient.text_quantity })) }; }