---
id: std-20251212-auto-create-foods
depthUsed: standard
timestamp: 2025-12-12T00:00:00Z
executed: true
originalPrompt: "mealie-mcp-typescript If trying to add ingredents that don't have a food in the dB yet, make it so it auto-adds the food."
---
# Improved Prompt
## Objective
Enhance the mealie-mcp-server TypeScript MCP tools to automatically create missing food items when adding recipe ingredients with structured data.
## Context
- Project: mealie-mcp-typescript (MCP server for Mealie recipe management)
- Current state: `create_recipe` and `update_recipe` tools only accept ingredients as plain text strings
- Mealie API supports structured ingredients with `quantity`, `unit` (object), and `food` (object) fields
- Foods API exists at `/api/foods` for CRUD operations on food items
## Requirements
### 1. Add Foods Management Tools
- `get_foods` - List/search existing foods with pagination
- `create_food` - Create a new food item (name required, optional: pluralName, description)
### 2. Update Recipe Tools for Structured Ingredients
Modify `create_recipe` and `update_recipe` to accept structured ingredients:
```typescript
{
quantity?: number, // e.g., 2
unit?: string, // e.g., "cup" - name or ID
food?: string, // e.g., "flour" - name or ID
note?: string // e.g., "sifted"
}
```
### 3. Auto-Create Missing Foods (Core Feature)
When a structured ingredient references a food that doesn't exist:
1. Search for the food by name via `GET /api/foods?search={name}`
2. If not found, automatically create it via `POST /api/foods` with `{ name: foodName }`
3. Use the returned food ID in the ingredient
4. Continue with recipe creation/update
### 4. Backward Compatibility
- Continue supporting plain string ingredients (stored in `note` field)
- Allow mixing structured and string ingredients in same recipe
## Technical Constraints
- Files to modify: `ts/src/tools/recipe.ts`, `ts/src/client.ts`, `ts/src/types/recipe.ts`
- New file: `ts/src/tools/foods.ts`
- Follow existing code patterns and error handling style
## Success Criteria
- Can create recipe with `{ quantity: 2, unit: "cups", food: "chicken broth" }`
- If "chicken broth" doesn't exist, it gets created automatically
- Existing string-based ingredients still work
- Foods tools available for manual food management
## Quality Scores
- **Clarity**: 55%
- **Efficiency**: 70%
- **Structure**: 40%
- **Completeness**: 35%
- **Actionability**: 45%
- **Specificity**: 50%
- **Overall**: 49% (needs-improvement)
## Original Prompt
```
mealie-mcp-typescript If trying to add ingredents that don't have a food in the dB yet, make it so it auto-adds the food.
```