formlab-mcp 0.6.88 → 0.6.89

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.88",
3
+ "version": "0.6.89",
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.88",
5
+ "version": "0.6.89",
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.88",
11
+ "version": "0.6.89",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -393,6 +393,8 @@ const list_lots = {
393
393
  // 'hold' / 'quarantine' / 'rejected' lots are blocked from auto-consumption;
394
394
  // holdReason explains a manual hold (QC / recall).
395
395
  holdReason: l.holdReason || '',
396
+ // A disposed lot: when, why, how much was written off (status is then "disposed").
397
+ disposal: l.status === 'disposed' ? { date: l.disposedAt || null, by: l.disposedBy || '', reason: l.disposeReason || '', note: l.disposeNote || '', qty: l.disposedQty ?? null } : null,
396
398
  unitCost: (l.unitCost != null && l.unitCost !== '') ? l.unitCost : null,
397
399
  unitCostCcy: l.unitCostCcy || null,
398
400
  ..._lotCoaInfo(l, ingById.get(l.ingredientId)),
package/tools/lab.js CHANGED
@@ -297,6 +297,8 @@ const list_batches = {
297
297
  since_date: { type: 'string', description: 'ISO date (YYYY-MM-DD). Only batches prepared on/after this date.' },
298
298
  best_by_before: { type: 'string', description: 'ISO date (YYYY-MM-DD). Only batches whose best-by falls before this date (today = past best-by). Batches with no best-by are left out.' },
299
299
  lots_expire_first: { type: 'boolean', description: 'When true, only batches that drew from an ingredient lot expiring before the batch\'s best-by (the app\'s ⚠ on Best by).' },
300
+ shipped_to: { type: 'string', description: 'Only batches with a shipment whose note (customer / destination / PO) contains this text, case-insensitive. Use it to find which batch went to a customer.' },
301
+ on_hold: { type: 'boolean', description: 'When true, only finished batches currently on hold (no shipment can be recorded until released).' },
300
302
  limit: { type: 'number', description: 'Max rows (default 50, max 500).' },
301
303
  },
302
304
  },
@@ -318,6 +320,8 @@ const list_batches = {
318
320
  if (args.status && !norm(b.status).includes(norm(args.status))) return false;
319
321
  if (args.origin_only && b.parentBatchId) return false;
320
322
  if (args.since_date && (b.preparedDate || '') < args.since_date) return false;
323
+ if (args.shipped_to && !(Array.isArray(b.stockLedger) && b.stockLedger.some(e => e && e.kind === 'shipment' && norm(e.note).includes(norm(args.shipped_to))))) return false;
324
+ if (args.on_hold && !(b.fgHold && b.fgHold.at)) return false;
321
325
  if (args.best_by_before || args.lots_expire_first) {
322
326
  const bb = _bestByInfo(b, b.formulationId ? indexes.formulationsById.get(b.formulationId) : null);
323
327
  if (!bb) return false;
@@ -385,6 +389,8 @@ const get_batch = {
385
389
  date: e.ts || null, delta: e.delta ?? null, unit: e.unit || b.unit || '', kind: e.kind || '', note: e.note || '',
386
390
  })),
387
391
  shippedQty: (Array.isArray(b.stockLedger) ? b.stockLedger : []).reduce((s, e) => e.kind === 'shipment' ? s + Math.abs(parseFloat(e.delta) || 0) : s, 0),
392
+ // Finished-batch hold: while set, the app records no shipment of this batch (QA / complaint / recall).
393
+ hold: (b.fgHold && b.fgHold.at) ? { since: b.fgHold.at, by: b.fgHold.by || '', reason: b.fgHold.reason || '' } : null,
388
394
  theoreticalParameters: theoreticalParams(getStore().db, 'batch', b.id),
389
395
  };
390
396
  },
package/vendor/cost.js CHANGED
@@ -1716,24 +1716,32 @@ function deviationLegendHtml() {
1716
1716
  // Used by the batch AND sample weigh-outs so both correct identically. This is
1717
1717
  // a bench/weigh-out concept only — composition, cost, and property math keep
1718
1718
  // using the as-declared amounts.
1719
- function effectivePurity(ing) {
1719
+ function effectivePurity(ing, pinLotId) {
1720
1720
  if (!ing) return null;
1721
1721
  const nom = parseFloat(ing.purity);
1722
1722
  if (isFinite(nom) && nom > 0) return nom < 100 ? nom : null;
1723
- // No usable nominal → fall back to a representative active lot with purity.
1723
+ // LP1 (19 Nov): a batch that pins a lot for this ingredient draws that lot first, so its purity is the one weighed.
1724
+ if (pinLotId && typeof db !== 'undefined' && Array.isArray(db.lots)) {
1725
+ const pl = db.lots.find(l => l && l.id === pinLotId && l.ingredientId === ing.id);
1726
+ if (pl && (parseFloat(pl.qtyRemaining) || 0) > 0 && (typeof _lotIsUsable !== 'function' || _lotIsUsable(pl))) {
1727
+ const pp = parseFloat(pl.purity);
1728
+ return (isFinite(pp) && pp > 0 && pp < 100) ? pp : null;
1729
+ }
1730
+ }
1731
+ // No usable nominal → the purity of the lot the next draw takes (the lab's FEFO / FIFO rule over every usable lot),
1732
+ // if that lot has one. It used to pick the first lot WITH a purity, so a trial drum's 68.5% grossed up a batch that
1733
+ // drew a different supplier's lot with none (supplier-swap sim, 19 Nov: +46% SLES). No lot rule (off) → no fallback.
1724
1734
  const lots = (typeof db !== 'undefined' && Array.isArray(db.lots))
1725
- ? db.lots.filter(l => l.ingredientId === ing.id
1726
- && (parseFloat(l.qtyRemaining) || 0) > 0
1727
- && (!l.status || l.status === 'active')
1728
- && l.purity != null && isFinite(parseFloat(l.purity)) && parseFloat(l.purity) > 0)
1735
+ ? db.lots.filter(l => l.ingredientId === ing.id && (parseFloat(l.qtyRemaining) || 0) > 0
1736
+ && (typeof _lotIsUsable === 'function' ? _lotIsUsable(l) : (!l.status || l.status === 'active')))
1729
1737
  : [];
1730
1738
  if (!lots.length) return null;
1731
- lots.sort((a, b) => {
1732
- const ax = a.expiryDate || '9999-12-31', bx = b.expiryDate || '9999-12-31';
1733
- if (ax !== bx) return ax < bx ? -1 : 1;
1734
- return (a.receivedDate || '').localeCompare(b.receivedDate || '');
1735
- });
1736
- const p = parseFloat(lots[0].purity);
1739
+ const strat = (typeof _lotStrategy === 'function') ? _lotStrategy() : 'fefo';
1740
+ if (strat === 'off') return null;
1741
+ const ordered = (typeof sortLotsForConsumption === 'function') ? sortLotsForConsumption(lots, strat === 'fifo' ? 'fifo' : 'fefo')
1742
+ : lots.slice().sort((a, b) => { const ax = a.expiryDate || '9999-12-31', bx = b.expiryDate || '9999-12-31';
1743
+ return ax !== bx ? (ax < bx ? -1 : 1) : (a.receivedDate || '').localeCompare(b.receivedDate || ''); });
1744
+ const p = parseFloat((ordered[0] || {}).purity);
1737
1745
  return (isFinite(p) && p > 0 && p < 100) ? p : null;
1738
1746
  }
1739
1747
 
@@ -1773,12 +1781,12 @@ function lotPurityDeviation(ing, opts) {
1773
1781
  // model — other rows are NOT rebalanced). Returns the amount technicians
1774
1782
  // weigh, the purity used, and the active amount it delivers. Sub-formula rows
1775
1783
  // and rows with no purity data pass through unchanged.
1776
- function correctAmountForPurity(comp, amt) {
1784
+ function correctAmountForPurity(comp, amt, pins) {
1777
1785
  const passthrough = { amount: amt, purity: null, activeAmount: amt };
1778
1786
  if (!comp || !comp.ingredientId || amt == null || !isFinite(amt)) return passthrough;
1779
1787
  const ing = (typeof db !== 'undefined' && Array.isArray(db.ingredients))
1780
1788
  ? db.ingredients.find(i => i.id === comp.ingredientId) : null;
1781
- const p = effectivePurity(ing);
1789
+ const p = effectivePurity(ing, pins && ing ? pins[ing.id] : null);
1782
1790
  if (p == null || !(p > 0) || p >= 100) return passthrough;
1783
1791
  return { amount: amt / (p / 100), purity: p, activeAmount: amt };
1784
1792
  }
@@ -2092,7 +2100,7 @@ function renderWeighoutPanel(w, actuals, formula, copyOnclick, noun) {
2092
2100
  return (inAlt != null && isFinite(inAlt)) ? `<strong>${fmt(inAlt)}</strong> <span translate="no" style="color:var(--dk-faint, #94a3b8);font-size:10px">${esc(altUnit)}</span>` : null;
2093
2101
  })();
2094
2102
  const tfoot = `<tr style="border-top:1px solid #dbeafe">
2095
- <td></td><td style="padding:5px 8px;font-weight:600">Total${_volTarget ? ` <span style="font-weight:400;color:var(--dk-faint, #94a3b8);font-size:10.5px" title="Sum of the pure-ingredient volumes in the Planned column. Not a lab quantity — the finished batch is ${esc(w.qty)} ${esc(w.unit)}; the mass in the ≈ column is what the batch weighs.">(pure-ingredient volumes)</span>` : ''}</td>
2103
+ <td></td><td style="padding:5px 8px;font-weight:600">Total${_volTarget ? ` <span style="font-weight:400;color:var(--dk-faint, #94a3b8);font-size:10.5px" title="Sum of ingredient volumes in the Planned column. The finished batch is ${esc(w.qty)} ${esc(w.unit)}.">(pure-ingredient volumes)</span>` : ''}</td>
2096
2104
  <td style="padding:5px 8px;text-align:right;font-variant-numeric:tabular-nums;font-weight:${_volTarget ? 400 : 700};color:${_volTarget ? 'var(--dk-faint, #94a3b8)' : 'inherit'}" title="${_volTarget ? `Volumes aren't additive on mixing — this sum has no bench meaning. Finished batch: ${esc(w.qty)} ${esc(w.unit)}.` : ''}">${cv(w.total)}</td>
2097
2105
  ${hasActuals ? `<td style="padding:5px 8px;text-align:right;font-variant-numeric:tabular-nums;font-weight:700">${cv(actualTotal)}</td>
2098
2106
  <td style="padding:5px 8px;text-align:right;font-variant-numeric:tabular-nums;color:var(--dk-muted, #64748b)">${cvs(totalDelta)}</td>` : ''}
@@ -2243,7 +2251,7 @@ function defaultPercentBasis(formulation, costSummary) {
2243
2251
  // Approximate kg conversion for batch.targetQuantity.unit. If
2244
2252
  // volume, falls back to *assume kg* unless density is known.
2245
2253
  function computeBatchCost(batch, displayCcy = getDisplayCurrency()) {
2246
- const f = db.formulations.find(x => x.id === batch.formulationId);
2254
+ const f = (typeof flBatchFormula === 'function' ? flBatchFormula(batch) : db.formulations.find(x => x.id === batch.formulationId));
2247
2255
  if (!f) return null;
2248
2256
  const perKg = computeFormulationCost(f, displayCcy);
2249
2257
  // Batch size in kg via the shared quantityToKg (mass units convert directly;
@@ -746,7 +746,7 @@ function flNlTabHtml(f) {
746
746
  <div class="card-body nl-stmt">
747
747
  ${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>
748
748
  ${_nlSuspectHtml(f) || (es.allergens.length ? '' : '<div class="nl-dim">No EU allergens on the ingredients.</div>')}
749
- <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>
749
+ <div class="nl-dim nl-hint" data-tip="The 14 EU allergens from each ingredient’s chips, in CAPITALS on Copy. A label_name custom field prints 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>
750
750
  ${s.contains.length ? `<div class="nl-contains"><strong>CONTAINS:</strong> ${esc(s.contains.join(', '))}.</div>` : ''}${_nlSuspectHtml(f) || (s.contains.length ? '' : '<div class="nl-dim">No major US allergens on the ingredients.</div>')}
751
751
  <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>`}
752
752
  </div>
@@ -455,7 +455,7 @@ function flRxApplySolve(fId) {
455
455
  // ---- A batch: as weighed, and (Pro) against the plan ----
456
456
  function flRxBatchStripHtml(b) {
457
457
  if (!b) return '';
458
- const f = (db.formulations || []).find(x => x.id === b.formulationId);
458
+ const f = (typeof flBatchFormula === 'function' ? flBatchFormula(b) : db.formulations.find(x => x.id === b.formulationId));
459
459
  const hasActual = Array.isArray(b.actualComposition) && b.actualComposition.length;
460
460
  const comp = hasActual ? b.actualComposition : (f ? f.composition : []);
461
461
  const found = flRxPairsFor(comp);
@@ -510,7 +510,7 @@ function flRxFormSectionHtml(ing) {
510
510
  <div class="fl-rx-frows" id="fl-rx-frows">${list.map(_flRxFormRowHtml).join('')}</div>
511
511
  <div class="fl-rx-fhead">
512
512
  <button type="button" class="btn btn-secondary btn-sm" onclick="_flRxFormAdd()">+ Add group</button>
513
- <span class="fl-rx-note" data-tip="EEW for a resin, AHEW for a hardener, OH number for a polyol, NCO % for an isocyanate, acid or amine value; groups per molecule (with the MW) for a pure chemical.">As the datasheet quotes it, or groups per molecule for a pure chemical.</span>
513
+ <span class="fl-rx-note" data-tip="EEW, AHEW, OH number, NCO %, acid or amine value; or groups per molecule (with the MW) for a pure chemical.">As the datasheet quotes it, or groups per molecule for a pure chemical.</span>
514
514
  </div>
515
515
  </div>`;
516
516
  }