formlab-mcp 0.6.83 → 0.6.84

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.
package/README.md CHANGED
@@ -30,7 +30,7 @@ Ask Claude (or another MCP client) things like:
30
30
  |---|---|
31
31
  | `list_formulations` | Filtered list of recipes, each with exact `batchCount` / `sampleCount` / `testReportCount`; `sort` (`batches`, `samples`, `test_reports`, `name`, `updated`) ranks every match before the limit — "which formulas have the most batch runs?" in one call |
32
32
  | `get_formulation` | Full record (incl. `versionLabel`, the label the user types, e.g. 1.0) + **version history** (`versionHistory`: one snapshot per save, v1, v2…, newest first, with the label each save had and its note) + flattened wt-% composition (sub-formulas expanded), the ordered **step procedure**, user **custom fields**, any **process-factor values** (DOE inputs — cure temp, mix time, RPM, pH…), the declared **finishedDensity** (g/mL of the mixed product; volume-targeted batches scale by it), and its **theoretical parameters computed** the way the app's Params tab does (Energy kcal/100g, NV %, Cost/kg…: value, unit, formula, spec pass/fail, and a `warning` when ingredients lack a value or carry mixed units) — the app's own engine, vendored in `mcp/vendor/` and run in an isolated `node:vm` context |
33
- | `get_nutrition_label` | The formula's **Label** tab (Pro, live workspace only): US Nutrition Facts lines per serving with FDA rounding and % Daily Value, the per-container column, whether the simplified format applies, the EU declaration (kJ / kcal, salt), the ingredient statement with its Contains line, and which ingredients are missing nutrition data. |
33
+ | `get_nutrition_label` | The formula's **Label** tab (Pro, live workspace only): US Nutrition Facts lines per serving with FDA rounding and % Daily Value, the per-container column, whether the simplified format applies, the EU declaration (kJ / kcal, salt) and EU ingredient list with allergens in capitals, the ingredient statement with its Contains line, and which ingredients are missing nutrition data. |
34
34
  | `find_similar_formulations` | Find formulas using a given ingredient ≥ threshold % |
35
35
  | `compare_formulations` | Pairwise side-by-side composition diff |
36
36
  | `list_ingredients` | Filtered list of raw materials. Filters: `family`, `supplier`, `name_contains`, `in_stock_only`, `ingredient_class` (small-molecule / surfactant / polymer / extract / fragrance / pigment / sequence / mixture), `sequence_contains` (e.g. `KTTKS` → Matrixyl), `taxon_contains` (e.g. `Centella`) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.83",
3
+ "version": "0.6.84",
4
4
  "mcpName": "io.github.juliu1980/formlab-mcp",
5
5
  "description": "Read-only Model Context Protocol server for FormLab. Lets Claude and other MCP clients read and analyze your FormLab data, from a local export file or your live cloud workspace.",
6
6
  "homepage": "https://formvix.com/mcp",
package/server.json CHANGED
@@ -2,13 +2,13 @@
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "io.github.juliu1980/formlab-mcp",
4
4
  "description": "Read-only MCP server for FormLab formulation data: a local export file or your live cloud workspace.",
5
- "version": "0.6.83",
5
+ "version": "0.6.84",
6
6
  "websiteUrl": "https://formvix.com/mcp",
7
7
  "packages": [
8
8
  {
9
9
  "registryType": "npm",
10
10
  "identifier": "formlab-mcp",
11
- "version": "0.6.83",
11
+ "version": "0.6.84",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
package/theoretical.js CHANGED
@@ -45,8 +45,10 @@ const EPILOGUE = `
45
45
  });
46
46
  return JSON.stringify(out);
47
47
  }
48
- // The Label tab's numbers (js/views/nutrition-label.js, 0.6.83). The app's allergen roll-up lives in a file that is not
48
+ // The Label tab's numbers (js/views/nutrition-label.js, 0.6.83; the EU ingredient list 0.6.84). The app's allergen roll-up lives in a file that is not
49
49
  // vendored; this is the same walk over the flattened leaves.
50
+ // The app's HTML escaper (js/utils.js, not vendored): the EU list builds its bold version with it.
51
+ function esc(v) { return String(v == null ? '' : v).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;'); }
50
52
  function rollupFormulaAllergens(f) {
51
53
  var out = new Map();
52
54
  (_flattenComposition(f).rows || []).forEach(function (r) {
@@ -64,7 +66,7 @@ function __nl(id) {
64
66
  var st = _nlSettings(f), sv = flNlServing(f), lines = flNlLines(f, c), sim = flNlSimplified(f, lines), s = flNlStatement(f);
65
67
  var decl = function (ls) { return ls.map(function (l) { return { nutrient: l.label, declared: l.text + ' ' + l.unit, unrounded: +(+l.raw).toPrecision(4), percentDailyValue: l.pct == null ? null : l.pct }; }); };
66
68
  var per100 = {}; FL_NL_NUTRIENTS.forEach(function (n) { per100[n.label + ' (' + n.unit + ')'] = +(+c.per100[n.key]).toPrecision(4); });
67
- var eu = flNlEu(f, c);
69
+ var eu = flNlEu(f, c), eus = flNlEuStatement(f);
68
70
  var strip = function (h) { return String(h).replace(/<[^>]+>/g, ''); };
69
71
  return JSON.stringify({
70
72
  ok: true, region: st.region, format: sim.use,
@@ -75,7 +77,8 @@ function __nl(id) {
75
77
  nutritionFacts: decl(lines),
76
78
  perContainer: sim.servings > 1 ? decl(flNlLines(f, c, sim.servings)) : null,
77
79
  simplified: { eligible: sim.eligible, insignificantNutrients: sim.count, statement: sim.eligible ? strip(_nlNotSource(lines, sim)) : null },
78
- eu: { basis: 'per ' + eu.basis, portion: eu.portion, rows: eu.rows.map(function (r) { return { nutrient: r.label, per: r.per, perPortion: r.portion }; }) },
80
+ eu: { basis: 'per ' + eu.basis, portion: eu.portion, rows: eu.rows.map(function (r) { return { nutrient: r.label, per: r.per, perPortion: r.portion }; }),
81
+ ingredientList: eus.text, allergens: eus.allergens },
79
82
  ingredientStatement: s.text, contains: s.contains,
80
83
  coverage: { ingredients: c.rows, withNutrition: c.withData, noData: c.noData, missing: c.missing, energyFromPartialMacros: c.partial },
81
84
  });
@@ -191,7 +191,7 @@ const get_formulation = {
191
191
  const get_nutrition_label = {
192
192
  definition: {
193
193
  name: 'get_nutrition_label',
194
- description: 'A formulation\'s nutrition label as FormLab\'s Label tab computes it (Pro; live workspace only), from each ingredient\'s per-100 g nutrition fields × the composition (premixes rolled up, units converted). Returns: `serving` (amount in g or mL, its weight in grams, household measure, servings per container, the density used for a mL serving); `cookingYieldPct` when set (numbers are then "as sold" = as mixed ÷ yield); `per100g` unrounded; `nutritionFacts`, the US Nutrition Facts lines per serving with `declared` (FDA rounding, 21 CFR 101.9) and `percentDailyValue`; `perContainer` when servings per container is above 1 (the dual-column second column, rounded from its own total); `simplified` (whether the food qualifies for the simplified format and its "Not a significant source of…" line); `eu`, the EU nutrition declaration per 100 g or 100 ml (kJ and kcal by the EU factors, carbohydrate without fibre, salt = sodium × 2.5) with a per-portion column when a serving is typed; `ingredientStatement` (by weight, 2% or less grouped) and `contains` (major US allergens); `coverage` (which ingredients have no nutrition data, which nutrients are missing on which, where calories came from partial macros). `region` / `format` are what the user chose on the tab. A blank field counts as 0: check `coverage` before calling a nutrient absent. Calculated from ingredient data, not a regulatory review.',
194
+ description: 'A formulation\'s nutrition label as FormLab\'s Label tab computes it (Pro; live workspace only), from each ingredient\'s per-100 g nutrition fields × the composition (premixes rolled up, units converted). Returns: `serving` (amount in g or mL, its weight in grams, household measure, servings per container, the density used for a mL serving); `cookingYieldPct` when set (numbers are then "as sold" = as mixed ÷ yield); `per100g` unrounded; `nutritionFacts`, the US Nutrition Facts lines per serving with `declared` (FDA rounding, 21 CFR 101.9) and `percentDailyValue`; `perContainer` when servings per container is above 1 (the dual-column second column, rounded from its own total); `simplified` (whether the food qualifies for the simplified format and its "Not a significant source of…" line); `eu`, the EU nutrition declaration per 100 g or 100 ml (kJ and kcal by the EU factors, carbohydrate without fibre, salt = sodium × 2.5) with a per-portion column when a serving is typed, plus `eu.ingredientList`, the EU ingredient list (every ingredient by weight, the 14 EU allergens in CAPITALS, added in brackets where the name does not say it) and `eu.allergens`; `ingredientStatement` (by weight, 2% or less grouped) and `contains` (major US allergens); `coverage` (which ingredients have no nutrition data, which nutrients are missing on which, where calories came from partial macros). `region` / `format` are what the user chose on the tab. A blank field counts as 0: check `coverage` before calling a nutrient absent. Calculated from ingredient data, not a regulatory review.',
195
195
  inputSchema: {
196
196
  type: 'object',
197
197
  properties: {
@@ -264,16 +264,58 @@ function flNlEuPanelHtml(f, calc) {
264
264
 
265
265
  // ── Ingredient statement and Contains ───────────────────────
266
266
  // Leaves in descending order by weight; those at 2 % or less may follow "Contains 2% or less of".
267
- function flNlStatement(f) {
267
+ // The formula's leaves, heaviest first: [{ name (label_name when set), w, allergens }]
268
+ function _nlStatementItems(f) {
268
269
  const leaves = (typeof _flattenComposition === 'function') ? _flattenComposition(f).rows : [];
269
270
  const by = new Map();
270
271
  leaves.forEach(r => { if (r.ingredientId && r._weight > 0) by.set(r.ingredientId, (by.get(r.ingredientId) || 0) + r._weight); });
271
- const items = [...by.entries()].map(([id, w]) => {
272
+ return [...by.entries()].map(([id, w]) => {
272
273
  const ing = (db.ingredients || []).find(i => i.id === id);
273
274
  if (!ing) return null;
274
275
  const cf = (ing.customFields || []).find(c => c && /^label[ _]?name$/i.test(String(c.name || '').trim()) && String(c.value || '').trim());
275
- return { name: cf ? String(cf.value).trim() : (ing.name || ''), w };
276
+ return { name: cf ? String(cf.value).trim() : (ing.name || ''), w, allergens: Array.isArray(ing.allergens) ? ing.allergens : [] };
276
277
  }).filter(x => x && x.name).sort((a, b) => b.w - a.w);
278
+ }
279
+
280
+ // ── EU ingredient list: allergens emphasised (Regulation (EU) No 1169/2011, Art. 21 and Annex II; 62c) ──
281
+ // The app's allergen chip → the word the list must show, and the words in an ingredient's own name that already say
282
+ // it. A name that says it gets that word emphasised ("WHEAT flour"); one that doesn't gets it added ("whey protein
283
+ // (MILK)"). On the page the emphasis is bold; in copied text, capitals. Latex is not a food allergen.
284
+ const FL_NL_EU_ALLERGENS = {
285
+ celery: ['celery', /celery|celeriac/i], eggs: ['egg', /eggs?/i], fish: ['fish', /fish/i],
286
+ gluten: ['gluten', /wheat|rye|barley|oats?|spelt|kamut|gluten/i], wheat: ['wheat', /wheat|spelt|durum/i],
287
+ lupin: ['lupin', /lupine?s?/i], milk: ['milk', /milk/i], molluscs: ['molluscs', /mollusc?ks?|oysters?|mussels?|squid|clams?|octopus/i],
288
+ mustard: ['mustard', /mustard/i], peanuts: ['peanuts', /peanuts?/i], sesame: ['sesame', /sesame/i],
289
+ shellfish: ['crustaceans', /crustaceans?|shrimps?|prawns?|crabs?|lobsters?|crayfish/i], soy: ['soya', /soya|soybeans?|soy/i],
290
+ sulfites: ['sulphites', /sulphites?|sulfites?|sul(?:ph|f)ur dioxide|(?:meta)?bisul(?:ph|f)ite/i],
291
+ 'tree-nuts': ['nuts', /almonds?|hazelnuts?|walnuts?|cashews?|pecans?|pistachios?|macadamias?|brazil nuts?|nuts?/i],
292
+ };
293
+ // → { html, text, allergens: [words], count }: every ingredient in descending order by weight.
294
+ function flNlEuStatement(f) {
295
+ const items = _nlStatementItems(f), found = [];
296
+ const one = (it, mark, safe) => {
297
+ const spans = [], add = [];
298
+ it.allergens.forEach(k => {
299
+ const d = FL_NL_EU_ALLERGENS[k];
300
+ if (!d) return;
301
+ if (!found.includes(d[0])) found.push(d[0]);
302
+ const m = new RegExp('\\b(?:' + d[1].source + ')\\b', 'i').exec(it.name);
303
+ if (m) { if (!spans.some(x => m.index < x[1] && m.index + m[0].length > x[0])) spans.push([m.index, m.index + m[0].length]); }
304
+ else if (!add.includes(d[0])) add.push(d[0]);
305
+ });
306
+ spans.sort((a, b) => a[0] - b[0]);
307
+ let out = '', at = 0;
308
+ spans.forEach(([a, b]) => { out += safe(it.name.slice(at, a)) + mark(it.name.slice(a, b)); at = b; });
309
+ out += safe(it.name.slice(at));
310
+ return out + (add.length ? ' (' + add.map(mark).join(', ') + ')' : '');
311
+ };
312
+ const list = (mark, safe) => items.map(it => one(it, mark, safe)).join(', ');
313
+ const html = list(w => `<b>${esc(w)}</b>`, esc), text = list(w => w.toUpperCase(), x => x);
314
+ return { html: html ? html + '.' : '', text: text ? text + '.' : '', allergens: found, count: items.length };
315
+ }
316
+
317
+ function flNlStatement(f) {
318
+ const items = _nlStatementItems(f);
277
319
  const major = items.filter(x => x.w > 0.02), minor = items.filter(x => x.w <= 0.02);
278
320
  const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
279
321
  let text = major.map(x => x.name).join(', ');
@@ -283,6 +325,7 @@ function flNlStatement(f) {
283
325
  return { text: text ? cap(text) + '.' : '', contains, count: items.length };
284
326
  }
285
327
  function _nlStatementText(f) {
328
+ if (_nlSettings(f).region === 'eu') { const e = flNlEuStatement(f); return e.text ? 'INGREDIENTS: ' + e.text : ''; }
286
329
  const s = flNlStatement(f);
287
330
  return (s.text ? 'INGREDIENTS: ' + s.text : '') + (s.contains.length ? '\nCONTAINS: ' + s.contains.join(', ') + '.' : '');
288
331
  }
@@ -466,9 +509,11 @@ function flNlTabHtml(f) {
466
509
  <div class="card-header"><h2>Ingredient statement</h2>
467
510
  <button class="btn btn-secondary btn-sm" onclick="flNlCopyStatement('${id}')">Copy</button></div>
468
511
  <div class="card-body nl-stmt">
469
- <div><strong>INGREDIENTS:</strong> ${esc(s.text) || '<span class="nl-dim">No ingredients yet.</span>'}</div>
512
+ ${eu ? (() => { const es = flNlEuStatement(f); return `<div class="nl-eu-stmt"><strong>INGREDIENTS:</strong> ${es.html || '<span class="nl-dim">No ingredients yet.</span>'}</div>
513
+ ${es.allergens.length ? '' : '<div class="nl-dim">No EU allergens on the ingredients.</div>'}
514
+ <div class="nl-dim nl-hint" data-tip="The 14 EU allergens, from each ingredient’s allergen chips. A name that doesn’t say the allergen gets it added in brackets. Copy gives them in CAPITALS. Add a custom field named label_name to an ingredient to print another name.">By weight, most first. Allergens in bold.</div>`; })() : `<div><strong>INGREDIENTS:</strong> ${esc(s.text) || '<span class="nl-dim">No ingredients yet.</span>'}</div>
470
515
  ${s.contains.length ? `<div class="nl-contains"><strong>CONTAINS:</strong> ${esc(s.contains.join(', '))}.</div>` : '<div class="nl-dim">No major US allergens on the ingredients.</div>'}
471
- <div class="nl-dim nl-hint" data-tip="Add a custom field named label_name to an ingredient to print another name here.">By weight, most first. 2% or less grouped.</div>
516
+ <div class="nl-dim nl-hint" data-tip="Add a custom field named label_name to an ingredient to print another name here.">By weight, most first. 2% or less grouped.</div>`}
472
517
  </div>
473
518
  </div>
474
519
  <div class="card">
@@ -615,7 +660,7 @@ function flNlPrint(fid) {
615
660
  win.document.write(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${esc(f.name || 'Nutrition Facts')}</title><style>${css}</style></head><body>
616
661
  <h1>${esc(f.name || '')}</h1><div class="meta">${esc([f.uid, 'calculated from ingredient data', 'printed ' + new Date().toLocaleDateString()].filter(Boolean).join(' · '))}</div>
617
662
  ${flNlPanelHtml(f)}
618
- <div class="stmt">${s.text ? `<div><b>INGREDIENTS:</b> ${esc(s.text)}</div>` : ''}${s.contains.length ? `<div><b>CONTAINS:</b> ${esc(s.contains.join(', '))}.</div>` : ''}</div>
663
+ <div class="stmt">${_nlSettings(f).region === 'eu' ? (() => { const es = flNlEuStatement(f); return es.html ? `<div><b>INGREDIENTS:</b> ${es.html}</div>` : ''; })() : `${s.text ? `<div><b>INGREDIENTS:</b> ${esc(s.text)}</div>` : ''}${s.contains.length ? `<div><b>CONTAINS:</b> ${esc(s.contains.join(', '))}.</div>` : ''}`}</div>
619
664
  <script>window.onload=()=>setTimeout(()=>window.print(),250)<\/script></body></html>`);
620
665
  win.document.close();
621
666
  if (typeof flPreparePrintWindow === 'function') flPreparePrintWindow(win);