formlab-mcp 0.6.62 → 0.6.64

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
@@ -52,7 +52,8 @@ Ask Claude (or another MCP client) things like:
52
52
  | `compare_batches` | Reproducibility of 2+ runs (ideally of one formula): each run's **yield %**, actual produced mass, cost/kg; per-ingredient **drift** across the runs vs the formula's proposed wt-%; and the biggest **outlier** run. `basis`: `wt_percent` (default) or `amount` |
53
53
  | `get_batch_pivot` | Production analytics — aggregate batches by `group_by` (formula / status / month / prepared_by / project) × `metric` (count, avg_yield_pct, total_produced_kg, avg_cost_per_batch, total_samples, total_tests), with share + total for additive metrics. Optional `batch_uids` scope + `status` filter |
54
54
  | `get_project_pivot` | Portfolio analytics — aggregate projects by `group_by` (status / phase / priority / business_unit / site / customer / lead, or `cf:<custom field>`) × `metric` (count, total_formulas / batches / samples, total_cost, avg_formulas / batches / cost_per_batch), rolling child activity + cost up by any project attribute. Optional `project_uids` scope |
55
- | `get_stability` | Grounded stability / shelf-life analysis for a formulation, sample or batch × parameter (auto-detected): time-series, drift (per-month slope + R²), an I-chart (mean ±3σ + out-of-control points), spec status, and an ICH-Q1E-flavored projected shelf life (point + 95%-CI crossing), all on **one point per test date per run condition** (replicates averaged, never separate time points), split by storage condition. A ranked-scale (ordinal) or text parameter returns its step / pass-fail series instead: per-condition points, firstFail, latest, scaleShift. Also the app's **Time points** (per condition: tested time points, skipped pulls, the next pull with its due date and whether it's overdue, on the formula's own pull schedule or the standard one; `as_of`) and **Arrhenius** (rates at the storage temperatures → the rate, Ea, Q10 and shelf life at `predict_at_c`, zero or first `order`, with 95% CIs and a verdict against the target) |
55
+ | `get_stability` | Grounded stability / shelf-life analysis for a formulation, sample or batch × parameter (auto-detected): time-series, drift (per-month slope + R²), an I-chart (mean ±3σ + out-of-control points), spec status, and an ICH-Q1E-flavored projected shelf life (point + 95%-CI crossing), all on **one point per test date per run condition** (replicates averaged, never separate time points), split by storage condition. A ranked-scale (ordinal) or text parameter returns its step / pass-fail series instead: per-condition points, firstFail, latest, scaleShift. Also the app's **Time points** (per condition: tested time points, skipped pulls, the next pull with its due date and whether it's overdue, on the formula's own pull schedule, in months or weeks, or the standard one; `as_of`) and **Arrhenius** (rates at the storage temperatures → the rate, Ea, Q10 and shelf life at `predict_at_c`, zero or first `order`, with 95% CIs and a verdict against the target), and per series the **moving range** (MR̄, its limit, the jumps above it) |
56
+ | `list_stability_pulls` | Stability pulls due across the whole workspace (the app's Needs Attention row): every formula on a study, its next pull per storage condition overdue or due within `within_days` (default 7), on its own pull schedule or the standard one; a test of any parameter counts as the pull; studies more than 60 days late listed apart as stopped |
56
57
  | `get_design_space` | COMPOSITION design space for one project, several (`projects`) or any formula list (`formulas`, across projects — like the app's Scope → DOE Matrix): which ingredients vary and over what observed wt-% ranges (ranked), an occupied-region summary ("where you've been"), the biggest untested **interior gap** as ready-to-seed DOE ranges (a combination you could have made but skipped), and an optional standardised **2-component PCA** of all varying ingredients — loadings, variance-explained, scree, and a full-dimensional gap. Optional `axes` (choose the 2–3 axes), `by_role` (map ingredients summed by primary Function, e.g. Pigment / Solvent / Film Former — no gap, roles aren't DOE factors) and `property` (highest / lowest formula plus the ingredients whose level tracks it, Spearman ρ). Reports formulas that aren't on the map and the spread on it. Matches the in-app Design Space Viewer exactly. Answers *"where haven't I explored?"* / *"what should I formulate next?"* |
57
58
  | `list_doe_designs` | Saved DOE designs — the *recipe* behind each batch of runs: design type, factors + ranges, constraints, run count, D-efficiency. Filters: `project`, `design_type`, `constrained_only`, `name_contains` |
58
59
  | `get_doe_design` | One design in full: constraints in plain language, the model it was optimised for, generation settings (run budget, replicates, centre points, seed) and the complete run matrix with the formulation each run became |
@@ -165,7 +166,7 @@ Or from the unpacked package:
165
166
  }
166
167
  ```
167
168
 
168
- Restart Claude Desktop. You should see a hammer icon indicating tools are available, and FormLab's 41 tools become callable in any conversation.
169
+ Restart Claude Desktop. You should see a hammer icon indicating tools are available, and FormLab's 44 tools become callable in any conversation.
169
170
 
170
171
  ## Wire it up to Claude Code
171
172
 
package/index.js CHANGED
@@ -7,7 +7,7 @@
7
7
  // FORMLAB_EXPORT=/path/to/export.json node index.js
8
8
  // formlab-mcp /path/to/export.json (when installed via npm)
9
9
  //
10
- // Exposes 41 tools (see ./tools/) over stdio. The MCP host (Claude
10
+ // Exposes 44 tools (see ./tools/) over stdio. The MCP host (Claude
11
11
  // Desktop, Claude Code, etc.) handles tool discovery, invocation
12
12
  // and response formatting. We just register handlers and stay out
13
13
  // of the way.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formlab-mcp",
3
- "version": "0.6.62",
3
+ "version": "0.6.64",
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.62",
5
+ "version": "0.6.64",
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.62",
11
+ "version": "0.6.64",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
@@ -1288,6 +1288,17 @@ function _iChart(ys) {
1288
1288
  return { mean, sigma, ucl, lcl, ooc };
1289
1289
  }
1290
1290
 
1291
+ // Moving range (the app's I-MR, _stabMR): each point's jump from the one before, MR̄, and UCL = 3.267 × MR̄ (D4 for
1292
+ // ranges of 2); the I-chart's σ is MR̄ ÷ 1.128.
1293
+ const _MR_D4 = 3.267;
1294
+ function _mr(ys) {
1295
+ const mr = ys.map((v, i) => i ? Math.abs(v - ys[i - 1]) : null);
1296
+ const vals = mr.slice(1);
1297
+ const bar = vals.length ? vals.reduce((a, b) => a + b, 0) / vals.length : null;
1298
+ const ucl = bar != null ? _MR_D4 * bar : null;
1299
+ return { mr, bar, ucl, over: mr.map(v => v != null && ucl != null && v > ucl + 1e-12) };
1300
+ }
1301
+
1291
1302
  // Shelf life: fit vs elapsed months, extrapolate to the spec limit the trend
1292
1303
  // heads toward. Point-estimate crossing + the conservative 95% CI-bound crossing.
1293
1304
  // One-sided 95% Student t for df = n − 2 (ICH Q1E) — a copy of the app's _stabT95
@@ -1356,18 +1367,31 @@ function _shelfLifeAssess(sl, targetMonths, now) {
1356
1367
  const _MS_PER_DAY = 86400000;
1357
1368
  const _PULLS_ACCEL = [1, 2, 3, 6];
1358
1369
  const _PULLS_LONG = [1, 2, 3, 6, 9, 12, 18, 24, 36];
1359
- // A time point from days since T₀: T₀ (≤ 3 days), weeks under 3 weeks, else whole months. key = days, for sorting.
1360
- function _tpBucket(days) {
1370
+ // A time point from days since T₀: T₀ (≤ 3 days), weeks under 3 weeks (or past the last week a schedule names), else
1371
+ // whole months. key = days, for sorting.
1372
+ function _tpBucket(days, weekDays = 21) {
1361
1373
  if (days <= 3) return { key: 0, label: 'T₀' };
1362
- if (days < 21) { const w = Math.max(1, Math.round(days / 7)); return { key: w * 7, label: `${w} wk` }; }
1374
+ if (days < weekDays) { const w = Math.max(1, Math.round(days / 7)); return { key: w * 7, label: `${w} wk` }; }
1363
1375
  const m = Math.max(1, Math.round(days / 30.4375));
1364
1376
  return { key: Math.round(m * 30.4375), label: `${m} mo` };
1365
1377
  }
1366
- // A formula's own pull months (Stability → Time points → Pull schedule): { long, accel }, accel = 35 °C and up.
1378
+ // A pull on a schedule: a number of months, or "<n>w" for weeks (Jun, 1 Nov: short accelerated and freeze-thaw
1379
+ // studies pull at 1, 2, 4 weeks).
1380
+ function _pullWeeks(e) { const w = typeof e === 'string' && /^(\d*\.?\d+)w$/.exec(e); return w ? +w[1] : null; }
1381
+ function _pullDays(e) { const w = _pullWeeks(e); return w != null ? w * 7 : +e * 30.4375; }
1382
+ function _pullLabel(e) { const w = _pullWeeks(e); return w != null ? `${w} wk` : `${+e} mo`; }
1383
+ // Valid pulls, one per day count, in time order.
1384
+ function _pullsClean(a) {
1385
+ if (!Array.isArray(a)) return [];
1386
+ const seen = new Set();
1387
+ return a.map(e => _pullWeeks(e) != null ? e : Number(e)).filter(e => _pullDays(e) > 0)
1388
+ .sort((x, y) => _pullDays(x) - _pullDays(y)).filter(e => { const d = _pullDays(e); return !seen.has(d) && seen.add(d); });
1389
+ }
1390
+ // A formula's own pull schedule (Stability → Time points → Pull schedule, or its Edit): { long, accel }, accel = 35 °C
1391
+ // and up.
1367
1392
  function _tpPlanOf(formula) {
1368
1393
  const p = formula && formula.stabilityPulls;
1369
- const ok = a => Array.isArray(a) ? [...new Set(a.map(Number).filter(m => m > 0))].sort((x, y) => x - y) : [];
1370
- return { long: p ? ok(p.long) : [], accel: p ? ok(p.accel) : [] };
1394
+ return { long: p ? _pullsClean(p.long) : [], accel: p ? _pullsClean(p.accel) : [] };
1371
1395
  }
1372
1396
  function _tpOwnPulls(plan, tC) {
1373
1397
  const own = plan && plan[tC != null && tC >= 35 ? 'accel' : 'long'];
@@ -1397,50 +1421,120 @@ function _condTempC(label) {
1397
1421
  // The study at a glance, one row per storage condition (the app's Time points plot): what was tested at each time
1398
1422
  // point from the entity's T₀ (its first test under any condition), the time points skipped, and the next pull with
1399
1423
  // its due date. points: [{ date, cond, pf }].
1424
+ // One storage condition's time points from T₀ and its next pull, on the formula's schedule or the standard one.
1425
+ // ps: points with .date (and .pf on a plot).
1426
+ function _tpCond(ps, t0, tC, targetMonths, plan, now) {
1427
+ const ladder = _tpLadder(tC, targetMonths, plan);
1428
+ // A schedule in weeks keeps its time points in weeks up to its last week pull.
1429
+ const weekDays = Math.max(21, ...ladder.filter(e => _pullWeeks(e) != null).map(e => _pullDays(e) + 4));
1430
+ const keyOf = e => _tpBucket(_pullDays(e), weekDays).key;
1431
+ const cells = new Map();
1432
+ ps.forEach(p => {
1433
+ const b = _tpBucket((p.date.getTime() - t0) / _MS_PER_DAY, weekDays);
1434
+ if (!cells.has(b.key)) cells.set(b.key, { ...b, points: [] });
1435
+ cells.get(b.key).points.push(p);
1436
+ });
1437
+ cells.forEach(c => { c.pf = c.points.some(p => p.pf === 'fail') ? 'fail' : c.points.some(p => p.pf === 'pass') ? 'pass' : null; });
1438
+ const lastKey = Math.max(...cells.keys());
1439
+ const nextE = ladder.find(e => keyOf(e) > lastKey);
1440
+ const next = nextE == null ? null : (() => {
1441
+ const due = t0 + _pullDays(nextE) * _MS_PER_DAY;
1442
+ return { label: _pullLabel(nextE), due: new Date(due), days: Math.floor((due - now) / _MS_PER_DAY) };
1443
+ })();
1444
+ return { cells, lastKey, weekDays, ladderKeys: ladder.map(keyOf), own: !!_tpOwnPulls(plan, tC), next };
1445
+ }
1446
+ const _dayOf = d => new Date(d).toISOString().slice(0, 10);
1447
+ const _nextOut = n => n ? { timePoint: n.label, due: _dayOf(n.due), daysUntil: n.days, overdue: n.days < 0 } : null;
1400
1448
  function _mcpTimePoints(points, formula, targetMonths, now) {
1401
1449
  if (!points.length) return null;
1402
- const day = d => new Date(d).toISOString().slice(0, 10);
1403
1450
  const t0 = Math.min(...points.map(p => p.date.getTime()));
1404
1451
  const plan = _tpPlanOf(formula);
1405
1452
  const byCond = new Map();
1406
1453
  points.forEach(p => { const c = (p.cond || '').trim(); if (!byCond.has(c)) byCond.set(c, []); byCond.get(c).push(p); });
1407
1454
  const rows = [...byCond.entries()].map(([cond, ps]) => ({ cond, ps, tC: cond ? _condTempC(cond) : null }))
1408
1455
  .sort((a, b) => (a.tC == null ? -Infinity : a.tC) - (b.tC == null ? -Infinity : b.tC) || a.cond.localeCompare(b.cond))
1409
- .map(({ cond, ps, tC }) => {
1410
- const cells = new Map();
1411
- ps.forEach(p => {
1412
- const b = _tpBucket((p.date.getTime() - t0) / _MS_PER_DAY);
1413
- if (!cells.has(b.key)) cells.set(b.key, { ...b, dates: new Set(), pfs: [] });
1414
- const c = cells.get(b.key); c.dates.add(day(p.date)); c.pfs.push(p.pf);
1415
- });
1416
- const lastKey = Math.max(...cells.keys());
1417
- const ladder = _tpLadder(tC, targetMonths, plan);
1418
- const nextM = ladder.find(m => Math.round(m * 30.4375) > lastKey);
1419
- const due = nextM == null ? null : t0 + nextM * _MS_PER_MONTH;
1420
- return { cond, tC, cells, lastKey, ladder, ladderKeys: ladder.map(m => Math.round(m * 30.4375)), own: !!_tpOwnPulls(plan, tC),
1421
- next: nextM == null ? null : { timePoint: `${nextM} mo`, due: day(due), daysUntil: Math.floor((due - now) / _MS_PER_DAY) } };
1422
- });
1456
+ .map(({ cond, ps, tC }) => ({ cond, tC, ladder: _tpLadder(tC, targetMonths, plan), ..._tpCond(ps, t0, tC, targetMonths, plan, now) }));
1423
1457
  // Skipped: a time point before this row's last test that its schedule, or (on the standard one) another row at its
1424
- // temperature, has.
1458
+ // temperature on the standard one, has.
1425
1459
  rows.forEach(r => {
1426
- const peers = r.own ? [] : rows.filter(o => o !== r && (o.tC != null ? o.tC === r.tC : o.cond === r.cond));
1460
+ const peers = r.own ? [] : rows.filter(o => o !== r && !o.own && (o.tC != null ? o.tC === r.tC : o.cond === r.cond));
1427
1461
  const keys = new Set([...r.ladderKeys, ...peers.flatMap(o => [...o.cells.keys()])]);
1428
1462
  r.skipped = [...keys].filter(k => k > 0 && k < r.lastKey && !r.cells.has(k)).sort((a, b) => a - b);
1429
1463
  });
1430
1464
  return {
1431
- t0: day(t0),
1465
+ t0: _dayOf(t0),
1432
1466
  rows: rows.map(r => ({
1433
1467
  condition: r.cond || null,
1434
1468
  temperatureC: r.tC != null ? _round(r.tC, 1) : null,
1435
1469
  schedule: r.own ? 'formula' : 'standard',
1436
- pullMonths: r.ladder,
1437
- tested: [...r.cells.values()].sort((a, b) => a.key - b.key).map(c => ({ timePoint: c.label, testDates: c.dates.size,
1438
- pf: c.pfs.includes('fail') ? 'fail' : c.pfs.includes('pass') ? 'pass' : null })),
1439
- skipped: r.skipped.map(k => _tpBucket(k).label),
1440
- next: r.next ? { ...r.next, overdue: r.next.daysUntil < 0 } : null,
1470
+ pulls: r.ladder.map(_pullLabel),
1471
+ tested: [...r.cells.values()].sort((a, b) => a.key - b.key).map(c => ({ timePoint: c.label, testDates: new Set(c.points.map(p => _dayOf(p.date))).size, pf: c.pf })),
1472
+ skipped: r.skipped.map(k => _tpBucket(k, r.weekDays).label),
1473
+ next: _nextOut(r.next),
1441
1474
  })),
1442
1475
  };
1443
1476
  }
1477
+ // Exploration runs (DOE / screening), as the app's flExplorationFormulaIds: the formula or its project marked
1478
+ // exploratory, or a DOE design's run that isn't Approved. Their alerts are expected, so sweeps leave them out.
1479
+ function _mcpExplorationIds(db) {
1480
+ const out = new Set();
1481
+ const proj = new Set((db.projects || []).filter(p => p && p.exploratory).map(p => p.id));
1482
+ const fromDoe = new Set();
1483
+ (db.doeDesigns || []).forEach(d => (d && d.formulationIds || []).forEach(id => fromDoe.add(id)));
1484
+ (db.formulations || []).forEach(f => {
1485
+ if (!f) return;
1486
+ if (f.exploratory || proj.has(f.projectId) || (fromDoe.has(f.id) && f.status !== 'Approved')) out.add(f.id);
1487
+ });
1488
+ return out;
1489
+ }
1490
+ // Pulls due across the workspace (the app's Needs Attention row, _stabPullsDueScan): every formula on a stability study
1491
+ // (tests under a storage condition with a temperature in its name on 2+ dates), its next pull per condition. A test of
1492
+ // any parameter counts as the pull; T₀ is the formula's first such test. Exploration runs, archived and trashed formulas
1493
+ // are left out; a pull more than _PULL_STALE_D days late is a study that stopped (returned apart, as `stopped`).
1494
+ const _PULL_STALE_D = 60;
1495
+ function _mcpPullsDue(db, now) {
1496
+ const due = [], stopped = [];
1497
+ const explore = _mcpExplorationIds(db);
1498
+ const defT = parseFloat(db.defaultShelfLifeMonths);
1499
+ const samplesOf = new Map();
1500
+ (db.samples || []).forEach(x => { if (x && !x._trashed && x.formulationId) { if (!samplesOf.has(x.formulationId)) samplesOf.set(x.formulationId, new Set()); samplesOf.get(x.formulationId).add(x.id); } });
1501
+ const testsOf = new Map();
1502
+ (db.testResults || []).forEach(t => { if (t && !t._trashed && t.sampleId) { if (!testsOf.has(t.sampleId)) testsOf.set(t.sampleId, []); testsOf.get(t.sampleId).push(t); } });
1503
+ (db.formulations || []).forEach(f => {
1504
+ if (!f || f._trashed || f.deletedAt || f.status === 'Archived' || explore.has(f.id)) return;
1505
+ const sids = samplesOf.get(f.id);
1506
+ if (!sids) return;
1507
+ const byCond = new Map(), params = new Map();
1508
+ sids.forEach(sid => (testsOf.get(sid) || []).forEach(t => {
1509
+ const day = String(t.testDate || '').slice(0, 10), ms = Date.parse(day);
1510
+ if (!Number.isFinite(ms)) return;
1511
+ (t.measurements || []).forEach(m => {
1512
+ const cond = _mcpCondLabel(m).trim();
1513
+ if (!cond || _condTempC(cond) == null) return;
1514
+ if (!byCond.has(cond)) byCond.set(cond, new Map());
1515
+ byCond.get(cond).set(day, ms);
1516
+ const p = String(m.parameter || '').trim(); if (p) params.set(p, (params.get(p) || 0) + 1);
1517
+ });
1518
+ }));
1519
+ const conds = [...byCond.entries()].filter(([, d]) => d.size >= 2);
1520
+ if (!conds.length) return;
1521
+ const t0 = Math.min(...conds.flatMap(([, d]) => [...d.values()]));
1522
+ const ownT = parseFloat(f.shelfLifeMonths);
1523
+ const target = ownT > 0 ? ownT : defT > 0 ? defT : null;
1524
+ const plan = _tpPlanOf(f);
1525
+ const param = [...params.entries()].sort((a, b) => b[1] - a[1])[0][0];
1526
+ conds.forEach(([cond, d]) => {
1527
+ const tC = _condTempC(cond);
1528
+ const r = _tpCond([...d.values()].map(ms => ({ date: new Date(ms) })), t0, tC, target, plan, now);
1529
+ if (!r.next) return;
1530
+ const row = { formula: { id: f.id, uid: f.uid || null, name: f.name || f.uid || 'Formula' }, condition: cond, temperatureC: _round(tC, 1),
1531
+ schedule: r.own ? 'formula' : 'standard', t0: _dayOf(t0), lastTimePoint: r.cells.get(r.lastKey).label, ..._nextOut(r.next), parameter: param };
1532
+ (r.next.days < -_PULL_STALE_D ? stopped : due).push(row);
1533
+ });
1534
+ });
1535
+ const byDays = (a, b) => a.daysUntil - b.daysUntil;
1536
+ return { due: due.sort(byDays), stopped: stopped.sort(byDays) };
1537
+ }
1444
1538
  // Two-sided 95% Student t (t 0.975), for a confidence interval: the Arrhenius CI. A copy of the app's _stabT975.
1445
1539
  const _T975_TABLE = [null, 12.706, 4.303, 3.182, 2.776, 2.571, 2.447, 2.365, 2.306, 2.262, 2.228, 2.201, 2.179, 2.160, 2.145, 2.131, 2.120, 2.110, 2.101, 2.093, 2.086, 2.080, 2.074, 2.069, 2.064, 2.060, 2.056, 2.052, 2.048, 2.045, 2.042];
1446
1540
  function _t975(df) {
@@ -1686,6 +1780,7 @@ const get_stability = {
1686
1780
  }
1687
1781
  const ic = _iChart(ys);
1688
1782
  if (ic) out.controlChart = { mean: _round(ic.mean), ucl: _round(ic.ucl), lcl: _round(ic.lcl), sigma: _round(ic.sigma), outOfControlPoints: ic.ooc };
1783
+ if (ic) { const m = _mr(ys); out.movingRange = { mean: _round(m.bar), ucl: _round(m.ucl), jumpsAbove: m.over.map((o, i) => o ? { date: pts[i].date.toISOString().slice(0, 10), from: pts[i - 1].date.toISOString().slice(0, 10), jump: _round(m.mr[i], 6) } : null).filter(Boolean) }; }
1689
1784
  if (spec.min != null || spec.max != null) out.spec = { ...spec, latestInSpec: (spec.min == null || ys[n - 1] >= spec.min) && (spec.max == null || ys[n - 1] <= spec.max) };
1690
1785
  else if (specVaries) {
1691
1786
  const ls = [...pts].reverse().find(p => p.spec);
@@ -1725,13 +1820,50 @@ const get_stability = {
1725
1820
  targetShelfLife: target ? { months: target.months, source: target.source } : null,
1726
1821
  timePoints: _mcpTimePoints(points, formula, target && target.months, asOf),
1727
1822
  arrhenius: specVaries ? null : _mcpArrhenius(points, spec, Number.isFinite(+args.predict_at_c) && args.predict_at_c !== null && args.predict_at_c !== '' ? +args.predict_at_c : 25, args.order === 'first' ? 'first' : 'zero', target && target.months),
1728
- timePointsNote: 'timePoints: one row per storage condition, time points counted from t0 (the first test under any condition): tested (pf "fail" when any reading that time point failed), skipped (a time point before the last test that the schedule or another condition at that temperature has, but this one does not), next (the next pull not yet tested, its due date, daysUntil; overdue = past as_of; null = schedule complete). schedule "formula" = the formula\'s own pull months, else "standard": 1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life.',
1729
- arrheniusNote: 'arrhenius (null when no condition names a temperature): rates per storage temperature (3+ test dates each), ln(rate) against 1/T fitted and read at predictAtC: activation energy, Q10, the rate there with its 95% CI, and the shelf life there from the T0 value to the spec limit (ci95Months: a faster rate gives the low end). "> 120" = beyond 10 years. verdict as shelfLife.verdict, against targetShelfLife. realTimeShelfLifeMonths = the trend projection at predictAtC itself when that temperature was tested. why = no prediction, and the reason.',
1823
+ movingRangeNote: 'movingRange (per series, beside controlChart): mean = MR̄, the average jump between consecutive points; ucl = 3.267 × MR̄; jumpsAbove = jumps bigger than chance (date, the point before, the jump). controlChart.sigma = MR̄ ÷ 1.128, so a jump above here is what widens the control limits.',
1824
+ timePointsNote: 'timePoints: one row per storage condition, time points counted from t0 (the first test under any condition): tested (pf "fail" when any reading that time point failed), skipped (a time point before the last test that the schedule or another condition at that temperature has, but this one does not), next (the next pull not yet tested, its due date, daysUntil; overdue = past as_of; null = schedule complete). schedule "formula" = the formula\'s own pulls (months, or weeks such as "2 wk"), else "standard": 1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life; pulls lists the row\'s schedule.',
1825
+ arrheniusNote: 'arrhenius (null when no condition names a temperature): rates per storage temperature (3+ test dates each), ln(rate) against 1/T fitted and read at predictAtC: activation energy, Q10 (how many times faster 10 °C warmer, from predictAtC to predictAtC + 10; it varies with temperature), the rate there with its 95% CI, and the shelf life there from the T0 value to the spec limit (ci95Months: a faster rate gives the low end). "> 120" = beyond 10 years. verdict as shelfLife.verdict, against targetShelfLife. realTimeShelfLifeMonths = the trend projection at predictAtC itself when that temperature was tested. why = no prediction, and the reason.',
1730
1826
  note: 'shelfLife.fromT0Months / ci95FromT0Months are the projected shelf life counted from the first test (T0): point estimate and the conservative (ICH Q1E) 95%-bound crossing. remainingMonths / ci95Months are the same, counted from the last test. verdict compares against targetShelfLife: "short" = the trend crosses spec before the target, "marginal" = the trend clears it but the 95% bound does not, "meets" = both clear it; null = no target set (then concern is by time left: medium <3 mo or overdue, else info). A projection never reaches \"high\": high is reserved for a MEASURED out-of-spec value (spec.latestInSpec=false). short/overdue → medium, marginal/meets → info. overdue=true means projectedCrossDate is already past today (time left runs from the last test), so the sample is probably out of spec now — recommend a re-test. reportable=false means the app shows no projection (R² < 0.3, crossing already past, or beyond 5 years). Numbers are computed here — narrate them, do not recompute.',
1731
1827
  };
1732
1828
  },
1733
1829
  };
1734
1830
 
1831
+ const list_stability_pulls = {
1832
+ definition: {
1833
+ name: 'list_stability_pulls',
1834
+ description: 'Stability pulls due across the whole workspace: the app\'s Needs Attention "stability pulls due" row, without naming a formula. Every formula on a stability study (tests under a storage condition with a temperature in its name, on 2+ dates) gives its next pull per condition, on the formula\'s own pull schedule or the standard one (1, 2, 3, 6 months at 35 °C and up; 1, 2, 3, 6, 9, 12, 18, 24, 36 months up to the target shelf life). A test of ANY parameter in a time point under that condition counts as the pull; T0 is the formula\'s first such test. Returns the pulls overdue or due within within_days (default 7), soonest first, with formula, condition, time point, due date, daysUntil (negative = overdue), schedule, the last time point tested, and the parameter the study measures most. A pull more than 60 days late is a study that stopped: listed apart under stopped. Exploration runs (DOE / screening), archived and trashed formulas are left out, as in the app. For one formula\'s full time-point grid use get_stability (timePoints).',
1835
+ inputSchema: {
1836
+ type: 'object',
1837
+ properties: {
1838
+ within_days: { type: 'number', description: 'Pulls due within this many days from as_of, plus every overdue one (default 7; 0 = overdue and due today only).' },
1839
+ formulation: { type: 'string', description: 'Only this formula (id or UID).' },
1840
+ as_of: { type: 'string', description: 'Date (YYYY-MM-DD) to count from. Default today.' },
1841
+ },
1842
+ },
1843
+ },
1844
+ handler: async (args) => {
1845
+ const db = getStore().db;
1846
+ const asOf = args.as_of && /^\d{4}-\d{2}-\d{2}$/.test(args.as_of) ? Date.parse(args.as_of) : Date.now();
1847
+ const within = Number.isFinite(+args.within_days) && args.within_days !== null && args.within_days !== '' ? Math.max(0, +args.within_days) : 7;
1848
+ let f = null;
1849
+ if (args.formulation) {
1850
+ f = (db.formulations || []).find(x => x && (x.id === args.formulation || x.uid === args.formulation));
1851
+ if (!f) return { error: `No formulation found for "${args.formulation}".` };
1852
+ }
1853
+ const r = _mcpPullsDue(db, asOf);
1854
+ const mine = x => !f || x.formula.id === f.id;
1855
+ const pulls = r.due.filter(x => mine(x) && x.daysUntil <= within);
1856
+ return {
1857
+ asOf: new Date(asOf).toISOString().slice(0, 10), withinDays: within,
1858
+ ...(f ? { formulation: { uid: f.uid, name: f.name } } : {}),
1859
+ count: pulls.length, overdue: pulls.filter(x => x.overdue).length, pulls,
1860
+ later: r.due.filter(x => mine(x) && x.daysUntil > within).length,
1861
+ stopped: r.stopped.filter(mine),
1862
+ note: 'daysUntil < 0 = overdue by that many days. schedule "formula" = the formula\'s own pulls, else "standard". later = studies whose next pull is further out than within_days. stopped = next pull more than 60 days late, read as a study that ended; the app leaves these out of Needs Attention. Narrate these figures; do not recompute the schedule.',
1863
+ };
1864
+ },
1865
+ };
1866
+
1735
1867
  export { _mcpRepNumber, _mcpMeasType, _evalPassFail, _resolveSpec, _shelfLife, _shelfLifeAssess, _mcpCondTags, _mcpArmNames, _mcpCondDefaultScore, _mcpCondSig, _mcpCondLabel, _mcpParamGroupsOf };
1736
1868
  // ============================================================
1737
1869
  // compare_test_results — the app's Compare Results table (js/views/testing-
@@ -1990,4 +2122,5 @@ export const tools = {
1990
2122
  list_doe_designs,
1991
2123
  get_doe_design,
1992
2124
  get_stability,
2125
+ list_stability_pulls,
1993
2126
  };
@@ -30,8 +30,9 @@ function _trimFormulation(f) {
30
30
  // Target shelf life (months): sets finished-goods expiry AND is what
31
31
  // get_stability judges the projected shelf life against.
32
32
  shelfLifeMonths: f.shelfLifeMonths ?? null,
33
- // Its own stability pull months (Stability → Time points → Pull schedule): long = below 35 °C, accel = 35 °C and
34
- // up; null = the standard schedule. get_stability's timePoints follow it.
33
+ // Its own stability pull schedule (Stability → Time points → Pull schedule, or its Edit): long = below 35 °C,
34
+ // accel = 35 °C and up; a number is months, "2w" two weeks; null = the standard schedule. get_stability's timePoints
35
+ // follow it.
35
36
  stabilityPulls: f.stabilityPulls && (Array.isArray(f.stabilityPulls.long) || Array.isArray(f.stabilityPulls.accel)) ? { long: f.stabilityPulls.long || [], accel: f.stabilityPulls.accel || [] } : null,
36
37
  // Density of the MIXED product (g/mL), when declared — volume-targeted
37
38
  // batches scale by it instead of the ideal-mix estimate. null = not set.