formlab-mcp 0.6.73 → 0.6.74
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 +1 -1
- package/server.json +2 -2
- package/vendor/cost.js +2 -2
- package/vendor/theoretical-params.js +73 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "formlab-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.74",
|
|
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.
|
|
5
|
+
"version": "0.6.74",
|
|
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.
|
|
11
|
+
"version": "0.6.74",
|
|
12
12
|
"runtimeHint": "npx",
|
|
13
13
|
"transport": {
|
|
14
14
|
"type": "stdio"
|
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:
|
|
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 & MOQ" style="width:100%;padding:7px 9px;border:1px solid var(--border);border-radius:
|
|
2651
|
+
<input id="cost-ov-note" type="text" value="${esc(String(curNote))}" placeholder="e.g. actual lot price incl. freight & 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(' · ')}</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
|
}
|