formlab-mcp 0.6.73 → 0.6.75

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.73",
3
+ "version": "0.6.75",
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.73",
5
+ "version": "0.6.75",
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.73",
11
+ "version": "0.6.75",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -17,7 +17,9 @@ const _COLL = {
17
17
  ingredient: 'ingredients', equipment: 'equipment', parameter: 'parameters', template: 'templates', lot: 'lots', doeDesign: 'doeDesigns',
18
18
  };
19
19
 
20
- function _record(type, id, db) {
20
+ function _record(type, id, db, viewName) {
21
+ // VT (0225): a shared saved view (view:doe, view:compare, …): its name, kept with each comment.
22
+ if (/^view:/.test(String(type || ''))) return { uid: null, name: viewName || 'a shared view' };
21
23
  if (type === 'request') {
22
24
  const r = (db.requests || []).find(x => x && x.id === id);
23
25
  return r ? { uid: r.uid, name: r.title } : null;
@@ -42,11 +44,11 @@ function _notLive(db) {
42
44
  const list_discussions = {
43
45
  definition: {
44
46
  name: 'list_discussions',
45
- description: 'List discussion comments that sit beside records (formulas, batches, samples, test reports, projects, ingredients, equipment) or work requests — optionally filtered by the record (entity_type + entity_id, UID accepted), author, text, date, or only unresolved threads. Grouped by thread by default (each thread: the record, resolved or not, its comments oldest first); flat=true returns comments newest first. Comments are append-only: a retracted one keeps retracted = {at, reason} — treat it as withdrawn, not as a finding. "tab" says which tab of the record the comment was written on.',
47
+ description: 'List discussion comments that sit beside records (formulas, batches, samples, test reports, projects, ingredients, equipment), shared saved views (entity_type view:doe, view:compare, view:stability, view:test-analytics, view:find; entityName is the view name) or work requests — optionally filtered by the record (entity_type + entity_id, UID accepted), author, text, date, or only unresolved threads. Grouped by thread by default (each thread: the record, resolved or not, its comments oldest first); flat=true returns comments newest first. Comments are append-only: a retracted one keeps retracted = {at, reason} — treat it as withdrawn, not as a finding. "tab" says which tab of the record the comment was written on.',
46
48
  inputSchema: {
47
49
  type: 'object',
48
50
  properties: {
49
- entity_type: { type: 'string', description: 'formulation, batch, sample, testResult, project, ingredient, equipment, or request.' },
51
+ entity_type: { type: 'string', description: 'formulation, batch, sample, testResult, project, ingredient, equipment, request, or a shared saved view (view:doe, view:compare, view:stability, view:test-analytics, view:find; entity_id = the view\'s id).' },
50
52
  entity_id: { type: 'string', description: 'The record (internal id or UID, e.g. FORM-0012, REQ-0003).' },
51
53
  author: { type: 'string', description: 'Case-insensitive substring of the author\'s name.' },
52
54
  text_contains: { type: 'string', description: 'Case-insensitive substring of the comment text.' },
@@ -77,13 +79,13 @@ const list_discussions = {
77
79
  const flat = [...threads.values()].filter(l => !args.open_only || !resolvedOf(l)).flat().filter(keep)
78
80
  .sort((a, b) => Date.parse(b.at) - Date.parse(a.at));
79
81
  return { totalMatching: flat.length, returned: Math.min(flat.length, limit),
80
- comments: flat.slice(0, limit).map(c => { const rec = _record(c.entityType, c.entityId, db);
82
+ comments: flat.slice(0, limit).map(c => { const rec = _record(c.entityType, c.entityId, db, c.viewName);
81
83
  return { ...row(c), entityType: c.entityType, entityId: c.entityId, entityUid: rec ? rec.uid : null, entityName: rec ? rec.name : '' }; }) };
82
84
  }
83
85
  const out = [...threads.values()].map(list => {
84
86
  const comments = list.filter(keep);
85
87
  if (!comments.length) return null;
86
- const c0 = list[0], rec = _record(c0.entityType, c0.entityId, db), resolved = resolvedOf(list);
88
+ const c0 = list[0], rec = _record(c0.entityType, c0.entityId, db, (list.find(c => c.viewName) || {}).viewName), resolved = resolvedOf(list);
87
89
  if (args.open_only && resolved) return null;
88
90
  return { entityType: c0.entityType, entityId: c0.entityId, entityUid: rec ? rec.uid : null, entityName: rec ? rec.name : '',
89
91
  resolved, lastAt: list[list.length - 1].at, comments: comments.map(row) };
@@ -102,7 +104,7 @@ const list_requests = {
102
104
  status: { type: 'string', description: 'open, in_progress, blocked, done, cancelled; or "active" for open + in_progress + blocked.' },
103
105
  assignee: { type: 'string', description: 'Case-insensitive substring of the name of the person it is asked of.' },
104
106
  kind: { type: 'string', description: 'batch, tests, samples, review, other.' },
105
- entity_type: { type: 'string', description: 'The linked record\'s type (formulation, batch, sample, testResult, project).' },
107
+ entity_type: { type: 'string', description: 'The linked record\'s type (formulation, batch, sample, testResult, project), or a shared saved view (view:doe, view:compare, …).' },
106
108
  entity_id: { type: 'string', description: 'The linked record (internal id or UID).' },
107
109
  late_only: { type: 'boolean', description: 'true = only active requests past their due date.' },
108
110
  limit: { type: 'number', description: 'Max rows (default 100, max 1000).' },
package/vendor/cost.js CHANGED
@@ -2646,9 +2646,9 @@ function openCostOverrideModal(kind, id) {
2646
2646
  Computed cost is <strong>${compStr}</strong>. Enter a manual override to record the actual cost — it'll be flagged on the detail page whenever it diverges from the live computed value.
2647
2647
  </p>
2648
2648
  <label style="font-size:12px;font-weight:600;display:block;margin-bottom:4px">Override (${esc(ccy)})</label>
2649
- <input id="cost-ov-input" type="number" step="any" value="${esc(String(cur))}" placeholder="${computed != null ? (+computed).toPrecision(4) : ''}" style="width:100%;padding:7px 9px;border:1px solid var(--border);border-radius:6px;font-size:14px" autofocus />
2649
+ <input id="cost-ov-input" type="number" step="any" value="${esc(String(cur))}" placeholder="${computed != null ? (+computed).toPrecision(4) : ''}" style="width:100%;padding:7px 9px;border:1px solid var(--border);border-radius:10px;font-size:14px" autofocus />
2650
2650
  <label style="font-size:12px;font-weight:600;display:block;margin:12px 0 4px">Reason <span style="font-weight:400;color:var(--text-muted)">(optional)</span></label>
2651
- <input id="cost-ov-note" type="text" value="${esc(String(curNote))}" placeholder="e.g. actual lot price incl. freight &amp; MOQ" style="width:100%;padding:7px 9px;border:1px solid var(--border);border-radius:6px;font-size:13px" />
2651
+ <input id="cost-ov-note" type="text" value="${esc(String(curNote))}" placeholder="e.g. actual lot price incl. freight &amp; MOQ" style="width:100%;padding:7px 9px;border:1px solid var(--border);border-radius:10px;font-size:13px" />
2652
2652
  <p style="font-size:11.5px;color:var(--text-muted);margin-top:8px">Leave the override blank and save to clear it (and its reason) and fall back to the computed cost.</p>`;
2653
2653
  showModal(`${kind === 'sample' ? 'Sample' : 'Batch'} cost override`, body, () => _saveCostOverride(kind, id));
2654
2654
  }
@@ -619,10 +619,71 @@ function _tpBuildRows(composition) {
619
619
  Object.defineProperty(rows, 'needsDensity', { value: [...new Set(noDensity)], enumerable: false });
620
620
  }
621
621
  }
622
+ _tpHarmonizeUnits(rows);
622
623
  rows.forEach(r => { delete r._srcIng; delete r._srcSub; });
623
624
  return rows;
624
625
  }
625
626
 
627
+ // One unit per field before any formula reads it (49z). Custom fields are
628
+ // typed per ingredient, so sodium in mg/100g on one and g/100g on another was
629
+ // off by 1000× (17g only flagged it). Within a family the value is converted:
630
+ // mass per mass (%, g/100g, mg/100g, g/kg, mg/kg, ppm, ppb …) and energy per
631
+ // mass (kcal/100g, kJ/100g …). The target is the field's usual unit when the
632
+ // presets read it in one (sodium mg/100g, protein g/100g, solids %), else the
633
+ // unit most of these rows already use. Rows with no unit are left as they are;
634
+ // units from different families stay mixed and are still flagged.
635
+ // Same starters as js/views/ingredients.js CUSTOM_FIELD_STARTERS.
636
+ const _TP_USUAL_UNIT = { protein: 'g/100g', carb: 'g/100g', fat: 'g/100g', sugar: 'g/100g', fiber: 'g/100g', sodium: 'mg/100g', solids: '%' };
637
+ const _TP_UNIT_FAMILY = {
638
+ // grams of the thing per gram of ingredient
639
+ '%': ['m', 0.01], 'wt%': ['m', 0.01], '%w/w': ['m', 0.01], 'w/w%': ['m', 0.01], 'w/w': ['m', 0.01], 'g/100g': ['m', 0.01],
640
+ 'mg/100g': ['m', 1e-5], 'µg/100g': ['m', 1e-8], 'g/kg': ['m', 1e-3], 'mg/g': ['m', 1e-3], 'g/g': ['m', 1],
641
+ 'mg/kg': ['m', 1e-6], 'µg/g': ['m', 1e-6], 'ppm': ['m', 1e-6], 'µg/kg': ['m', 1e-9], 'ppb': ['m', 1e-9],
642
+ // kJ per gram
643
+ 'kj/g': ['e', 1], 'kj/100g': ['e', 0.01], 'kj/kg': ['e', 0.001], 'kcal/g': ['e', 4.184], 'kcal/100g': ['e', 0.04184], 'kcal/kg': ['e', 0.004184], 'cal/g': ['e', 0.004184],
644
+ };
645
+ function _tpUnitKey(u) {
646
+ return String(u || '').trim().toLowerCase().replace(/\s+/g, '').replace(/^(mc|u)g/, 'µg').replace(/\/(mc|u)g/, '/µg');
647
+ }
648
+ function _tpUnitFactor(u) { return _TP_UNIT_FAMILY[_tpUnitKey(u)] || null; }
649
+ function _tpHarmonizeUnits(rows) {
650
+ const fields = new Set();
651
+ rows.forEach(r => Object.keys(r._cfUnits || {}).forEach(k => fields.add(k)));
652
+ const done = [];
653
+ fields.forEach(lk => {
654
+ const withUnit = rows.filter(r => r._cfUnits && r._cfUnits[lk] && r.ing && typeof r.ing[lk] === 'number' && Number.isFinite(r.ing[lk]));
655
+ const units = [...new Set(withUnit.map(r => r._cfUnits[lk]))];
656
+ if (units.length < 2) return;
657
+ // One unit, two spellings (ug/100g, µg/100g): one label, nothing to convert.
658
+ if (new Set(units.map(_tpUnitKey)).size < 2) { withUnit.forEach(r => { r._cfUnits[lk] = units[0]; }); return; }
659
+ const fams = new Set(units.map(u => (_tpUnitFactor(u) || ['?' + u])[0]));
660
+ if (fams.size !== 1 || [...fams][0][0] === '?') return; // not one convertible family: stays flagged
661
+ const usual = _TP_USUAL_UNIT[lk];
662
+ let target = usual && _tpUnitFactor(usual) && _tpUnitFactor(usual)[0] === [...fams][0] ? usual : null;
663
+ if (!target) {
664
+ // Counted by unit, not spelling (ug/100g = µg/100g); the unit's own spelling wins a tie.
665
+ const n = {}, order = [];
666
+ withUnit.forEach(r => { const k = _tpUnitKey(r._cfUnits[lk]); if (!(k in n)) { n[k] = 0; order.push(k); } n[k]++; });
667
+ const key = order.slice().sort((a, b) => (n[b] - n[a]) || order.indexOf(a) - order.indexOf(b))[0];
668
+ const spell = units.filter(u => _tpUnitKey(u) === key);
669
+ target = spell.find(u => u.replace(/\s+/g, '') === key) || spell[0];
670
+ }
671
+ const tf = _tpUnitFactor(target)[1];
672
+ const moved = [];
673
+ withUnit.forEach(r => {
674
+ const u = r._cfUnits[lk];
675
+ if (_tpUnitKey(u) === _tpUnitKey(target)) { r._cfUnits[lk] = target; return; }
676
+ const key = Object.keys(r.ing).find(k => k.toLowerCase() === lk);
677
+ if (!key) return;
678
+ r.ing[key] = +(r.ing[key] * _tpUnitFactor(u)[1] / tf).toPrecision(12);
679
+ r._cfUnits[lk] = target;
680
+ moved.push({ name: r.ing._isSubFormula ? (r._subName || 'sub-formula') : (r.ing.name || '(unnamed)'), from: u });
681
+ });
682
+ if (moved.length) done.push({ field: lk, to: target, rows: moved });
683
+ });
684
+ if (done.length) Object.defineProperty(rows, 'unitConversions', { value: done, enumerable: false, configurable: true });
685
+ }
686
+
626
687
  // A premix's fields for its row in the parent (Jun, 28 Oct: "yes to per-field rules"). A field rolls up as the
627
688
  // mass-weighted mean over the premix's rows when it adds by mass: a custom field in a per-mass unit (%, g/100 g,
628
689
  // mg/kg, ppm, mg KOH/g …), or a known per-mass name with no unit (solids, NV %, protein, fat …). Only when every row
@@ -965,6 +1026,17 @@ function _tpReplaceSpans(formula, spans, repl) {
965
1026
  spans.forEach((sp, k) => { out += formula.slice(cur, sp.start) + repl(k); cur = sp.end; });
966
1027
  return out + formula.slice(cur);
967
1028
  }
1029
+ // "sodium: 2 rows in g/100g read as mg/100g" under Show calc, for the fields this formula reads (49z).
1030
+ function _tpConvNoteHtml(formula, rows) {
1031
+ const conv = rows && rows.unitConversions;
1032
+ if (!conv || !conv.length) return '';
1033
+ const used = new Set(_tpFieldRefs(formula));
1034
+ const lines = conv.filter(c => used.has(c.field)).map(c => {
1035
+ const from = [...new Set(c.rows.map(r => r.from))].join(', ');
1036
+ return `<span title="${esc(c.rows.map(r => `${r.name}: ${r.from} → ${c.to}`).join('\n'))}">${esc(c.field)}: ${c.rows.length} row${c.rows.length === 1 ? '' : 's'} in ${esc(from)} read as ${esc(c.to)}</span>`;
1037
+ });
1038
+ return lines.length ? `<div class="tp-conv-note" style="margin-top:6px;font-size:11.5px;color:var(--text-muted)">Units converted: ${lines.join(' · ')}</div>` : '';
1039
+ }
968
1040
  function _tpCalcHtml(p, evalRows, valueMap) {
969
1041
  const formula = String(p.formula || '');
970
1042
  const refs = (typeof _tpScanParamRefs === 'function') ? _tpScanParamRefs(formula) : [];
@@ -1067,6 +1139,7 @@ function _tpCalcHtml(p, evalRows, valueMap) {
1067
1139
  return `<div style="padding:12px 14px;background:var(--dk-subtle, #f8fafc);border-top:1px solid var(--dk-line-soft, #e2e8f0);font-size:12px;color:var(--text);overflow-x:auto">
1068
1140
  ${refBits.length ? `<div style="font-size:11.5px;color:var(--text-muted);margin-bottom:6px">References: ${refBits.join(' &nbsp;·&nbsp; ')}</div>` : ''}
1069
1141
  ${tableHtml || (refBits.length ? '' : '<div style="color:var(--text-muted);font-size:11px">Value comes straight from the expression (no row aggregation).</div>')}
1142
+ ${_tpConvNoteHtml(formula, evalRows)}
1070
1143
  ${resultHtml}
1071
1144
  </div>`;
1072
1145
  }