formlab-mcp 0.6.81 → 0.6.82

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.81",
3
+ "version": "0.6.82",
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.81",
5
+ "version": "0.6.82",
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.81",
11
+ "version": "0.6.82",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -694,8 +694,9 @@ function _tpHarmonizeUnits(rows) {
694
694
  // with an amount has a number for it, in one unit: a premix with a solvent missing its solids is still "not
695
695
  // counted", as before. Not rolled: density (by volume), Tg, HLB, purity, cost, text fields. Nested premixes roll up
696
696
  // through _tpBuildRows; a cycle rolls up nothing.
697
- const _TP_MASS_UNIT = /^(%|wt\s*%|%\s*w\/w|w\/w\s*%?|g\s*\/\s*100\s*g|mg\s*\/\s*100\s*g|g\s*\/\s*kg|mg\s*\/\s*kg|ppm|ppb|mg\s*koh\s*\/\s*g|meq\s*\/\s*g|mmol\s*\/\s*g)$/i;
697
+ const _TP_MASS_UNIT = /^(%|wt\s*%|%\s*w\/w|w\/w\s*%?|g\s*\/\s*100\s*g|mg\s*\/\s*100\s*g|[µu]g\s*\/\s*100\s*g|g\s*\/\s*kg|mg\s*\/\s*kg|ppm|ppb|mg\s*koh\s*\/\s*g|meq\s*\/\s*g|mmol\s*\/\s*g)$/i;
698
698
  const _TP_MASS_NAMES = new Set(['solids', 'nv', 'nv %', 'nv%', 'non-volatiles', 'nonvolatiles', 'protein', 'fat', 'carb', 'carbs', 'carbohydrate', 'sugar', 'sugars', 'sodium', 'salt', 'fiber', 'fibre', 'ash', 'moisture',
699
+ 'sat_fat', 'trans_fat', 'added_sugar', 'cholesterol', 'calcium', 'iron', 'potassium', 'vit_d', 'atwater',
699
700
  'volume', 'pigmentvolume', 'dryvolume', 'volatileorganic', 'voc %']); // per gram, so they add by mass (PVC, VOC through a premix)
700
701
  const _TP_NOT_ROLLED = new Set(['density', 'mw', 'cost', 'purity', 'stock', 'reorder', 'tg', 'hlb', 'taxonid']);
701
702
  const _tpSubStack = new Set();
@@ -806,6 +807,12 @@ function _tpIngredientView(ing) {
806
807
  // a solvent (function Solvent; water is not a VOC): all of it volatile, none dry
807
808
  // anything else: dry by its solids (ing.solids or 'NV %'), volatile organic only by a 'VOC %' field
808
809
  Object.assign(out, _tpPerGramFields(ing, out), Object.fromEntries(Object.entries(out).filter(([k]) => _TP_PER_GRAM.has(k))));
810
+ // Food factors (61i, food labels phase 2): ing.atwater is this ingredient's energy in kcal/100 g by ITS OWN calorie
811
+ // factors (kept from Look up in USDA as ing.fdc.factors), the general 4 / 9 / 4 where it has none; empty unless
812
+ // protein, fat and carb are all filled. ing.nFactor is its nitrogen-to-protein factor, 6.25 where it has none.
813
+ // Per mass, so ing.atwater rolls up through a premix. A custom field of the same name wins.
814
+ const _ff = _tpFoodFactorFields(ing);
815
+ Object.keys(_ff).forEach(k => { if (!Object.keys(out).some(o => o.toLowerCase() === k.toLowerCase())) out[k] = _ff[k]; });
809
816
  // Wrap in a Proxy that does case-insensitive property reads. Bracket
810
817
  // form `ing['Solids']` and dotted form `ing.Solids` both flow through
811
818
  // here, so a single hook covers every access path the formula language
@@ -838,6 +845,42 @@ function _tpCiView(out) {
838
845
  }
839
846
 
840
847
  const _TP_FIELD_NEEDS = { volume: 'density', pigmentvolume: 'density', dryvolume: 'density or solids' };
848
+ const _TP_GENERAL_FACTORS = { protein: 4, fat: 9, carb: 4, nitrogen: 6.25 };
849
+ // The ingredient's factors: its own where Look up in USDA kept them, the general ones otherwise. `own` says which.
850
+ function _tpFoodFactors(ing) {
851
+ const f = (ing && ing.fdc && ing.fdc.factors) || {};
852
+ const ok = (v) => typeof v === 'number' && Number.isFinite(v) && v > 0;
853
+ const kcalOwn = ok(f.protein) && ok(f.fat) && ok(f.carb); // all three or none: never a mix of the two systems
854
+ return {
855
+ protein: kcalOwn ? f.protein : _TP_GENERAL_FACTORS.protein,
856
+ fat: kcalOwn ? f.fat : _TP_GENERAL_FACTORS.fat,
857
+ carb: kcalOwn ? f.carb : _TP_GENERAL_FACTORS.carb,
858
+ nitrogen: ok(f.nitrogen) ? f.nitrogen : _TP_GENERAL_FACTORS.nitrogen,
859
+ own: kcalOwn, ownNitrogen: ok(f.nitrogen),
860
+ };
861
+ }
862
+ function _tpFoodFactorFields(ing) {
863
+ const fx = _tpFoodFactors(ing);
864
+ // The three macros in g/100 g, whatever unit the field carries (mg/100g, %, g/kg …).
865
+ const per100 = (name) => {
866
+ const cf = (ing.customFields || []).find(c => c && String(c.name || '').trim().toLowerCase() === name);
867
+ if (!cf || cf.value == null || cf.value === '') return null;
868
+ const v = typeof cf.value === 'number' ? cf.value : parseFloat(cf.value);
869
+ if (!Number.isFinite(v)) return null;
870
+ const u = String(cf.unit || '').trim();
871
+ if (!u) return v;
872
+ const fam = _tpUnitFactor(u);
873
+ return fam && fam[0] === 'm' ? v * fam[1] * 100 : null;
874
+ };
875
+ const p = per100('protein'), f = per100('fat'), c = per100('carb');
876
+ return {
877
+ atwater: (p != null && f != null && c != null) ? +(fx.protein * p + fx.fat * f + fx.carb * c).toPrecision(12) : null,
878
+ nFactor: fx.nitrogen,
879
+ // For Show calc's note (never read by the math; "_" fields don't roll up): the ingredient's own factors, if any.
880
+ _fxKcal: fx.own ? [fx.protein, fx.fat, fx.carb] : null,
881
+ _fxN: fx.ownNitrogen ? fx.nitrogen : null,
882
+ };
883
+ }
841
884
  const _TP_PER_GRAM = new Set(['volume', 'pigmentVolume', 'dryVolume', 'volatileOrganic']); // a custom field of the same name wins
842
885
  function _tpPerGramFields(ing, view) {
843
886
  const d = (typeof _densityToKgPerL === 'function') ? _densityToKgPerL(ing.density, ing.densityUnit) : (parseFloat(ing.density) || null);
@@ -1030,6 +1073,23 @@ function _tpReplaceSpans(formula, spans, repl) {
1030
1073
  spans.forEach((sp, k) => { out += formula.slice(cur, sp.start) + repl(k); cur = sp.end; });
1031
1074
  return out + formula.slice(cur);
1032
1075
  }
1076
+ // "Own factors: Whey protein 4.27 / 8.79 / 3.87 kcal/g · others 4 / 9 / 4" under Show calc, when the formula reads
1077
+ // ing.atwater or ing.nFactor (61i): which rows used their own USDA factors, and what the rest used.
1078
+ function _tpFactorNoteHtml(formula, rows) {
1079
+ const used = new Set(_tpFieldRefs(formula));
1080
+ const live = (rows || []).filter(r => r && r.ing && !r.ing._missing && !r.ing._isSubFormula && r.amount > 0);
1081
+ const f = (v) => String(+(+v).toFixed(2));
1082
+ const line = (label, own, general, fmt) => {
1083
+ const total = live.length;
1084
+ return `<div class="tp-factor-note" style="margin-top:6px;font-size:11.5px;color:var(--text-muted)">${label}: ${own.length
1085
+ ? `${own.map(r => `${esc(r.ing.name || '(unnamed)')} ${fmt(r)}`).join(' · ')}${own.length < total ? ` · others ${general}` : ''}`
1086
+ : `${general} for every ingredient (none has USDA factors)`}</div>`;
1087
+ };
1088
+ let out = '';
1089
+ if (used.has('atwater')) out += line('Calorie factors (protein / fat / carb, kcal/g)', live.filter(r => Array.isArray(r.ing._fxKcal)), '4 / 9 / 4', r => r.ing._fxKcal.map(f).join(' / '));
1090
+ if (used.has('nfactor')) out += line('Nitrogen factors', live.filter(r => typeof r.ing._fxN === 'number'), '6.25', r => `× ${f(r.ing._fxN)}`);
1091
+ return out;
1092
+ }
1033
1093
  // "sodium: 2 rows in g/100g read as mg/100g" under Show calc, for the fields this formula reads (49z).
1034
1094
  function _tpConvNoteHtml(formula, rows) {
1035
1095
  const conv = rows && rows.unitConversions;
@@ -1144,6 +1204,7 @@ function _tpCalcHtml(p, evalRows, valueMap) {
1144
1204
  ${refBits.length ? `<div style="font-size:11.5px;color:var(--text-muted);margin-bottom:6px">References: ${refBits.join(' &nbsp;·&nbsp; ')}</div>` : ''}
1145
1205
  ${tableHtml || (refBits.length ? '' : '<div style="color:var(--text-muted);font-size:11px">Value comes straight from the expression (no row aggregation).</div>')}
1146
1206
  ${_tpConvNoteHtml(formula, evalRows)}
1207
+ ${_tpFactorNoteHtml(formula, evalRows)}
1147
1208
  ${resultHtml}
1148
1209
  </div>`;
1149
1210
  }
@@ -1882,6 +1943,27 @@ function _tpPresetCatalog() {
1882
1943
  formula: 'SUM(row.amount * (17 * ing.protein + 17 * ing.carb + 37 * ing.fat)) / SUM(row.amount)',
1883
1944
  description: 'Energy in kilojoules: 17 kJ/g protein, 17 kJ/g carbohydrate, 37 kJ/g fat. Needs ing.protein, ing.carb and ing.fat (g/100g).',
1884
1945
  },
1946
+ {
1947
+ group: 'Food & nutrition',
1948
+ name: 'Energy (food factors)',
1949
+ unit: 'kcal/100g',
1950
+ formula: 'SUM(row.amount * ing.atwater) / SUM(row.amount)',
1951
+ description: 'Energy by each ingredient\u2019s own calorie factors from USDA (milk protein 4.27, not 4), the general 4 / 9 / 4 where it has none. Needs ing.protein, ing.fat and ing.carb; Look up in USDA keeps the factors.',
1952
+ },
1953
+ {
1954
+ group: 'Food & nutrition',
1955
+ name: 'Energy (food factors, kJ)',
1956
+ unit: 'kJ/100g',
1957
+ formula: '4.184 * SUM(row.amount * ing.atwater) / SUM(row.amount)',
1958
+ description: 'The same in kilojoules (1 kcal = 4.184 kJ).',
1959
+ },
1960
+ {
1961
+ group: 'Food & nutrition',
1962
+ name: 'Protein (from nitrogen)',
1963
+ unit: 'g/100g',
1964
+ formula: 'SUM(row.amount * ing.nitrogen * ing.nFactor) / SUM(row.amount)',
1965
+ description: 'Protein from measured nitrogen: N \u00d7 each ingredient\u2019s own factor from USDA (milk 6.38, wheat 5.83), 6.25 where it has none. Needs ing.nitrogen (g/100g).',
1966
+ },
1885
1967
  {
1886
1968
  group: 'Food & nutrition',
1887
1969
  name: 'Protein',