recipe links
This commit is contained in:
@@ -196,6 +196,30 @@ class RecipeAnalysisInput(BaseModel):
|
||||
substitutions: dict[str, str] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class RecipeComponentInput(BaseModel):
|
||||
recipe_id: str
|
||||
servings: Decimal = Field(gt=0, le=Decimal('99999.99'))
|
||||
|
||||
|
||||
class RecipeCompositionInput(BaseModel):
|
||||
title: str = Field(min_length=1, max_length=180)
|
||||
default_servings: Decimal = Field(default=Decimal('2'), gt=0, le=Decimal('99999.99'))
|
||||
components: list[RecipeComponentInput] = Field(min_length=1, max_length=10)
|
||||
|
||||
|
||||
class RecipeLinkInput(BaseModel):
|
||||
recipe_id: str
|
||||
relationship: Literal['goes_well_with', 'try_with', 'alternative_to'] = 'goes_well_with'
|
||||
note: str = Field(default='', max_length=255)
|
||||
reciprocal: bool = True
|
||||
|
||||
|
||||
class RecipeLinkChanges(BaseModel):
|
||||
relationship: Literal['goes_well_with', 'try_with', 'alternative_to'] | None = None
|
||||
note: str | None = Field(default=None, max_length=255)
|
||||
reciprocal: bool | None = None
|
||||
|
||||
|
||||
class GroceryItemInput(BaseModel):
|
||||
name: str
|
||||
quantity: Decimal = Field(gt=0)
|
||||
@@ -539,7 +563,7 @@ def create_server() -> MCPServer:
|
||||
return {'success': False, 'error': item['error']}
|
||||
return {'success': True, 'item': _inventory(item)}
|
||||
|
||||
@server.tool(structured_output=True, description='Preview or update up to 20 owned inventory rows. Uses inventory_update field rules. Partial success is default; atomic=true rolls back all updates if any item fails. Actual execution requires a unique idempotency_key; reuse the same key and payload on retry. Optionally supply expected_updated_at per item to reject concurrent edits.')
|
||||
@server.tool(structured_output=True, description='Preview or update up to 50 owned inventory rows. Uses inventory_update field rules and returns per-item before/after values and counts. Dry run is default and writes nothing. Partial success is default for compatibility; atomic=true rolls back all updates if any item fails. Actual execution requires an idempotency_key; reuse the same key and payload on retry. Supply expected_updated_at per item to reject concurrent edits.')
|
||||
async def inventory_bulk_update(items: list[InventoryBulkUpdateEntry], idempotency_key: str | None = None,
|
||||
dry_run: bool = True, atomic: bool = False) -> dict[str, Any]:
|
||||
if not dry_run and not idempotency_key:
|
||||
@@ -634,6 +658,41 @@ def create_server() -> MCPServer:
|
||||
async def recipe_get(recipe_id: str) -> dict[str, Any]:
|
||||
return await api_request('GET', f'recipes/{recipe_id}/')
|
||||
|
||||
@server.tool(structured_output=True, description='List up to 100 linked recipe suggestions for an owned recipe. Includes incoming suggestions only when the other owner-visible link is reciprocal. Suggestions are not recipe ingredients.')
|
||||
async def recipe_link_list(recipe_id: str) -> dict[str, Any]:
|
||||
return await api_request('GET', f'recipes/{recipe_id}/links/')
|
||||
|
||||
@server.tool(structured_output=True, description='Create a one-way or reciprocal suggestion between two owned recipes. This does not add ingredients or change nutrition. Reuse idempotency_key on retries.')
|
||||
async def recipe_link_create(recipe_id: str, link: RecipeLinkInput,
|
||||
idempotency_key: str | None = None) -> dict[str, Any]:
|
||||
key = _key(idempotency_key)
|
||||
data = await api_request('POST', f'recipes/{recipe_id}/links/',
|
||||
payload=link.model_dump(mode='json'), idempotency_key=key)
|
||||
return {**data, 'idempotency_key': key}
|
||||
|
||||
@server.tool(structured_output=True, description='Edit the relationship, note, or reciprocal visibility of an owned recipe link.')
|
||||
async def recipe_link_update(recipe_id: str, link_id: str,
|
||||
changes: RecipeLinkChanges) -> dict[str, Any]:
|
||||
return await api_request('PATCH', f'recipes/{recipe_id}/links/{link_id}/',
|
||||
payload=changes.model_dump(mode='json', exclude_unset=True))
|
||||
|
||||
@server.tool(structured_output=True, description='Remove an owned suggestion link. The linked recipe remains unchanged.')
|
||||
async def recipe_link_remove(recipe_id: str, link_id: str) -> dict[str, Any]:
|
||||
return await api_request('DELETE', f'recipes/{recipe_id}/links/{link_id}/')
|
||||
|
||||
@server.tool(structured_output=True, description='Preview an explicitly selected set of owned component recipes. Returns ingredient details, nutrition completeness, duplicate ingredient warnings, and issues. Suggestion links are excluded; this does not create a recipe, log a meal, or deduct inventory.')
|
||||
async def recipe_composition_preview(components: list[RecipeComponentInput]) -> dict[str, Any]:
|
||||
return await api_request('POST', 'recipes/compositions/preview/',
|
||||
payload={'components': [item.model_dump(mode='json') for item in components]})
|
||||
|
||||
@server.tool(structured_output=True, description='Create a new draft recipe that explicitly includes selected owned component recipes. Existing source recipes remain intact. This does not log a meal or deduct inventory. Reuse idempotency_key on retries.')
|
||||
async def recipe_composition_create(composition: RecipeCompositionInput,
|
||||
idempotency_key: str | None = None) -> dict[str, Any]:
|
||||
key = _key(idempotency_key)
|
||||
data = await api_request('POST', 'recipes/compositions/',
|
||||
payload=composition.model_dump(mode='json'), idempotency_key=key)
|
||||
return {'recipe': data, 'idempotency_key': key}
|
||||
|
||||
@server.tool(structured_output=True, description='Save one owned recipe to your Cook Later list. Idempotent; does not log a meal or use inventory.')
|
||||
async def recipe_cook_later_add(recipe_id: str) -> dict[str, Any]:
|
||||
return await api_request('POST', 'recipes/cook-later/', payload={'recipe_id': recipe_id})
|
||||
|
||||
Reference in New Issue
Block a user