formlab-mcp 0.6.91 → 0.6.93

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
@@ -36,13 +36,13 @@ Ask Claude (or another MCP client) things like:
36
36
  | `compare_formulations` | Pairwise side-by-side composition diff |
37
37
  | `list_ingredients` | Filtered list of raw materials. Filters: `family`, `supplier`, `name_contains`, `lot_number` (the ingredient a lot belongs to), `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`) |
38
38
  | `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) |
39
- | `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`, `lot_number`, `expiring_within_days`, `status` (e.g. `hold` to find lots held for a recall), `missing_coa` |
39
+ | `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 `holdAt` — 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`, `lot_number`, `expiring_within_days`, `status` (e.g. `hold` to find lots held for a recall), `missing_coa` |
40
40
  | `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 |
41
41
  | `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) |
42
42
  | `list_documents` | The document register (same as the app's Documents page): ingredient SDS / PDS / CoA / other with lot, version, source and expiry; test and notebook attachments; per-record uploads and links (formulas, batches, samples, suppliers, equipment…). File **metadata** only, never the text inside a file, with who added each file (`addedBy`) and when. Filters: `type`, `record`, `linked`, `query`, `lot`, `format`, `expiry`, `expiring_within_days`, `without_expiry`, `uploaded_within_days`, `added_by`. A `summary` block carries the page's tile counts: expired, expiring in 30 days, SDS/CoA without expiry, ingredients missing an SDS (+ coverage %), lots in stock without a CoA, added last 7 days |
43
- | `list_inventory` | Portfolio stock rollup — one row per ingredient with on-hand qty, summed lot balance, nearest expiry, and a low-stock flag (on-hand ≤ `reorderThreshold`, or zero). Filters: `low_stock_only`, `expiring_within_days`, `family` |
44
- | `list_batches` | Filtered list of production / lab-prep events; each row has **`bestBy`**; filter by `best_by_before` (past best-by = today) or `lots_expire_first` |
45
- | `get_batch` | Full record + actual composition, measured/derived **actual volume** (mass ÷ density, never a sum of per-ingredient volumes) and **actual mass** (yield, else summed as-prepared inputs — mL rows through that ingredient's density — else measured volume × density), **estimatedVolume** (mass ÷ the formula's finished density when no actual exists, flagged `estimate: true`), **plannedMass** for volume-target batches (target × finished density) and **formulaFinishedDensity**, the **process** method + any **process-factor values** (DOE inputs), samples + blend lineage, and — as a finished-goods lot — its **`bestBy`** (the adjusted date with its change, reason, note and retest report, else prepared date + shelf life; `lotsExpiringFirst` = lots it drew from that expire sooner), its storage **`location`** + finished-goods **`stockLedger`** (shipments out + adjustments; `shippedQty` total), and its **theoretical parameters computed on the batch as made** (actual composition when logged — `basis: "actual"` — else the recipe; the batch's own parameter list when it overrides the formula's) |
43
+ | `list_inventory` | Portfolio stock rollup — one row per ingredient with on-hand qty, summed lot balance, nearest expiry, a low-stock flag (on-hand ≤ `reorderThreshold`, or zero), and stock on hold (`heldQty` plus `lotsOnHold`: lot number, quantity, reason, since; a held lot with stock left). Filters: `low_stock_only`, `expiring_within_days`, `on_hold_only`, `family` |
44
+ | `list_batches` | Filtered list of production / lab-prep events; each row has **`bestBy`**; filter by `best_by_before` (past best-by = today) or `lots_expire_first`, `on_hold`, `made_with_lot` (batches that drew from a recalled lot), `held_lot` (drew from any lot now on hold) |
45
+ | `get_batch` | Full record + **`lotsUsed`** (raw lots drawn, with each lot's status and hold reason now) + actual composition, measured/derived **actual volume** (mass ÷ density, never a sum of per-ingredient volumes) and **actual mass** (yield, else summed as-prepared inputs — mL rows through that ingredient's density — else measured volume × density), **estimatedVolume** (mass ÷ the formula's finished density when no actual exists, flagged `estimate: true`), **plannedMass** for volume-target batches (target × finished density) and **formulaFinishedDensity**, the **process** method + any **process-factor values** (DOE inputs), samples + blend lineage, and — as a finished-goods lot — its **`bestBy`** (the adjusted date with its change, reason, note and retest report, else prepared date + shelf life; `lotsExpiringFirst` = lots it drew from that expire sooner), its storage **`location`** + finished-goods **`stockLedger`** (shipments out + adjustments; `shippedQty` total), and its **theoretical parameters computed on the batch as made** (actual composition when logged — `basis: "actual"` — else the recipe; the batch's own parameter list when it overrides the formula's) |
46
46
  | `list_samples` | Filtered list of physical specimens |
47
47
  | `get_sample` | Full record + canonical variant + test reports + blend lineage + its stability pulls (next pull, or pulled at) |
48
48
  | `list_test_results` | Filtered list of test reports (by sample, parameter, **measured-value range** (`value_min`/`value_max` — a curve at its final point, a distribution at its spec's statistic or D50), **grade** (`min_grade`/`max_grade` on a ranked scale), **text value** (`value_equals`), **run condition** (`condition`), date, or lab) |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.91",
3
+ "version": "0.6.93",
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.91",
5
+ "version": "0.6.93",
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.91",
11
+ "version": "0.6.93",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -220,6 +220,8 @@ const get_ingredient = {
220
220
  qtyRemaining: l.qtyRemaining, qtyReceived: l.qtyReceived, unit: l.unit || '',
221
221
  receivedDate: l.receivedDate || null, expiryDate: l.expiryDate || null,
222
222
  supplier: l.supplier || '', supplierId: l.supplierId || null, status: l.status || 'active',
223
+ // 0.6.93: why and since when a lot is on hold (QC / recall).
224
+ hold: l.status === 'hold' ? { reason: l.holdReason || '', since: l.holdAt || null } : null,
223
225
  sourceId: l.sourceId || null, source: _lotSourceInfo(l),
224
226
  ..._lotCoaInfo(l, ing),
225
227
  }));
@@ -398,6 +400,7 @@ const list_lots = {
398
400
  // 'hold' / 'quarantine' / 'rejected' lots are blocked from auto-consumption;
399
401
  // holdReason explains a manual hold (QC / recall).
400
402
  holdReason: l.holdReason || '',
403
+ holdAt: l.status === 'hold' ? (l.holdAt || null) : null, // 0.6.93: since when it is held
401
404
  // A disposed lot: when, why, how much was written off (status is then "disposed").
402
405
  disposal: l.status === 'disposed' ? { date: l.disposedAt || null, by: l.disposedBy || '', reason: l.disposeReason || '', note: l.disposeNote || '', qty: l.disposedQty ?? null } : null,
403
406
  unitCost: (l.unitCost != null && l.unitCost !== '') ? l.unitCost : null,
@@ -424,6 +427,7 @@ const list_inventory = {
424
427
  properties: {
425
428
  low_stock_only: { type: 'boolean', description: 'Only ingredients flagged low (on-hand ≤ reorderThreshold, or on-hand is 0).' },
426
429
  expiring_within_days: { type: 'number', description: 'Only ingredients with a lot expiring within this many days from now (already-expired lots always qualify).' },
430
+ on_hold_only: { type: 'boolean', description: 'Only ingredients with a lot on hold that still has stock (the app\'s Inventory "On hold" tile). heldQty says how much of the on-hand is held.' },
427
431
  family: { type: 'string', description: 'Filter by ingredient family. Case-insensitive substring.' },
428
432
  limit: { type: 'number', description: 'Max rows (default 200, max 1000).' },
429
433
  },
@@ -453,6 +457,9 @@ const list_inventory = {
453
457
  const expiries = lots.map(l => Date.parse(l.expiryDate)).filter(isFinite);
454
458
  const nearestExpiryMs = expiries.length ? Math.min(...expiries) : null;
455
459
  const lowStock = (onHand === 0) || (onHand != null && reorder != null && onHand <= reorder);
460
+ // 0.6.93: lots on hold with stock left. Held stock still counts in on-hand but can't be used until released.
461
+ const heldLots = lots.filter(l => l.status === 'hold' && Number(l.qtyRemaining) > 0);
462
+ const heldQty = heldLots.reduce((s, l) => s + Number(l.qtyRemaining), 0);
456
463
  return {
457
464
  id: i.id, uid: i.uid, name: i.name || '', family: i.family || '',
458
465
  stockOnHand: onHand, stockUnit: i.stockUnit || null,
@@ -462,9 +469,12 @@ const list_inventory = {
462
469
  nearestExpiry: nearestExpiryMs != null ? new Date(nearestExpiryMs).toISOString().slice(0, 10) : null,
463
470
  daysToNearestExpiry: nearestExpiryMs != null ? Math.floor((nearestExpiryMs - nowMs) / 86400000) : null,
464
471
  lowStock,
472
+ heldQty: heldLots.length ? +heldQty.toFixed(6) : 0,
473
+ lotsOnHold: heldLots.map(l => ({ lotNumber: l.lotNumber || l.uid || '', qty: Number(l.qtyRemaining), unit: l.unit || '', reason: l.holdReason || '', since: l.holdAt || null })),
465
474
  };
466
475
  }).filter(r => {
467
476
  if (args.low_stock_only && !r.lowStock) return false;
477
+ if (args.on_hold_only && !(r.heldQty > 0)) return false;
468
478
  if (args.expiring_within_days != null) {
469
479
  if (r.daysToNearestExpiry == null) return false;
470
480
  if (r.daysToNearestExpiry > args.expiring_within_days) return false;
@@ -480,6 +490,7 @@ const list_inventory = {
480
490
  totalMatching: rows.length,
481
491
  returned: Math.min(rows.length, limit),
482
492
  lowStockCount: rows.filter(r => r.lowStock).length,
493
+ onHoldCount: rows.filter(r => r.heldQty > 0).length,
483
494
  inventory: rows.slice(0, limit),
484
495
  };
485
496
  },
package/tools/lab.js CHANGED
@@ -284,10 +284,26 @@ function _trimSample(s, formulationsById, batchesById) {
284
284
  };
285
285
  }
286
286
 
287
+ // Raw lots a batch drew, net of material returned to the lot, with each lot's status now (0.6.92).
288
+ function _batchLotsUsed(db, batchId) {
289
+ const net = new Map();
290
+ (db.stockMovements || []).forEach(m => {
291
+ if (!m || m.batchId !== batchId || !m.lotId) return;
292
+ const d = Number(m.delta); if (!Number.isFinite(d)) return;
293
+ net.set(m.lotId, (net.get(m.lotId) || 0) - d);
294
+ });
295
+ return [...net].filter(([, q]) => q > 0.0000005).map(([lotId, q]) => {
296
+ const l = (db.lots || []).find(x => x && x.id === lotId) || {};
297
+ const ing = (db.ingredients || []).find(i => i && i.id === l.ingredientId);
298
+ return { lotId, lotUid: l.uid || '', lotNumber: l.lotNumber || '', ingredient: ing ? (ing.uid || ing.name || '') : '', ingredientName: ing ? (ing.name || '') : '',
299
+ qty: Math.round(q * 1e6) / 1e6, unit: l.unit || '', status: l.status || 'active', holdReason: l.status === 'hold' ? (l.holdReason || '') : '' };
300
+ });
301
+ }
302
+
287
303
  const list_batches = {
288
304
  definition: {
289
305
  name: 'list_batches',
290
- description: 'List batches (production / lab-prep events), optionally filtered by formulation, status, origin-only (hides batches derived from other batches), best-by before a date, or batches whose ingredient lots expire before their best-by. Each row carries `bestBy` (date, adjusted or from shelf life, the reason, lots expiring first). Returns metadata; use get_batch for the full consumption ledger and samples.',
306
+ description: 'List batches (production / lab-prep events), optionally filtered by formulation, status, origin-only (hides batches derived from other batches), best-by before a date, batches whose ingredient lots expire before their best-by, batches made with a given raw lot (made_with_lot), or with a lot now on hold (held_lot). Each row carries `bestBy` (date, adjusted or from shelf life, the reason, lots expiring first). Returns metadata; use get_batch for the full consumption ledger and samples.',
291
307
  inputSchema: {
292
308
  type: 'object',
293
309
  properties: {
@@ -299,6 +315,8 @@ const list_batches = {
299
315
  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
316
  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
317
  on_hold: { type: 'boolean', description: 'When true, only finished batches currently on hold (no shipment can be recorded until released).' },
318
+ made_with_lot: { type: 'string', description: 'Only batches that drew from this raw lot: its lot number (e.g. "BIT-9912", from a supplier recall), lot UID, or internal id. Answers "which batches used the recalled lot?"; pair with on_hold to see which are not held yet.' },
319
+ held_lot: { type: 'boolean', description: 'When true, only batches that drew from a raw lot now on hold, whether or not the batch itself is held.' },
302
320
  limit: { type: 'number', description: 'Max rows (default 50, max 500).' },
303
321
  },
304
322
  },
@@ -314,8 +332,18 @@ const list_batches = {
314
332
  if (!f) return { error: `No formulation matched "${args.formulation_id}".` };
315
333
  formId = f.id;
316
334
  }
335
+ let lotBatches = null;
336
+ if (args.made_with_lot) {
337
+ const w = norm(args.made_with_lot).trim();
338
+ const lotIds = new Set((db.lots || []).filter(l => l && !l._trashed && (l.id === args.made_with_lot || norm(l.uid) === w || norm(l.lotNumber) === w)).map(l => l.id));
339
+ if (!lotIds.size) return { error: `No lot matched "${args.made_with_lot}" (lot number, lot UID, or id).` };
340
+ lotBatches = new Set((db.stockMovements || []).filter(m => m && lotIds.has(m.lotId) && m.batchId && Number(m.delta) < 0).map(m => m.batchId));
341
+ }
342
+ const heldBatches = args.held_lot ? (() => { const held = new Set((db.lots || []).filter(l => l && !l._trashed && l.status === 'hold').map(l => l.id)); return new Set((db.stockMovements || []).filter(m => m && held.has(m.lotId) && m.batchId && Number(m.delta) < 0).map(m => m.batchId)); })() : null;
317
343
  const filtered = (db.batches || []).filter(b => {
318
344
  if (!b || b._trashed) return false;
345
+ if (lotBatches && !lotBatches.has(b.id)) return false;
346
+ if (heldBatches && !heldBatches.has(b.id)) return false;
319
347
  if (formId && b.formulationId !== formId) return false;
320
348
  if (args.status && !norm(b.status).includes(norm(args.status))) return false;
321
349
  if (args.origin_only && b.parentBatchId) return false;
@@ -341,7 +369,7 @@ const list_batches = {
341
369
  const get_batch = {
342
370
  definition: {
343
371
  name: 'get_batch',
344
- description: 'Get full details for a single batch including its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation.',
372
+ description: 'Get full details for a single batch including the raw lots it drew (lotsUsed: lot number, quantity, and the status of each lot now, with holdReason for a lot on hold), its actual composition (as-prepared, when logged), child samples, lineage (parent / sub-blend parents), and — treating the batch as a finished-goods lot — its storage `location` and finished-goods `stockLedger` (shipments out + adjustments; on-hand = produced − sample pulls − sub-batch draws + Σ ledger). Plus finished-product density + actual volume (measured directly or derived as actual mass ÷ measured density — never summed from per-ingredient volumes). Accepts internal id or UID. Also returns `theoreticalParameters` computed on the batch as made (its actual composition when logged — `basis: "actual"` — else the recipe of its formula), with the batch parameter list when it overrides the one on the formula; same fields as get_formulation.',
345
373
  inputSchema: {
346
374
  type: 'object',
347
375
  properties: {
@@ -391,6 +419,9 @@ const get_batch = {
391
419
  shippedQty: (Array.isArray(b.stockLedger) ? b.stockLedger : []).reduce((s, e) => e.kind === 'shipment' ? s + Math.abs(parseFloat(e.delta) || 0) : s, 0),
392
420
  // Finished-batch hold: while set, the app records no shipment of this batch (QA / complaint / recall).
393
421
  hold: (b.fgHold && b.fgHold.at) ? { since: b.fgHold.at, by: b.fgHold.by || '', reason: b.fgHold.reason || '' } : null,
422
+ // 0.6.92: the raw lots this batch drew (net of returns), each with its status now. A lot on hold
423
+ // here ("status: hold" + holdReason) is why a recall reaches this batch, held or not.
424
+ lotsUsed: _batchLotsUsed(getStore().db, b.id),
394
425
  theoreticalParameters: theoreticalParams(getStore().db, 'batch', b.id),
395
426
  };
396
427
  },