mcp-grocy 2.2.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +125 -32
  3. package/build/resources/CHANGELOG.md +47 -0
  4. package/build/resources/DOCS.md +8 -3
  5. package/build/resources/README.md +125 -32
  6. package/build/resources/api-reference.md +88 -88
  7. package/build/resources/config.md +45 -17
  8. package/build/resources/examples.md +120 -221
  9. package/build/resources/installation.md +9 -14
  10. package/build/resources/response-format.md +29 -20
  11. package/build/version.js +2 -2
  12. package/package.json +50 -24
  13. package/build/api/client.js +0 -121
  14. package/build/config/index.js +0 -205
  15. package/build/main.js +0 -44
  16. package/build/server/http-server.js +0 -218
  17. package/build/server/mcp-server.js +0 -163
  18. package/build/server/resources.js +0 -60
  19. package/build/tools/base.js +0 -141
  20. package/build/tools/household/definitions.js +0 -157
  21. package/build/tools/household/handlers.js +0 -109
  22. package/build/tools/household/index.js +0 -25
  23. package/build/tools/index.js +0 -2
  24. package/build/tools/inventory/definitions.js +0 -379
  25. package/build/tools/inventory/handlers.js +0 -430
  26. package/build/tools/inventory/index.js +0 -32
  27. package/build/tools/module-loader.js +0 -151
  28. package/build/tools/recipes/definitions.js +0 -261
  29. package/build/tools/recipes/handlers.js +0 -471
  30. package/build/tools/recipes/index.js +0 -33
  31. package/build/tools/recipes/validations.js +0 -23
  32. package/build/tools/shopping/definitions.js +0 -71
  33. package/build/tools/shopping/handlers.js +0 -43
  34. package/build/tools/shopping/index.js +0 -14
  35. package/build/tools/system/definitions.js +0 -86
  36. package/build/tools/system/handlers.js +0 -94
  37. package/build/tools/system/index.js +0 -16
  38. package/build/tools/types.js +0 -1
  39. package/build/tools/validation-helpers.js +0 -36
  40. package/build/types/index.js +0 -62
  41. package/build/utils/errors.js +0 -138
  42. package/build/utils/logger.js +0 -141
@@ -1,471 +0,0 @@
1
- /**
2
- * Simplified recipe tool handlers
3
- * Demonstrates the new simplified pattern
4
- */
5
- import { BaseToolHandler } from '../base.js';
6
- import { InventoryToolHandlers } from '../inventory/handlers.js';
7
- export class RecipeToolHandlers extends BaseToolHandler {
8
- inventoryHandlers = new InventoryToolHandlers();
9
- /**
10
- * Helper method to get meal plan for multiple days
11
- */
12
- async getMealPlanForDays(dates) {
13
- const allResults = [];
14
- for (const date of dates) {
15
- const dayString = date.toISOString().split('T')[0];
16
- const dayResult = await this.apiCall(`/objects/meal_plan`, 'GET', undefined, {
17
- queryParams: {
18
- 'query[]': `day=${dayString}`,
19
- order: 'day'
20
- }
21
- });
22
- if (Array.isArray(dayResult)) {
23
- allResults.push(...dayResult);
24
- }
25
- }
26
- return allResults;
27
- }
28
- /**
29
- * Get recipes with specified fields
30
- */
31
- getRecipes = async (args) => {
32
- return this.executeToolHandler(async () => {
33
- const { fields } = args || {};
34
- // Validate required parameters
35
- this.validateRequired({ fields }, ['fields']);
36
- const fieldList = this.parseArrayParam(fields, 'fields');
37
- // Fetch recipes
38
- const recipes = await this.apiCall('/objects/recipes', 'GET', undefined, {
39
- queryParams: { 'query[]': 'type=normal' }
40
- });
41
- if (!Array.isArray(recipes)) {
42
- return this.createSuccess([]);
43
- }
44
- // Filter to requested fields
45
- const filteredRecipes = this.filterFields(recipes, fieldList);
46
- return this.createSuccess(filteredRecipes);
47
- });
48
- };
49
- /**
50
- * Get recipe by ID
51
- */
52
- getRecipeById = async (args) => {
53
- return this.executeToolHandler(async () => {
54
- const { recipeId } = args || {};
55
- this.validateRequired({ recipeId }, ['recipeId']);
56
- const id = this.parseNumberParam(recipeId, 'recipeId');
57
- const recipe = await this.apiCall(`/objects/recipes/${id}`);
58
- return this.createSuccess(recipe);
59
- });
60
- };
61
- /**
62
- * Get recipe fulfillment information
63
- */
64
- getRecipeFulfillment = async (args) => {
65
- return this.executeToolHandler(async () => {
66
- const { recipeId } = args || {};
67
- this.validateRequired({ recipeId }, ['recipeId']);
68
- const id = this.parseNumberParam(recipeId, 'recipeId');
69
- const fulfillment = await this.apiCall(`/recipes/${id}/fulfillment`);
70
- return this.createSuccess(fulfillment);
71
- });
72
- };
73
- /**
74
- * Add recipe to meal plan
75
- */
76
- addRecipeToMealPlan = async (args) => {
77
- return this.executeToolHandler(async () => {
78
- const { recipeId, day, mealType } = args || {};
79
- this.validateRequired({ recipeId, day }, ['recipeId', 'day']);
80
- const id = this.parseNumberParam(recipeId, 'recipeId');
81
- const mealPlanData = {
82
- day,
83
- type: mealType || 'lunch',
84
- recipe_id: id
85
- };
86
- const result = await this.apiCall('/objects/meal_plan', 'POST', mealPlanData);
87
- return this.createSuccess(result, 'Recipe added to meal plan successfully');
88
- });
89
- };
90
- /**
91
- * Cook recipe - consume ingredients from stock
92
- */
93
- cookRecipe = async (args) => {
94
- return this.executeToolHandler(async () => {
95
- const { recipeId, servings } = args || {};
96
- this.validateRequired({ recipeId }, ['recipeId']);
97
- const id = this.parseNumberParam(recipeId, 'recipeId');
98
- const servingCount = this.parseNumberParam(servings, 'servings', false) || 1;
99
- // Get recipe details first
100
- const recipe = await this.apiCall(`/objects/recipes/${id}`);
101
- // Cook the recipe
102
- const cookData = {
103
- recipe_id: id,
104
- servings: servingCount
105
- };
106
- const result = await this.apiCall('/recipes/cook', 'POST', cookData);
107
- return this.createSuccess({
108
- recipe: recipe.name,
109
- servings: servingCount,
110
- result
111
- }, `Recipe "${recipe.name}" cooked successfully`);
112
- });
113
- };
114
- /**
115
- * Get recipe nutrition information
116
- */
117
- getRecipeNutrition = async (args) => {
118
- return this.executeToolHandler(async () => {
119
- const { recipeId } = args || {};
120
- this.validateRequired({ recipeId }, ['recipeId']);
121
- const id = this.parseNumberParam(recipeId, 'recipeId');
122
- const nutrition = await this.apiCall(`/recipes/${id}/nutrition`);
123
- return this.createSuccess(nutrition);
124
- });
125
- };
126
- /**
127
- * Search recipes by name or ingredients
128
- */
129
- searchRecipes = async (args) => {
130
- return this.executeToolHandler(async () => {
131
- const { query, fields } = args || {};
132
- this.validateRequired({ query }, ['query']);
133
- const fieldList = this.parseArrayParam(fields || ['id', 'name'], 'fields');
134
- // Get all recipes and filter locally
135
- // Note: This could be optimized with server-side search if Grocy supports it
136
- const recipes = await this.apiCall('/objects/recipes', 'GET', undefined, {
137
- queryParams: { 'query[]': 'type=normal' }
138
- });
139
- if (!Array.isArray(recipes)) {
140
- return this.createSuccess([]);
141
- }
142
- const searchTerm = query.toLowerCase();
143
- const filtered = recipes.filter((recipe) => recipe.name?.toLowerCase().includes(searchTerm) ||
144
- recipe.description?.toLowerCase().includes(searchTerm));
145
- const result = this.filterFields(filtered, fieldList);
146
- return this.createSuccess(result);
147
- });
148
- };
149
- // ==================== MEAL PLANNING METHODS ====================
150
- /**
151
- * Get meal plan data with context
152
- */
153
- getMealPlan = async (args) => {
154
- return this.executeToolHandler(async () => {
155
- const { date, weekly } = args || {};
156
- // Date parameter is mandatory
157
- this.validateRequired({ date }, ['date']);
158
- const targetDate = new Date(date);
159
- if (isNaN(targetDate.getTime())) {
160
- throw new Error('Invalid date format. Use YYYY-MM-DD.');
161
- }
162
- const datesToQuery = [];
163
- if (weekly) {
164
- // For weekly view, get the start of the week (Monday)
165
- const dayOfWeek = targetDate.getDay();
166
- const mondayOffset = dayOfWeek === 0 ? -6 : 1 - dayOfWeek;
167
- const startDate = new Date(targetDate);
168
- startDate.setDate(targetDate.getDate() + mondayOffset);
169
- // Get all 7 days of the week with ±1 day buffer for timezone issues
170
- for (let i = -1; i <= 7; i++) {
171
- const day = new Date(startDate);
172
- day.setDate(startDate.getDate() + i);
173
- datesToQuery.push(day);
174
- }
175
- }
176
- else {
177
- // Get the specific date with ±1 day buffer for timezone issues
178
- const dayBefore = new Date(targetDate);
179
- dayBefore.setDate(targetDate.getDate() - 1);
180
- const dayAfter = new Date(targetDate);
181
- dayAfter.setDate(targetDate.getDate() + 1);
182
- datesToQuery.push(dayBefore, targetDate, dayAfter);
183
- }
184
- const result = await this.getMealPlanForDays(datesToQuery);
185
- if (result.length === 0) {
186
- return this.createSuccess({
187
- message: weekly ? 'No meals planned for the requested week' : 'No meals planned for the requested date',
188
- meal_plan_by_date: {}
189
- }, 'Meal plan retrieved successfully');
190
- }
191
- // Extract unique recipe IDs
192
- const recipeIds = [...new Set(result.map(entry => entry.recipe_id).filter(id => id))];
193
- // Fetch recipe details and all sections in parallel
194
- const [recipeDetails, allSections] = await Promise.all([
195
- Promise.all(recipeIds.map(recipeId => this.apiCall(`/objects/recipes/${recipeId}`))),
196
- this.apiCall('/objects/meal_plan_sections')
197
- ]);
198
- // Simplify meal plan entries - don't merge recipe/section details
199
- const simplifiedMealPlanByDate = {};
200
- result.forEach(entry => {
201
- const entryDate = entry.day;
202
- if (!simplifiedMealPlanByDate[entryDate]) {
203
- simplifiedMealPlanByDate[entryDate] = [];
204
- }
205
- simplifiedMealPlanByDate[entryDate].push({
206
- id: entry.id,
207
- day: entry.day,
208
- section_id: entry.section_id,
209
- recipe_id: entry.recipe_id,
210
- recipe_servings: entry.recipe_servings,
211
- note: entry.note,
212
- done: entry.done
213
- });
214
- });
215
- return this.createSuccess({
216
- meal_plan_by_date: simplifiedMealPlanByDate,
217
- recipes: recipeDetails.map((recipe) => ({
218
- id: recipe.id,
219
- name: recipe.name,
220
- product_id: recipe.product_id,
221
- })),
222
- sections: Array.isArray(allSections) ? allSections.map((section) => ({
223
- id: section.id,
224
- name: section.name,
225
- time_info: section.time_info
226
- })) : []
227
- }, 'Meal plan retrieved successfully');
228
- });
229
- };
230
- /**
231
- * Get meal plan sections
232
- */
233
- getMealPlanSections = async () => {
234
- return this.executeToolHandler(async () => {
235
- const result = await this.apiCall('/objects/meal_plan_sections');
236
- return this.createSuccess(result, 'Meal plan sections retrieved successfully');
237
- });
238
- };
239
- /**
240
- * Delete recipe from meal plan
241
- */
242
- deleteRecipeFromMealPlan = async (args) => {
243
- return this.executeToolHandler(async () => {
244
- const { mealPlanEntryId } = args || {};
245
- this.validateRequired({ mealPlanEntryId }, ['mealPlanEntryId']);
246
- const result = await this.apiCall(`/objects/meal_plan/${mealPlanEntryId}`, 'DELETE');
247
- return this.createSuccess(result, 'Recipe deleted from meal plan successfully');
248
- });
249
- };
250
- // ==================== RECIPE CREATION ====================
251
- /**
252
- * Create a new recipe
253
- */
254
- printRecipeLabel = async (args) => {
255
- return this.executeToolHandler(async () => {
256
- const { recipeId } = args || {};
257
- this.validateRequired({ recipeId }, ['recipeId']);
258
- const result = await this.apiCall(`/recipes/${recipeId}/printlabel`);
259
- return this.createSuccess(result, 'Recipe label printed successfully');
260
- });
261
- };
262
- createRecipe = async (args) => {
263
- return this.executeToolHandler(async () => {
264
- const { name, description, baseServings, instructions } = args || {};
265
- this.validateRequired({ name }, ['name']);
266
- const recipeData = {
267
- name,
268
- description: description || '',
269
- base_servings: baseServings || 1,
270
- type: 'normal',
271
- instructions: instructions || ''
272
- };
273
- const result = await this.apiCall('/objects/recipes', 'POST', recipeData);
274
- return this.createSuccess(result, `Recipe "${name}" created successfully`);
275
- });
276
- };
277
- // ==================== RECIPE FULFILLMENT ====================
278
- /**
279
- * Get fulfillment status for all recipes
280
- */
281
- getAllRecipeFulfillment = async () => {
282
- return this.executeToolHandler(async () => {
283
- const fulfillment = await this.apiCall('/recipes/fulfillment');
284
- return this.createSuccess(fulfillment);
285
- });
286
- };
287
- // ==================== RECIPE CONSUMPTION ====================
288
- /**
289
- * Consume/cook a recipe (simple version)
290
- */
291
- consumeRecipe = async (args) => {
292
- return this.executeToolHandler(async () => {
293
- const { recipeId, servings } = args || {};
294
- this.validateRequired({ recipeId }, ['recipeId']);
295
- const id = this.parseNumberParam(recipeId, 'recipeId');
296
- const servingCount = this.parseNumberParam(servings, 'servings', false) || 1;
297
- const consumeData = {
298
- recipe_id: id,
299
- servings: servingCount
300
- };
301
- const result = await this.apiCall('/recipes/consume', 'POST', consumeData);
302
- return this.createSuccess(result, `Recipe consumed (${servingCount} servings)`);
303
- });
304
- };
305
- // ==================== RECIPE SHOPPING INTEGRATION ====================
306
- /**
307
- * Add all products from a recipe to shopping list
308
- */
309
- addAllProductsToShopping = async (args) => {
310
- return this.executeToolHandler(async () => {
311
- const { recipeId } = args || {};
312
- this.validateRequired({ recipeId }, ['recipeId']);
313
- const id = this.parseNumberParam(recipeId, 'recipeId');
314
- const result = await this.apiCall(`/recipes/${id}/add-all-ingredients-to-shopping-list`, 'POST');
315
- return this.createSuccess(result, 'All recipe products added to shopping list');
316
- });
317
- };
318
- /**
319
- * Add missing products from a recipe to shopping list
320
- */
321
- addMissingProductsToShopping = async (args) => {
322
- return this.executeToolHandler(async () => {
323
- const { recipeId } = args || {};
324
- this.validateRequired({ recipeId }, ['recipeId']);
325
- const id = this.parseNumberParam(recipeId, 'recipeId');
326
- const result = await this.apiCall(`/recipes/${id}/add-not-fulfilled-products-to-shopping-list`, 'POST');
327
- return this.createSuccess(result, 'Missing recipe products added to shopping list');
328
- });
329
- };
330
- // ==================== COOKING METHODS ====================
331
- /**
332
- * Mark recipe from meal plan entry as cooked - modernized version
333
- */
334
- cookedSomething = async (args) => {
335
- return this.executeToolHandler(async () => {
336
- const { mealPlanEntryId, recipeId, stockAmounts } = args || {};
337
- // Get configuration from unified config
338
- const { config } = await import('../../config/index.js');
339
- const { toolSubConfigs } = config.parseToolConfiguration();
340
- const subConfigs = toolSubConfigs?.get('complete');
341
- const allowMealPlanEntryAlreadyDone = subConfigs?.get('allow_meal_plan_entry_already_done') ?? false;
342
- const printLabels = subConfigs?.get('print_labels') ?? true;
343
- const allowNoMealPlan = subConfigs?.get('allow_no_meal_plan') ?? false;
344
- // Validate parameters based on configuration
345
- if (!allowNoMealPlan && !mealPlanEntryId) {
346
- throw new Error('mealPlanEntryId is required when allow_no_meal_plan is false.');
347
- }
348
- if (allowNoMealPlan && !recipeId) {
349
- throw new Error('recipeId is required when allow_no_meal_plan is true.');
350
- }
351
- if (allowNoMealPlan && mealPlanEntryId) {
352
- throw new Error('mealPlanEntryId should not be provided when allow_no_meal_plan is true. Use recipeId instead.');
353
- }
354
- this.validateRequired({ stockAmounts }, ['stockAmounts']);
355
- if (!Array.isArray(stockAmounts) || stockAmounts.length === 0) {
356
- throw new Error('stockAmounts must be a non-empty array of serving amounts.');
357
- }
358
- // Validate all stock amounts are positive numbers
359
- for (let i = 0; i < stockAmounts.length; i++) {
360
- const amount = stockAmounts[i];
361
- if (typeof amount !== 'number' || amount <= 0) {
362
- throw new Error(`stockAmounts[${i}] must be a positive number, got: ${amount}`);
363
- }
364
- }
365
- const completedSteps = [];
366
- let actualRecipeId;
367
- let totalServings;
368
- let mealPlanDate;
369
- let mealplanShadow;
370
- if (allowNoMealPlan) {
371
- // Direct recipe mode - no meal plan entry involved
372
- actualRecipeId = recipeId;
373
- totalServings = stockAmounts.reduce((sum, amount) => sum + amount, 0);
374
- mealPlanDate = new Date().toISOString().split('T')[0];
375
- mealplanShadow = `${mealPlanDate}#direct-recipe-${actualRecipeId}`;
376
- completedSteps.push('Using direct recipe mode (no meal plan entry)');
377
- }
378
- else {
379
- // Meal plan mode - traditional workflow
380
- const mealPlanEntry = await this.apiCall(`/objects/meal_plan/${mealPlanEntryId}`);
381
- if (!mealPlanEntry) {
382
- throw new Error(`Meal plan entry ${mealPlanEntryId} not found.`);
383
- }
384
- if (mealPlanEntry.done == 1 && !allowMealPlanEntryAlreadyDone) {
385
- throw new Error(`Meal plan entry ${mealPlanEntryId} is already marked as done. Cannot mark as cooked again.`);
386
- }
387
- actualRecipeId = mealPlanEntry.recipe_id;
388
- totalServings = stockAmounts.reduce((sum, amount) => sum + amount, 0);
389
- mealPlanDate = mealPlanEntry.day || new Date().toISOString().split('T')[0];
390
- mealplanShadow = `${mealPlanDate}#${mealPlanEntryId}`;
391
- // Mark the meal plan entry as done and update recipe_servings
392
- await this.apiCall(`/objects/meal_plan/${mealPlanEntryId}`, 'PUT', {
393
- done: 1,
394
- recipe_servings: totalServings
395
- });
396
- completedSteps.push('Meal plan entry marked as done');
397
- }
398
- // Consume recipe ingredients
399
- if (allowNoMealPlan) {
400
- // Direct consumption using the recipe ID
401
- await this.apiCall(`/recipes/${actualRecipeId}/consume`, 'POST');
402
- completedSteps.push('Recipe consumed directly');
403
- }
404
- else {
405
- // Query for the mealplan shadow recipe by name
406
- const shadowRecipes = await this.apiCall('/objects/recipes', 'GET', undefined, {
407
- queryParams: { 'query[]': `name=${mealplanShadow}` }
408
- });
409
- if (!Array.isArray(shadowRecipes) || shadowRecipes.length === 0) {
410
- throw new Error(`Mealplan shadow recipe '${mealplanShadow}' not found. Cannot consume ingredients.`);
411
- }
412
- const shadowRecipeId = shadowRecipes[0].id;
413
- // Consume ingredients using the shadow recipe ID
414
- await this.apiCall(`/recipes/${shadowRecipeId}/consume`, 'POST');
415
- completedSteps.push('Recipe consumed via meal plan entry');
416
- }
417
- // Handle stock entry splitting and label printing
418
- let stockEntries = { splitEntries: [], labelsPrinted: 0 };
419
- const recipe = await this.apiCall(`/objects/recipes/${actualRecipeId}`);
420
- if (recipe && recipe.product_id) {
421
- // Get product details and most recent stock entry
422
- const [product, entries] = await Promise.all([
423
- this.apiCall(`/objects/products/${recipe.product_id}`),
424
- this.apiCall(`/stock/products/${recipe.product_id}/entries`, 'GET', undefined, {
425
- queryParams: { order: 'row_created_timestamp:desc', limit: '1' }
426
- })
427
- ]);
428
- // Get quantity unit info
429
- let quantityUnit = null;
430
- if (product.qu_id_stock) {
431
- try {
432
- quantityUnit = await this.apiCall(`/objects/quantity_units/${product.qu_id_stock}`);
433
- }
434
- catch (error) {
435
- console.warn('Failed to fetch quantity unit:', error);
436
- }
437
- }
438
- // Helper function to get correct unit form
439
- const getUnitForm = (amount) => {
440
- if (!quantityUnit || !quantityUnit.name)
441
- return '';
442
- if (amount === 1)
443
- return quantityUnit.name;
444
- return quantityUnit.name_plural || quantityUnit.name;
445
- };
446
- if (Array.isArray(entries) && entries.length > 0) {
447
- const originalEntry = entries[0];
448
- // Use the real stock splitting functionality
449
- stockEntries.splitEntries = await this.inventoryHandlers.splitStockEntry(originalEntry, stockAmounts, getUnitForm);
450
- // Print labels for all entries (if enabled)
451
- if (printLabels) {
452
- for (const entry of stockEntries.splitEntries) {
453
- try {
454
- await this.apiCall(`/stock/entry/${originalEntry.id}/printlabel`);
455
- stockEntries.labelsPrinted++;
456
- }
457
- catch (error) {
458
- console.error(`Failed to print label for stock entry ${entry.stockId}:`, error);
459
- }
460
- }
461
- }
462
- }
463
- }
464
- return this.createSuccess({
465
- message: `Recipe ${actualRecipeId} cooked (${totalServings} servings consumed, ${stockEntries.splitEntries.length} stock entries created, ${stockEntries.labelsPrinted} labels printed)`,
466
- stockEntries,
467
- completedSteps
468
- });
469
- });
470
- };
471
- }
@@ -1,33 +0,0 @@
1
- import { recipeToolDefinitions } from './definitions.js';
2
- import { RecipeToolHandlers } from './handlers.js';
3
- import { validateCompleteSubConfigs } from './validations.js';
4
- // Use simplified handlers
5
- const handlers = new RecipeToolHandlers();
6
- export const recipeModule = {
7
- definitions: recipeToolDefinitions,
8
- handlers: {
9
- // Recipe Management
10
- recipes_management_get: handlers.getRecipes,
11
- recipes_management_get_by_id: handlers.getRecipeById,
12
- recipes_management_create: handlers.createRecipe,
13
- recipes_management_print_label: handlers.printRecipeLabel,
14
- // Recipe Fulfillment
15
- recipes_fulfillment_get: handlers.getRecipeFulfillment,
16
- recipes_fulfillment_get_all: handlers.getAllRecipeFulfillment,
17
- // Meal Planning
18
- recipes_mealplan_get: handlers.getMealPlan,
19
- recipes_mealplan_get_sections: handlers.getMealPlanSections,
20
- recipes_mealplan_add_recipe: handlers.addRecipeToMealPlan,
21
- recipes_mealplan_delete_entry: handlers.deleteRecipeFromMealPlan,
22
- // Recipe Cooking
23
- recipes_cooking_consume: handlers.consumeRecipe,
24
- recipes_cooking_complete: handlers.cookedSomething,
25
- // Shopping Integration
26
- recipes_shopping_add_all_products: handlers.addAllProductsToShopping,
27
- recipes_shopping_add_missing_products: handlers.addMissingProductsToShopping
28
- },
29
- validators: {
30
- recipes_cooking_complete: validateCompleteSubConfigs
31
- }
32
- };
33
- export * from './definitions.js';
@@ -1,23 +0,0 @@
1
- /**
2
- * Recipe tools sub-configuration validation functions
3
- */
4
- import { ValidationHelpers } from '../validation-helpers.js';
5
- /**
6
- * Validation function for complete tool sub-configurations
7
- */
8
- export const validateCompleteSubConfigs = (subConfigs) => {
9
- const allowMealPlanEntryAlreadyDone = subConfigs.get('allow_meal_plan_entry_already_done');
10
- const allowNoMealPlan = subConfigs.get('allow_no_meal_plan');
11
- const printLabels = subConfigs.get('print_labels');
12
- // Validate types
13
- ValidationHelpers.validateBoolean(allowMealPlanEntryAlreadyDone, 'allow_meal_plan_entry_already_done');
14
- ValidationHelpers.validateBoolean(allowNoMealPlan, 'allow_no_meal_plan');
15
- ValidationHelpers.validateBoolean(printLabels, 'print_labels');
16
- // Business logic validation
17
- if (allowNoMealPlan && allowMealPlanEntryAlreadyDone) {
18
- throw new Error('allow_no_meal_plan and allow_meal_plan_entry_already_done cannot both be true - they are mutually exclusive modes');
19
- }
20
- // Check for unknown options
21
- const knownOptions = new Set(['allow_meal_plan_entry_already_done', 'allow_no_meal_plan', 'print_labels', 'ack_token']);
22
- ValidationHelpers.validateKnownOptions(subConfigs, knownOptions, 'complete');
23
- };
@@ -1,71 +0,0 @@
1
- export const shoppingToolDefinitions = [
2
- {
3
- name: 'shopping_list_get',
4
- description: '[SHOPPING/LIST] Get your current shopping list items.',
5
- inputSchema: {
6
- type: 'object',
7
- properties: {},
8
- required: []
9
- }
10
- },
11
- {
12
- name: 'shopping_list_add_item',
13
- description: '[SHOPPING/LIST] Add an item to your shopping list. Use inventory_products_get first to find the product ID you want to add.',
14
- inputSchema: {
15
- type: 'object',
16
- properties: {
17
- productId: {
18
- type: 'number',
19
- description: 'ID of the product to add. Use inventory_products_get tool to find the correct product ID by searching for the product name in the results.'
20
- },
21
- amount: {
22
- type: 'number',
23
- description: 'Amount to add to shopping list in the product\'s stock unit (e.g., 2 pieces, 1.5 kg, 750 ml). Ensure you know the product\'s unit before specifying amount. Default: 1',
24
- default: 1
25
- },
26
- shoppingListId: {
27
- type: 'number',
28
- description: 'ID of the shopping list to add to (default: 1). Most users have only one shopping list with ID 1.',
29
- default: 1
30
- },
31
- note: {
32
- type: 'string',
33
- description: 'Optional note for the shopping list item'
34
- }
35
- },
36
- required: ['productId']
37
- }
38
- },
39
- {
40
- name: 'shopping_list_remove_item',
41
- description: '[SHOPPING/LIST] Remove an item from your shopping list. Use shopping_list_get first to find the shopping list item ID.',
42
- inputSchema: {
43
- type: 'object',
44
- properties: {
45
- shoppingListItemId: {
46
- type: 'number',
47
- description: 'ID of the shopping list item to remove. Use shopping_list_get tool to find the correct shopping list item ID by looking at the "id" field in the results.'
48
- }
49
- },
50
- required: ['shoppingListItemId']
51
- }
52
- },
53
- {
54
- name: 'shopping_locations_get',
55
- description: '[SHOPPING/LOCATIONS] Get all shopping locations (stores) from your Grocy instance. Use this to find store IDs and names when working with tools that require storeId parameters.',
56
- inputSchema: {
57
- type: 'object',
58
- properties: {},
59
- required: []
60
- }
61
- },
62
- {
63
- name: 'shopping_list_print_thermal',
64
- description: '[SHOPPING/PRINTING] Print the shopping list with a thermal printer. This creates a physical shopping list for store visits.',
65
- inputSchema: {
66
- type: 'object',
67
- properties: {},
68
- required: []
69
- }
70
- }
71
- ];
@@ -1,43 +0,0 @@
1
- import { BaseToolHandler } from '../base.js';
2
- export class ShoppingToolHandlers extends BaseToolHandler {
3
- getShoppingList = async () => {
4
- return this.executeToolHandler(async () => {
5
- const result = await this.apiCall('/objects/shopping_list');
6
- return this.createSuccess(result, 'Shopping list retrieved successfully');
7
- });
8
- };
9
- addShoppingListItem = async (args) => {
10
- return this.executeToolHandler(async () => {
11
- const { productId, amount = 1, shoppingListId = 1, note = '' } = args || {};
12
- this.validateRequired({ productId }, ['productId']);
13
- const body = {
14
- product_id: productId,
15
- amount,
16
- shopping_list_id: shoppingListId,
17
- note
18
- };
19
- const result = await this.apiCall('/objects/shopping_list', 'POST', body);
20
- return this.createSuccess(result, 'Shopping list item added successfully');
21
- });
22
- };
23
- removeShoppingListItem = async (args) => {
24
- return this.executeToolHandler(async () => {
25
- const { shoppingListItemId } = args || {};
26
- this.validateRequired({ shoppingListItemId }, ['shoppingListItemId']);
27
- const result = await this.apiCall(`/objects/shopping_list/${shoppingListItemId}`, 'DELETE');
28
- return this.createSuccess(result, 'Shopping list item removed successfully');
29
- });
30
- };
31
- getShoppingLocations = async () => {
32
- return this.executeToolHandler(async () => {
33
- const result = await this.apiCall('/objects/shopping_locations');
34
- return this.createSuccess(result, 'Shopping locations retrieved successfully');
35
- });
36
- };
37
- printShoppingListThermal = async () => {
38
- return this.executeToolHandler(async () => {
39
- const result = await this.apiCall('/print/shoppinglist/thermal');
40
- return this.createSuccess(result, 'Shopping list sent to thermal printer successfully');
41
- });
42
- };
43
- }
@@ -1,14 +0,0 @@
1
- import { shoppingToolDefinitions } from './definitions.js';
2
- import { ShoppingToolHandlers } from './handlers.js';
3
- const handlers = new ShoppingToolHandlers();
4
- export const shoppingModule = {
5
- definitions: shoppingToolDefinitions,
6
- handlers: {
7
- shopping_list_get: handlers.getShoppingList,
8
- shopping_list_add_item: handlers.addShoppingListItem,
9
- shopping_list_remove_item: handlers.removeShoppingListItem,
10
- shopping_locations_get: handlers.getShoppingLocations,
11
- shopping_list_print_thermal: handlers.printShoppingListThermal
12
- }
13
- };
14
- export * from './definitions.js';