formlab-mcp 0.6.65 → 0.6.67

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
@@ -33,7 +33,7 @@ Ask Claude (or another MCP client) things like:
33
33
  | `find_similar_formulations` | Find formulas using a given ingredient ≥ threshold % |
34
34
  | `compare_formulations` | Pairwise side-by-side composition diff |
35
35
  | `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`) |
36
- | `get_ingredient` | Full record + supplier / **cost ($/kg)** / stock / chemical name / molecular weight / storage / formulations using it, plus **GHS safety** (pictograms, H/P codes, signal word), **per-jurisdiction regulatory status**, **approved sources** (the suppliers / manufacturers qualified to supply this material — ASL/AML), and **inventory lots** (balances + expiry + the source each was received from). Returns every class-specific sub-object when present: `sequence` (peptide / oligo), `taxon` (NCBI ID + scientific name), `ingredientClass`, `extractDetails`, `sequenceDetails`, `polymerDetails`, `surfactantDetails`, `pigmentDetails`, `fragranceDetails`, and its **custom fields** with units (`customFields`: protein / carb / fat in g/100g, solids %… — what theoretical parameters read) |
36
+ | `get_ingredient` | Full record + supplier / **cost ($/kg)** / stock / chemical name / molecular weight / storage / formulations using it, plus **GHS safety** (pictograms, H/P codes, signal word), **per-jurisdiction regulatory status**, **approved sources** (the suppliers / manufacturers qualified to supply this material — ASL/AML), and **inventory lots** (balances + expiry + the source each was received from). Returns every class-specific sub-object when present: `sequence` (peptide / oligo), `taxon` (NCBI ID + scientific name), `ingredientClass`, `extractDetails`, `sequenceDetails`, `polymerDetails`, `surfactantDetails`, `pigmentDetails`, `fragranceDetails`, and its **custom fields** with units (`customFields`: protein / carb / fat in g/100g, solids %… — what theoretical parameters read), and its **reactive groups** (EEW, AHEW, OH number, NCO %, acid / amine value: as entered, in the datasheet's terms and meq/g, with any row the app ignores and why) |
37
37
  | `list_lots` | Inventory lots across ingredients (each a received batch with its own remaining balance, supplier, expiry, **unit cost**, **status** — `active` / `hold` / `quarantine` / `rejected`; held lots are blocked from consumption, with a `holdReason` — and the **approved source** it was received from: `source.supplier` + `source.manufacturer`, where recalls hinge on the manufacturer). Each lot also reports its **Certificate of Analysis** (`coa`: linked, or matched by lot number) and `coaMissing` for an in-stock lot without one. Filters: `ingredient_id`, `expiring_within_days`, `status` (e.g. `hold` to find lots held for a recall), `missing_coa` |
38
38
  | `list_suppliers` | Supplier / manufacturer records with roll-ups — ingredients approved, lots received / on hand (+ value at paid cost), qualified / trial / disqualified source counts, last receipt; lots count by supplier **and** by manufacturer |
39
39
  | `get_supplier` | One supplier in full: record, every ingredient it's an approved source for, every lot from it, and the **recall trace** (batches that consumed those lots → products, shipments, samples, sub-batches; lots on hold flagged) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.65",
3
+ "version": "0.6.67",
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.65",
5
+ "version": "0.6.67",
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.65",
11
+ "version": "0.6.67",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
package/theoretical.js CHANGED
@@ -26,7 +26,26 @@ function source() {
26
26
  // Runs inside the vm: evaluates one formulation's (or batch's) parameters and
27
27
  // returns a JSON string, so only plain text crosses back.
28
28
  const EPILOGUE = `
29
- ;function __theo(kind, id) {
29
+ ;function __rx(id) {
30
+ var ing = (db.ingredients || []).find(function (x) { return x && x.id === id; });
31
+ if (!ing) return '[]';
32
+ var meq = flRxIngMeq(ing);
33
+ var stored = ing.reactiveGroups || [];
34
+ var counted = []; // the stored row each group's value came from (the app takes the first valid one)
35
+ var out = Object.keys(meq).map(function (g) {
36
+ var e = stored.find(function (x) { return x && x.group === g && flRxMeq(x, ing.mw) != null; });
37
+ if (e) counted.push(e);
38
+ return { group: g, label: FL_RX_GROUPS[g].label, datasheet: flRxTermText(g, meq[g]), meqPerG: +meq[g].toPrecision(4),
39
+ entered: e ? { basis: FL_RX_BASES[e.basis].label, value: +e.value } : 'water, counted by its CAS number' };
40
+ });
41
+ stored.forEach(function (x) {
42
+ if (!x || counted.indexOf(x) >= 0) return;
43
+ var why = !FL_RX_GROUPS[x.group] ? 'unknown group' : !FL_RX_BASES[x.basis] ? 'unknown basis' : (x.basis === 'f' && !(+ing.mw > 0)) ? 'groups per molecule needs the MW' : !(+x.value > 0) ? 'no positive value' : 'a second row for the group (the first counts)';
44
+ out.push({ group: x.group, ignored: true, entered: { basis: (FL_RX_BASES[x.basis] || {}).label || x.basis, value: x.value }, why: why });
45
+ });
46
+ return JSON.stringify(out);
47
+ }
48
+ function __theo(kind, id) {
30
49
  var coll = kind === 'batch' ? db.batches : db.formulations;
31
50
  var e = (coll || []).find(function (x) { return x && x.id === id; });
32
51
  if (!e) return '[]';
@@ -39,7 +58,7 @@ const EPILOGUE = `
39
58
  var r = res[p.id] || {};
40
59
  var v = (!r.error && Number.isFinite(r.value)) ? r.value : null;
41
60
  var warning = null;
42
- try { var m = _tpMissingNote(_tpMissingInputs(p.formula, rows)); if (m) warning = m.text; } catch (_) {}
61
+ try { var m = r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : _tpMissingNote(_tpMissingInputs(p.formula, rows)); if (m) warning = m.text; } catch (_) {}
43
62
  var spec = (p.spec && (p.spec.min != null || p.spec.max != null)) ? { min: p.spec.min != null ? p.spec.min : null, max: p.spec.max != null ? p.spec.max : null } : null;
44
63
  var pass = (v != null && spec) ? ((spec.min == null || v >= spec.min) && (spec.max == null || v <= spec.max)) : null;
45
64
  return { name: p.name || '', value: v, unit: p.unit || '', formula: p.formula || '', error: r.error || null,
@@ -66,6 +85,16 @@ function contextFor(db) {
66
85
  return ctx;
67
86
  }
68
87
 
88
+ // An ingredient's reactive groups as the app reads them (js/reactive.js): [{ group, label, datasheet ("AHEW 42.6
89
+ // g/eq"), meqPerG, entered: { basis, value } }], plus the rows it ignores and why (ignored: true, why).
90
+ export function reactiveGroups(db, id) {
91
+ try {
92
+ const ctx = contextFor(db);
93
+ vm.runInContext('var __rid = ' + JSON.stringify(String(id)) + ';', ctx);
94
+ return JSON.parse(vm.runInContext('__rx(__rid)', ctx, { timeout: 2000 }));
95
+ } catch (e) { return []; }
96
+ }
97
+
69
98
  // [{ name, value, unit, formula, error, warning, spec, pass, pinned, basis }] —
70
99
  // value null when it can't be computed (error says why); warning is the Params
71
100
  // tab's ⚠ note ("2 ingredients missing carb", "sugar in mixed units (…)");
@@ -6,6 +6,7 @@
6
6
 
7
7
  import { getStore, resolveById } from '../data.js';
8
8
  import { ingredientSmiles } from '../peptide.js';
9
+ import { reactiveGroups } from '../theoretical.js';
9
10
 
10
11
  // FormLab's export is the raw db, so ingredients carry the APP field shapes:
11
12
  // `cas` (not casNumber) and `cost = {value, currency, unit}` (not a flat
@@ -170,7 +171,7 @@ const list_ingredients = {
170
171
  const get_ingredient = {
171
172
  definition: {
172
173
  name: 'get_ingredient',
173
- description: 'Get full details for a single ingredient: cost ($/kg), GHS safety (pictograms / H- / P-codes / signal word), per-jurisdiction regulatory status, approved sources (the suppliers/manufacturers qualified to supply this material — ASL/AML), inventory lots (balances + expiry + the source each was received from), recent stock movements, and the formulations using it, plus its `customFields` (name, value, unit — e.g. protein / carb / fat in g/100g, solids %; what theoretical parameters read). Accepts internal id or UID (e.g. ING-001).',
174
+ description: 'Get full details for a single ingredient: cost ($/kg), GHS safety (pictograms / H- / P-codes / signal word), per-jurisdiction regulatory status, approved sources (the suppliers/manufacturers qualified to supply this material — ASL/AML), inventory lots (balances + expiry + the source each was received from), recent stock movements, and the formulations using it, plus its `customFields` (name, value, unit — e.g. protein / carb / fat in g/100g, solids %; what theoretical parameters read) and `reactiveGroups` (EEW, AHEW, OH number, NCO %, acid / amine value, Si-H, vinyl, water: the datasheet value as entered, the same in the datasheet\'s own terms, and meq/g; rows the app ignores are listed with why). Accepts internal id or UID (e.g. ING-001).',
174
175
  inputSchema: {
175
176
  type: 'object',
176
177
  properties: {
@@ -228,6 +229,9 @@ const get_ingredient = {
228
229
  // (protein / carb / fat in g/100g for nutrition, solids % for NV, …).
229
230
  // The unit is a label; a 0 is a value.
230
231
  customFields: (ing.customFields || []).filter(c => c && c.name).map(c => ({ name: c.name, value: c.value != null ? c.value : '', unit: c.unit || '', ...(c.info ? { info: c.info } : {}) })),
232
+ // Reactive groups (EEW, AHEW, OH number, NCO %, acid / amine value, Si-H, vinyl, water) as the app reads them,
233
+ // in the datasheet's terms and meq/g, with any row it ignores and why.
234
+ reactiveGroups: reactiveGroups(db, ing.id),
231
235
  safety,
232
236
  regulatory,
233
237
  lots,
@@ -170,7 +170,11 @@ function flRxMixedUnits(comp) {
170
170
  const typed = new Set((comp || []).filter(c => c && (c.ingredientId || c.formulationId) && _flRxNum(c.amount) > 0)
171
171
  .map(c => (abs(c.unit) ? 'abs' : _flRxUnitBasis(c.unit))).filter(Boolean));
172
172
  if (typed.size > 1) return true;
173
- return new Set(_flRxRows(comp).filter(r => r && r.amount > 0).map(r => _flRxUnitBasis(r.unit)).filter(Boolean)).size > 1;
173
+ const built = _flRxRows(comp).filter(r => r && r.amount > 0);
174
+ // A row still in mL once built had no density, so none were made masses: an all-mL recipe multiplied millilitres
175
+ // by meq per gram (QA sweep, Jun 1 Nov: 100 mL of a 1.16 g/mL epoxy counted as 100 g).
176
+ if (typeof isVolUnit === 'function' && built.some(r => isVolUnit(r.unit))) return true;
177
+ return new Set(built.map(r => _flRxUnitBasis(r.unit)).filter(Boolean)).size > 1;
174
178
  }
175
179
  // The pairs a composition holds: both sides present.
176
180
  function flRxPairsFor(comp) {
@@ -193,6 +197,7 @@ function flRxKitRatio(comp) {
193
197
  const rows = _flRxRows(comp).filter(r => r && r.ing && r.ing._isSubFormula);
194
198
  if (rows.length !== parts.length || !(rows[0].amount > 0)) return null;
195
199
  const subs = parts.map(c => (db.formulations || []).find(g => g.id === c.formulationId));
200
+ if (subs.some(g => !g || g._trashed || g.deletedAt)) return null; // a part deleted or in Trash: no ratio to quote (QA sweep)
196
201
  const dens = subs.map(g => (g && typeof _rolledUpDensity === 'function') ? _rolledUpDensity(g) : null);
197
202
  const vol = dens.every(d => d > 0) ? rows.map((r, i) => r.amount / dens[i]) : null;
198
203
  return {
@@ -455,7 +460,7 @@ function flRxBatchStripHtml(b) {
455
460
  const comp = hasActual ? b.actualComposition : (f ? f.composition : []);
456
461
  const found = flRxPairsFor(comp);
457
462
  if (!found.length) return '';
458
- if (flRxMixedUnits(comp)) return `<div class="fl-rx-strip" id="fl-rx-bstrip-${esc(b.id)}"><span class="fl-rx-kicker">Reactive balance</span><span class="fl-rx-warn">Rows in different units: put them on one basis for an index.</span></div>`;
463
+ if (flRxMixedUnits(comp)) return `<div class="fl-rx-strip" id="fl-rx-bstrip-${esc(b.id)}"><span class="fl-rx-kicker">Reactive balance</span><span class="fl-rx-warn">Rows in different units (% and g, or mL without a density): put them on one basis for an index.</span></div>`;
459
464
  const pro = typeof hasFeature !== 'function' || hasFeature('reactive.solve');
460
465
  const planned = f && hasActual && !flRxMixedUnits(f.composition) ? flRxPairsFor(f.composition) : [];
461
466
  const chips = found.map(({ pair, index }) => {
@@ -243,6 +243,8 @@ function _tpTransformRefs(expr) {
243
243
  // Evaluate a compiled formula against a row set. Aggregation helpers
244
244
  // are passed in fresh on each call so they close over the right rows.
245
245
  function _tpEvaluate(formula, rows) {
246
+ // mL rows without a density (_tpBuildRows): no number from the rows, never raw mL read as wt% (smart search calls in here).
247
+ if (rows && rows.needsDensity && /\b(row|ing)\./i.test(String(formula || ''))) return NaN;
246
248
  const fn = _tpCompile(formula);
247
249
  const safe = (rows || []).filter(Boolean);
248
250
  const filteredFor = (cf) => {
@@ -375,21 +377,26 @@ function _tpEvaluateAll(params, rows) {
375
377
  visiting[p.id] = true;
376
378
 
377
379
  const valueMap = {};
378
- let depError = '';
380
+ let depError = '', needsDensity = null;
379
381
  for (const ref of _tpScanParamRefs(p.formula)) {
380
382
  const key = ref.name.toLowerCase();
381
383
  const dep = byName[key];
382
384
  if (!dep) { depError = depError || `Unknown parameter [${ref.name}]`; continue; }
383
385
  if (dep.id === p.id) { depError = depError || 'Circular reference'; continue; }
384
386
  const dr = resolve(dep);
387
+ if (dr.needsDensity) { needsDensity = dr.needsDensity; continue; }
385
388
  if (dr.error) { depError = depError || `[${ref.name}] → ${dr.error}`; continue; }
386
389
  if (!Number.isFinite(dr.value)) { depError = depError || `[${ref.name}] is not a number`; continue; }
387
390
  valueMap[key] = dr.value;
388
391
  }
389
392
 
393
+ // Reads the recipe's rows while some are mL with no density: no value, and the ingredients to fix.
394
+ if (!needsDensity && rows && rows.needsDensity && /\b(row|ing)\./i.test(String(p.formula || ''))) needsDensity = rows.needsDensity;
390
395
  let res;
391
396
  if (depError) {
392
397
  res = { value: null, error: depError, name: p.name };
398
+ } else if (needsDensity) {
399
+ res = { value: null, error: '', name: p.name, needsDensity };
393
400
  } else {
394
401
  try {
395
402
  const substituted = _tpSubstituteParamRefs(p.formula, valueMap);
@@ -460,17 +467,24 @@ function _tpBuildRows(composition) {
460
467
  const isV = u => (typeof isVolUnit === 'function') && isVolUnit(u);
461
468
  const abs = rows.filter(r => isM(r.unit) || isV(r.unit));
462
469
  if (abs.length && typeof massToKg === 'function' && typeof volToL === 'function') {
470
+ const noDensity = [];
463
471
  const grams = abs.map(r => {
464
472
  if (isM(r.unit)) { const f = massToKg(r.unit); return (f != null) ? r.amount * f * 1000 : null; }
465
473
  const L = volToL(r.unit);
466
474
  let d = null;
467
475
  if (r._srcIng && typeof _densityToKgPerL === 'function') d = _densityToKgPerL(r._srcIng.density, r._srcIng.densityUnit);
468
476
  else if (r._srcSub && typeof _rolledUpDensity === 'function') { const sub = db.formulations.find(g => g.id === r._srcSub); d = sub ? _rolledUpDensity(sub) : null; }
469
- return (L != null && d != null && isFinite(d) && d > 0) ? r.amount * L * d * 1000 : null;
477
+ const ok = L != null && d != null && isFinite(d) && d > 0;
478
+ if (!ok && r.amount > 0) noDensity.push(r._srcIng ? (r._srcIng.name || '(unnamed)') : (r._subName || 'sub-formula'));
479
+ return ok ? r.amount * L * d * 1000 : null;
470
480
  });
471
481
  const total = grams.reduce((a, g) => a + (g || 0), 0);
472
482
  if (grams.every(g => g != null && isFinite(g)) && total > 0) {
473
483
  abs.forEach((r, i) => { r.amount = (grams[i] / total) * 100; r.unit = 'wt%'; });
484
+ } else if (noDensity.length) {
485
+ // A volume row with no density leaves every row as typed, and an expression would read raw mL as if it were
486
+ // wt% (Jun, 1 Nov). Said here, so _tpEvaluateAll gives those parameters no value instead.
487
+ Object.defineProperty(rows, 'needsDensity', { value: [...new Set(noDensity)], enumerable: false });
474
488
  }
475
489
  }
476
490
  rows.forEach(r => { delete r._srcIng; delete r._srcSub; });
@@ -976,6 +990,12 @@ function _tpMissingInputs(formula, rows) {
976
990
  res.ingredients = [...names];
977
991
  return res;
978
992
  }
993
+ // The line for a parameter left without a value: mL rows need a density to count by mass.
994
+ function _tpNeedsDensityNote(names) {
995
+ const n = names.length;
996
+ return { text: `Needs a density: ${names.slice(0, 2).join(', ')}${n > 2 ? ` +${n - 2} more` : ''}`,
997
+ tip: `Rows in mL count by mass. Give ${n === 1 ? 'it' : 'these'} a density, or enter the recipe in g or %: ${names.join(', ')}.` };
998
+ }
979
999
  // One short line for the table (and its tooltip), '' when nothing is missing.
980
1000
  function _tpMissingNote(miss) {
981
1001
  if (!miss) return null;
@@ -1050,7 +1070,7 @@ function renderTheoreticalParamsHtml(entityType, entity) {
1050
1070
  // Pass/fail vs. spec, if defined
1051
1071
  const pfBadge = (!errorText && Number.isFinite(value)) ? _tpSpecBadgeHtml(value, p.spec) : '';
1052
1072
 
1053
- const miss = (!errorText && Number.isFinite(value)) ? _tpMissingNote(_tpMissingInputs(p.formula, evalRows)) : null;
1073
+ const miss = (!errorText && Number.isFinite(value)) ? _tpMissingNote(_tpMissingInputs(p.formula, evalRows)) : (r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : null);
1054
1074
  const missHtml = miss ? `<div class="tp-miss" title="${esc(miss.tip)}" style="margin-top:3px;font-size:11px;font-weight:400;color:var(--dk-amber-fg, #b45309);cursor:help">⚠ ${esc(miss.text)}</div>` : '';
1055
1075
 
1056
1076
  const formulaPreview = (p.formula || '').length > 80
@@ -1136,7 +1156,7 @@ function _tpPinnedChipsHtml(entityType, entity) {
1136
1156
  if (okMin && okMax) { bg = 'var(--dk-green-bg2, #dcfce7)'; fg = 'var(--dk-green-fg, #15803d)'; bd = 'var(--dk-green-line, #bbf7d0)'; }
1137
1157
  else { bg = 'var(--dk-red-bg2, #fee2e2)'; fg = 'var(--dk-red-fg, #b91c1c)'; bd = 'var(--dk-red-line, #fecaca)'; }
1138
1158
  } else if (r.error) { fg = 'var(--dk-red-fg, #b91c1c)'; }
1139
- const miss = (!r.error && Number.isFinite(r.value)) ? _tpMissingNote(_tpMissingInputs(p.formula, chipRows)) : null;
1159
+ const miss = (!r.error && Number.isFinite(r.value)) ? _tpMissingNote(_tpMissingInputs(p.formula, chipRows)) : (r.needsDensity ? _tpNeedsDensityNote(r.needsDensity) : null);
1140
1160
  const title = r.error ? r.error : ((p.description || `${p.name}${p.unit ? ' (' + p.unit + ')' : ''}`) + (miss ? '\n⚠ ' + miss.text + '\n' + miss.tip : ''));
1141
1161
  return `<span title="${esc(title)}" style="display:inline-flex;align-items:baseline;gap:5px;padding:3px 9px;border-radius:9999px;background:${bg};border:1px solid ${bd};font-size:11.5px;line-height:1.4;white-space:nowrap">
1142
1162
  <span style="color:var(--dk-muted, #64748b)">${esc(p.name)}</span>