formlab-mcp 0.6.70 → 0.6.72

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
@@ -39,8 +39,8 @@ Ask Claude (or another MCP client) things like:
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) |
40
40
  | `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 |
41
41
  | `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` |
42
- | `list_batches` | Filtered list of production / lab-prep events |
43
- | `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 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) |
42
+ | `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` |
43
+ | `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) |
44
44
  | `list_samples` | Filtered list of physical specimens |
45
45
  | `get_sample` | Full record + canonical variant + test reports + blend lineage + its stability pulls (next pull, or pulled at) |
46
46
  | `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.70",
3
+ "version": "0.6.72",
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/peptide.js CHANGED
@@ -25,7 +25,16 @@ const NTERM_SMILES = {
25
25
  };
26
26
  const CTERM_SMILES = { NH2: 'N', OMe: 'OC' };
27
27
 
28
- const tokenize = (raw) => (typeof raw === 'string' && raw) ? raw.split('-').map(s => s.trim()).filter(Boolean) : [];
28
+ // The app's _seqSplit / _seqFreeEnds / _tokenizeSequence (48y): any dash, spaces dropped, /…/ mods whole, and the free
29
+ // ends written out (H-…-OH, H-…-NH2) are the amine and the acid, not His and Hyp + His.
30
+ const SEQ_DASHES = /[\u2010-\u2015\u2212]/g;
31
+ function tokenize(raw) {
32
+ if (!raw || typeof raw !== 'string') return [];
33
+ const t = (raw.replace(SEQ_DASHES, '-').match(/\/[^\/]*\/|[^\/-]+/g) || []).map(s => s.replace(/\s+/g, '')).filter(Boolean);
34
+ const n = t.length, last = t[n - 1];
35
+ const freeN = n >= 3 && t[0] === 'H' && /^(OH|NH2|OMe)$/.test(last), freeC = n >= 2 && last === 'OH';
36
+ return t.slice(freeN ? 1 : 0, freeC ? -1 : undefined);
37
+ }
29
38
  function residues(tokens) {
30
39
  const out = [];
31
40
  for (const tok of tokens) {
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.70",
5
+ "version": "0.6.72",
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.70",
11
+ "version": "0.6.72",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
package/tools/lab.js CHANGED
@@ -132,6 +132,81 @@ function _plannedMassInfo(b, f, batchesById) {
132
132
  return { kg: +(L * fd.value).toFixed(4), unit: 'kg', densityUsed: fd.value, densitySource: fd.source, densityFromBatch: fd.fromBatch, note: 'Each recipe row weighs out to its wt% of this mass; the balance (q.s.) row is filled to the volume mark, so pure-ingredient volumes do not sum to the target.' };
133
133
  }
134
134
 
135
+ // --- Best-by (mirrors js/cost.js batchBestByISO + js/views/batch-stock.js) ----
136
+ // The batch's own adjusted date (Stock tab → Adjust: b.bestByAdjust) wins over
137
+ // prepared date + the formula's shelfLifeMonths. lotsExpiringFirst = lots the
138
+ // batch drew from (net of put-backs) that expire before it, as the app's ⚠:
139
+ // lots in Trash, with no or a broken expiry, or expiring on the day are left out.
140
+ const _ISO_DAY = /^\d{4}-\d{2}-\d{2}$/;
141
+ function _realDay(s) {
142
+ const v = String(s || '').slice(0, 10);
143
+ if (!_ISO_DAY.test(v)) return '';
144
+ const [y, m, d] = v.split('-').map(Number), t = new Date(Date.UTC(y, m - 1, d));
145
+ return (t.getUTCFullYear() === y && t.getUTCMonth() === m - 1 && t.getUTCDate() === d) ? v : '';
146
+ }
147
+ function _shelfLifeISO(f, preparedDate) {
148
+ const m = f && f.shelfLifeMonths;
149
+ if (m == null || m === '' || !isFinite(+m) || +m <= 0) return null;
150
+ const pm = Date.parse(preparedDate);
151
+ if (!isFinite(pm)) return null;
152
+ const d = new Date(pm), day = d.getUTCDate();
153
+ d.setUTCDate(1); d.setUTCMonth(d.getUTCMonth() + (+m));
154
+ const last = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + 1, 0)).getUTCDate();
155
+ d.setUTCDate(Math.min(day, last));
156
+ return d.toISOString().slice(0, 10);
157
+ }
158
+ const _lotNetCache = new WeakMap();
159
+ function _lotNetIndex(db) {
160
+ const moves = db.stockMovements || [];
161
+ const hit = _lotNetCache.get(db);
162
+ if (hit && hit.src === moves && hit.len === moves.length) return hit.idx;
163
+ const idx = new Map();
164
+ for (const m of moves) {
165
+ if (!m || !m.lotId || !m.batchId) continue;
166
+ const d = parseFloat(m.delta);
167
+ if (!isFinite(d)) continue;
168
+ const row = idx.get(m.batchId) || new Map();
169
+ row.set(m.lotId, (row.get(m.lotId) || 0) + d);
170
+ idx.set(m.batchId, row);
171
+ }
172
+ _lotNetCache.set(db, { src: moves, len: moves.length, idx });
173
+ return idx;
174
+ }
175
+ function _bestByInfo(b, f) {
176
+ const { db } = getStore();
177
+ const shelf = _shelfLifeISO(f, b.preparedDate);
178
+ const a = b.bestByAdjust && _realDay(b.bestByAdjust.date) ? b.bestByAdjust : null;
179
+ const date = a ? _realDay(a.date) : shelf;
180
+ if (!date) return null;
181
+ const test = a && a.testId ? (db.testResults || []).find(t => t && t.id === a.testId) : null;
182
+ const net = _lotNetIndex(db).get(b.id) || new Map();
183
+ const lotsById = new Map((db.lots || []).map(l => [l.id, l]));
184
+ const ingById = new Map((db.ingredients || []).map(i => [i.id, i]));
185
+ const early = [];
186
+ for (const [lotId, d] of net) {
187
+ if (!(d < -1e-9)) continue;
188
+ const lot = lotsById.get(lotId);
189
+ if (!lot || lot._trashed) continue;
190
+ const exp = _realDay(lot.expiryDate);
191
+ if (!exp || exp >= date) continue;
192
+ const ing = ingById.get(lot.ingredientId);
193
+ early.push({ lotId, lotNumber: lot.lotNumber || lot.uid || '', ingredient: ing ? (ing.name || ing.uid || '') : '', expiryDate: exp });
194
+ }
195
+ early.sort((x, y) => x.expiryDate.localeCompare(y.expiryDate));
196
+ return {
197
+ date,
198
+ source: a ? 'adjusted' : 'shelfLife',
199
+ shelfLifeDate: shelf,
200
+ adjusted: a ? {
201
+ change: !shelf || a.date === shelf ? 'set' : (a.date > shelf ? 'extended' : 'shortened'),
202
+ reason: a.reason || '', note: a.note || '',
203
+ retestReport: test ? { id: test.id, uid: test.uid || '' } : null,
204
+ by: a.by || null, at: a.at || null,
205
+ } : null,
206
+ lotsExpiringFirst: early,
207
+ };
208
+ }
209
+
135
210
  function _trimBatch(b, formulationsById, ingredientsById, batchesById) {
136
211
  if (!b) return null;
137
212
  const f = b.formulationId ? formulationsById.get(b.formulationId) : null;
@@ -170,6 +245,10 @@ function _trimBatch(b, formulationsById, ingredientsById, batchesById) {
170
245
  formulaFinishedDensity: _finishedDensityInfo(f, batchesById),
171
246
  preparedDate: b.preparedDate || '',
172
247
  preparedBy: b.preparedBy || '',
248
+ // Best-by: { date, source 'adjusted'|'shelfLife', shelfLifeDate, adjusted
249
+ // {change, reason, note, retestReport, by, at} | null, lotsExpiringFirst }.
250
+ // null = no shelf life on the formula and no adjusted date.
251
+ bestBy: _bestByInfo(b, f),
173
252
  // Finished-goods storage location for this batch's produced stock (Production
174
253
  // Inventory: a batch is a finished-goods lot).
175
254
  location: b.location || '',
@@ -208,7 +287,7 @@ function _trimSample(s, formulationsById, batchesById) {
208
287
  const list_batches = {
209
288
  definition: {
210
289
  name: 'list_batches',
211
- description: 'List batches (production / lab-prep events), optionally filtered by formulation, status, or origin-only (hides batches derived from other batches). Returns metadata; use get_batch for the full consumption ledger and samples.',
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.',
212
291
  inputSchema: {
213
292
  type: 'object',
214
293
  properties: {
@@ -216,6 +295,8 @@ const list_batches = {
216
295
  status: { type: 'string', description: 'Filter by status (case-insensitive substring).' },
217
296
  origin_only: { type: 'boolean', description: 'When true, exclude batches that have a parentBatchId.' },
218
297
  since_date: { type: 'string', description: 'ISO date (YYYY-MM-DD). Only batches prepared on/after this date.' },
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
+ 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).' },
219
300
  limit: { type: 'number', description: 'Max rows (default 50, max 500).' },
220
301
  },
221
302
  },
@@ -223,6 +304,7 @@ const list_batches = {
223
304
  handler: async (args) => {
224
305
  const { db, indexes } = getStore();
225
306
  const limit = Math.min(500, Math.max(1, args.limit || 50));
307
+ if (args.best_by_before && !_realDay(args.best_by_before)) return { error: `best_by_before must be a date (YYYY-MM-DD), got "${args.best_by_before}".` };
226
308
  const norm = (s) => String(s || '').toLowerCase();
227
309
  let formId = null;
228
310
  if (args.formulation_id) {
@@ -236,6 +318,12 @@ const list_batches = {
236
318
  if (args.status && !norm(b.status).includes(norm(args.status))) return false;
237
319
  if (args.origin_only && b.parentBatchId) return false;
238
320
  if (args.since_date && (b.preparedDate || '') < args.since_date) return false;
321
+ if (args.best_by_before || args.lots_expire_first) {
322
+ const bb = _bestByInfo(b, b.formulationId ? indexes.formulationsById.get(b.formulationId) : null);
323
+ if (!bb) return false;
324
+ if (args.best_by_before && !(bb.date < _realDay(args.best_by_before))) return false;
325
+ if (args.lots_expire_first && !bb.lotsExpiringFirst.length) return false;
326
+ }
239
327
  return true;
240
328
  });
241
329
  return {
package/vendor/cost.js CHANGED
@@ -2287,6 +2287,33 @@ function shelfLifeExpiryISO(formulation, preparedDate) {
2287
2287
  const d = shelfLifeExpiry(formulation, preparedDate);
2288
2288
  return d ? d.toISOString().slice(0, 10) : null;
2289
2289
  }
2290
+ // A batch's best-by. The batch's own date (Adjust best-by, build 49p:
2291
+ // b.bestByAdjust = { date, reason, note, testId, by, at }) wins over the
2292
+ // formula's shelf life; Reset removes it. Every place that shows or acts on a
2293
+ // batch's best-by reads batchBestByISO, so they all agree.
2294
+ const _BESTBY_ISO_RX = /^\d{4}-\d{2}-\d{2}$/;
2295
+ function batchBestByDefaultISO(b, f) {
2296
+ if (!b) return null;
2297
+ const ff = f || (((typeof db !== 'undefined' && db && db.formulations) || []).find(x => x.id === b.formulationId));
2298
+ return shelfLifeExpiryISO(ff, b.preparedDate);
2299
+ }
2300
+ function batchBestByAdjusted(b) {
2301
+ const a = b && b.bestByAdjust;
2302
+ return !!(a && _BESTBY_ISO_RX.test(String(a.date || '')));
2303
+ }
2304
+ function batchBestByISO(b, f) {
2305
+ return batchBestByAdjusted(b) ? b.bestByAdjust.date : batchBestByDefaultISO(b, f);
2306
+ }
2307
+ // "extended" / "shortened" / "set" next to an adjusted best-by; '' otherwise.
2308
+ function batchBestByTagHtml(b, f) {
2309
+ if (!batchBestByAdjusted(b)) return '';
2310
+ const a = b.bestByAdjust, was = batchBestByDefaultISO(b, f);
2311
+ const word = !was || a.date === was ? 'set' : (a.date > was ? 'extended' : 'shortened');
2312
+ const t = (a.testId && typeof db !== 'undefined' && db && db.testResults) ? db.testResults.find(x => x.id === a.testId) : null;
2313
+ const tip = [was ? 'Was ' + was : 'No shelf life on the formula', a.reason || '', t ? (t.uid || 'retest report') : '', a.note || ''].filter(Boolean).join(' · ');
2314
+ const e = s => (typeof esc === 'function' ? esc(s) : String(s));
2315
+ return ` <span class="fl-bestby-tag" data-tip="${e(tip)}" style="font-size:10.5px;font-weight:500;color:var(--text-muted, #64748b);border-bottom:1px dotted currentColor;cursor:help;white-space:nowrap">${word}</span>`;
2316
+ }
2290
2317
  // A small coloured badge for a best-by date (red if past, amber if ≤30d).
2291
2318
  function shelfLifeBadgeHtml(iso) {
2292
2319
  if (!iso) return '—';