formlab-mcp 0.6.83 → 0.6.85

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.85",
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.85",
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.85",
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: {
@@ -119,7 +119,9 @@ function flNlCompute(f) {
119
119
  FL_NL_NUTRIENTS.forEach((n, j) => {
120
120
  let sum = 0; const miss = [];
121
121
  rows.forEach((r, i) => { const v = vals[i][j]; if (v == null) { if (vals[i].some(x => x != null)) miss.push(_nlRowName(r)); } else sum += r.amount * v; });
122
- out.per100[n.key] = sum / total;
122
+ // An impossible figure (an amount or a field near 1e308 overflows to Infinity) counts as 0, not "Infinity%" (QA, 17 Nov).
123
+ const v = sum / total;
124
+ out.per100[n.key] = Number.isFinite(v) && v <= 1e9 ? v : 0;
123
125
  if (miss.length) out.missing[n.key] = miss;
124
126
  });
125
127
  out.ok = out.withData > 0;
@@ -144,10 +146,12 @@ function flNlHasFoodData(f) {
144
146
  }
145
147
 
146
148
  const FL_NL_MAX_SERVING = 5000; // g; a larger serving is a typo
149
+ // Typed text only: a stored object or array is not a household measure ("[object Object]"; QA, 17 Nov).
150
+ const _nlStr = (v) => (typeof v === 'string' || typeof v === 'number') ? String(v).trim() : '';
147
151
  function _nlSettings(f) {
148
152
  const l = (f && f.label) || {};
149
153
  const s = parseFloat(l.serving), y = parseFloat(l.yield);
150
- return { yield: Number.isFinite(y) && y >= FL_NL_YIELD[0] && y <= FL_NL_YIELD[1] && y !== 100 ? y : null, serving: Number.isFinite(s) && s > 0 && s <= FL_NL_MAX_SERVING ? s : null, unit: l.unit === 'mL' ? 'mL' : 'g', region: l.region === 'eu' ? 'eu' : 'us', format: ['simplified', 'tabular', 'linear', 'dual'].includes(l.format) ? l.format : 'standard', household: String(l.household || '').trim(), servings: String(l.servings || '').trim() };
154
+ return { yield: Number.isFinite(y) && y >= FL_NL_YIELD[0] && y <= FL_NL_YIELD[1] && y !== 100 ? y : null, serving: Number.isFinite(s) && s > 0 && s <= FL_NL_MAX_SERVING ? s : null, unit: l.unit === 'mL' ? 'mL' : 'g', region: l.region === 'eu' ? 'eu' : 'us', format: ['simplified', 'tabular', 'linear', 'dual'].includes(l.format) ? l.format : 'standard', household: _nlStr(l.household), servings: _nlStr(l.servings) };
151
155
  }
152
156
  // A serving in grams. A drink's serving is in mL (61r): grams = mL × the formula's density, the finished density
153
157
  // when it has one, else the ideal-mix estimate; with neither, 1 g/mL and `noDensity` so the tab can say so.
@@ -264,16 +268,59 @@ function flNlEuPanelHtml(f, calc) {
264
268
 
265
269
  // ── Ingredient statement and Contains ───────────────────────
266
270
  // Leaves in descending order by weight; those at 2 % or less may follow "Contains 2% or less of".
267
- function flNlStatement(f) {
271
+ // The formula's leaves, heaviest first: [{ name (label_name when set), w, allergens }]
272
+ function _nlStatementItems(f) {
268
273
  const leaves = (typeof _flattenComposition === 'function') ? _flattenComposition(f).rows : [];
269
274
  const by = new Map();
270
275
  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]) => {
276
+ return [...by.entries()].map(([id, w]) => {
272
277
  const ing = (db.ingredients || []).find(i => i.id === id);
273
278
  if (!ing) return null;
274
279
  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 };
280
+ return { name: cf ? String(cf.value).trim() : (ing.name || ''), w, allergens: Array.isArray(ing.allergens) ? ing.allergens : [] };
276
281
  }).filter(x => x && x.name).sort((a, b) => b.w - a.w);
282
+ }
283
+
284
+ // ── EU ingredient list: allergens emphasised (Regulation (EU) No 1169/2011, Art. 21 and Annex II; 62c) ──
285
+ // The app's allergen chip → the word the list must show, and the words in an ingredient's own name that already say
286
+ // it. A name that says it gets that word emphasised ("WHEAT flour"); one that doesn't gets it added ("whey protein
287
+ // (MILK)"). On the page the emphasis is bold; in copied text, capitals. Latex is not a food allergen.
288
+ const FL_NL_EU_ALLERGENS = {
289
+ celery: ['celery', /celery|celeriac/i], eggs: ['egg', /eggs?/i], fish: ['fish', /fish/i],
290
+ gluten: ['gluten', /wheat|rye|barley|oats?|spelt|kamut|gluten/i], wheat: ['wheat', /wheat|spelt|durum/i],
291
+ lupin: ['lupin', /lupine?s?/i], milk: ['milk', /milk/i], molluscs: ['molluscs', /mollusc?ks?|oysters?|mussels?|squid|clams?|octopus/i],
292
+ mustard: ['mustard', /mustard/i], peanuts: ['peanuts', /peanuts?/i], sesame: ['sesame', /sesame/i],
293
+ shellfish: ['crustaceans', /crustaceans?|shrimps?|prawns?|crabs?|lobsters?|crayfish/i], soy: ['soya', /soya|soybeans?|soy/i],
294
+ sulfites: ['sulphites', /sulphites?|sulfites?|sul(?:ph|f)ur dioxide|(?:meta)?bisul(?:ph|f)ite/i],
295
+ 'tree-nuts': ['nuts', /almonds?|hazelnuts?|walnuts?|cashews?|pecans?|pistachios?|macadamias?|brazil nuts?|nuts?/i],
296
+ };
297
+ // → { html, text, allergens: [words], count }: every ingredient in descending order by weight.
298
+ function flNlEuStatement(f) {
299
+ const items = _nlStatementItems(f), found = [];
300
+ const one = (it, mark, safe) => {
301
+ const spans = [], add = [];
302
+ it.allergens.forEach(k => {
303
+ // Own keys only: a stored chip named "constructor" found Object's own and took the tab down (QA, 17 Nov).
304
+ const d = typeof k === 'string' && Object.prototype.hasOwnProperty.call(FL_NL_EU_ALLERGENS, k) ? FL_NL_EU_ALLERGENS[k] : null;
305
+ if (!d) return;
306
+ if (!found.includes(d[0])) found.push(d[0]);
307
+ const m = new RegExp('\\b(?:' + d[1].source + ')\\b', 'i').exec(it.name);
308
+ 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]); }
309
+ else if (!add.includes(d[0])) add.push(d[0]);
310
+ });
311
+ spans.sort((a, b) => a[0] - b[0]);
312
+ let out = '', at = 0;
313
+ spans.forEach(([a, b]) => { out += safe(it.name.slice(at, a)) + mark(it.name.slice(a, b)); at = b; });
314
+ out += safe(it.name.slice(at));
315
+ return out + (add.length ? ' (' + add.map(mark).join(', ') + ')' : '');
316
+ };
317
+ const list = (mark, safe) => items.map(it => one(it, mark, safe)).join(', ');
318
+ const html = list(w => `<b>${esc(w)}</b>`, esc), text = list(w => w.toUpperCase(), x => x);
319
+ return { html: html ? html + '.' : '', text: text ? text + '.' : '', allergens: found, count: items.length };
320
+ }
321
+
322
+ function flNlStatement(f) {
323
+ const items = _nlStatementItems(f);
277
324
  const major = items.filter(x => x.w > 0.02), minor = items.filter(x => x.w <= 0.02);
278
325
  const cap = (s) => s.charAt(0).toUpperCase() + s.slice(1);
279
326
  let text = major.map(x => x.name).join(', ');
@@ -283,6 +330,7 @@ function flNlStatement(f) {
283
330
  return { text: text ? cap(text) + '.' : '', contains, count: items.length };
284
331
  }
285
332
  function _nlStatementText(f) {
333
+ if (_nlSettings(f).region === 'eu') { const e = flNlEuStatement(f); return e.text ? 'INGREDIENTS: ' + e.text : ''; }
286
334
  const s = flNlStatement(f);
287
335
  return (s.text ? 'INGREDIENTS: ' + s.text : '') + (s.contains.length ? '\nCONTAINS: ' + s.contains.join(', ') + '.' : '');
288
336
  }
@@ -466,9 +514,11 @@ function flNlTabHtml(f) {
466
514
  <div class="card-header"><h2>Ingredient statement</h2>
467
515
  <button class="btn btn-secondary btn-sm" onclick="flNlCopyStatement('${id}')">Copy</button></div>
468
516
  <div class="card-body nl-stmt">
469
- <div><strong>INGREDIENTS:</strong> ${esc(s.text) || '<span class="nl-dim">No ingredients yet.</span>'}</div>
517
+ ${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>
518
+ ${es.allergens.length ? '' : '<div class="nl-dim">No EU allergens on the ingredients.</div>'}
519
+ <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
520
  ${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>
521
+ <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
522
  </div>
473
523
  </div>
474
524
  <div class="card">
@@ -597,6 +647,7 @@ const FL_NL_PANEL_CSS = `.nl-panel{box-sizing:border-box;width:280px;padding:4px
597
647
  .nl-panel.nl-eu{width:316px;padding:0;border-width:1px}
598
648
  .nl-eu table{width:100%;table-layout:fixed;border-collapse:collapse;margin:0;background:none;font:400 11.5px/1.25 Helvetica,Arial,sans-serif}
599
649
  .nl-eu th,.nl-eu td{padding:3px 5px;border:0;border-bottom:1px solid #000;background:none;color:#000;font:400 11.5px/1.25 Helvetica,Arial,sans-serif;text-align:right;vertical-align:bottom;text-transform:none;letter-spacing:0;white-space:nowrap}
650
+ .nl-panel.nl-eu th,.nl-panel.nl-eu td{background:rgb(255,255,255)!important;color:#000!important}
600
651
  .nl-eu th{font-weight:700;border-bottom-width:1.5px;white-space:normal}.nl-eu th:first-child{width:38%}.nl-eu th:first-child,.nl-eu td:first-child{text-align:left}
601
652
  .nl-eu th + th,.nl-eu td + td{border-left:1px solid #000}
602
653
  .nl-eu tr:last-child td{border-bottom:0}.nl-eu .nl-e-in td:first-child{padding-left:16px}`;
@@ -615,7 +666,7 @@ function flNlPrint(fid) {
615
666
  win.document.write(`<!DOCTYPE html><html><head><meta charset="utf-8"><title>${esc(f.name || 'Nutrition Facts')}</title><style>${css}</style></head><body>
616
667
  <h1>${esc(f.name || '')}</h1><div class="meta">${esc([f.uid, 'calculated from ingredient data', 'printed ' + new Date().toLocaleDateString()].filter(Boolean).join(' · '))}</div>
617
668
  ${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>
669
+ <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
670
  <script>window.onload=()=>setTimeout(()=>window.print(),250)<\/script></body></html>`);
620
671
  win.document.close();
621
672
  if (typeof flPreparePrintWindow === 'function') flPreparePrintWindow(win);