formlab-mcp 0.6.95 → 0.6.96

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.95",
3
+ "version": "0.6.96",
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.95",
5
+ "version": "0.6.96",
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.95",
11
+ "version": "0.6.96",
12
12
  "runtimeHint": "npx",
13
13
  "transport": {
14
14
  "type": "stdio"
package/vendor/cost.js CHANGED
@@ -2279,9 +2279,37 @@ function defaultPercentBasis(formulation, costSummary) {
2279
2279
  // ============================================================
2280
2280
  // Approximate kg conversion for batch.targetQuantity.unit. If
2281
2281
  // volume, falls back to *assume kg* unless density is known.
2282
+ // A batch derived from another (a rework, a let-down) is made of the parent's material: it costs what the parent
2283
+ // cost per kg, not the recipe at today's prices (Jun, 29 Nov: BATCH-0187-A read $1.79/kg fresh while BATCH-0187 had
2284
+ // cost $36.98 for 20 kg from its own lots). The parent's actual COGS when its lots carried prices, else its own cost,
2285
+ // up the chain. Null for a batch with no parent, or when the parent has no cost.
2286
+ let _flDerivedDepth = 0;
2287
+ function flDerivedBatchCost(batch, displayCcy) {
2288
+ if (!batch || !batch.parentBatchId || _flDerivedDepth > 10) return null;
2289
+ const p = (db.batches || []).find(x => x && x.id === batch.parentBatchId);
2290
+ if (!p) return null;
2291
+ const ccy = displayCcy || (typeof getDisplayCurrency === 'function' ? getDisplayCurrency() : 'USD');
2292
+ _flDerivedDepth++;
2293
+ try {
2294
+ const pf = typeof flBatchFormula === 'function' ? flBatchFormula(p) : (db.formulations || []).find(x => x.id === p.formulationId);
2295
+ let perKg = null, basis = 'recipe';
2296
+ if (typeof _batchStockSummary === 'function' && typeof _batchStockValue === 'function') {
2297
+ const ps = _batchStockSummary(p), pv = _batchStockValue(p, ps);
2298
+ const pKg = quantityToKg(ps.produced, p.unit, pf, typeof _batchUnitMassKg === 'function' ? _batchUnitMassKg(p) : null);
2299
+ if (pv && pv.producedValue != null && pKg > 0) { perKg = pv.producedValue / pKg; basis = pv.basis || 'recipe'; }
2300
+ }
2301
+ if (perKg == null) { const pc = computeBatchCost(p, ccy); if (pc && pc.perKg != null) perKg = pc.perKg; }
2302
+ if (perKg == null || !isFinite(perKg)) return null;
2303
+ const f = typeof flBatchFormula === 'function' ? flBatchFormula(batch) : (db.formulations || []).find(x => x.id === batch.formulationId);
2304
+ const sizeKg = quantityToKg(batch.targetQuantity, batch.unit, f || pf, typeof _batchUnitMassKg === 'function' ? _batchUnitMassKg(batch) : null);
2305
+ return { perKg, sizeKg, total: sizeKg != null ? perKg * sizeKg : null, parent: p, basis };
2306
+ } finally { _flDerivedDepth--; }
2307
+ }
2282
2308
  function computeBatchCost(batch, displayCcy = getDisplayCurrency()) {
2283
2309
  const f = (typeof flBatchFormula === 'function' ? flBatchFormula(batch) : db.formulations.find(x => x.id === batch.formulationId));
2284
2310
  if (!f) return null;
2311
+ const der = flDerivedBatchCost(batch, displayCcy);
2312
+ if (der) return { formulation: f, perKg: der.perKg, sizeKg: der.sizeKg, total: der.total, currency: displayCcy, missing: [], fromParent: der.parent, parentBasis: der.basis };
2285
2313
  const perKg = computeFormulationCost(f, displayCcy);
2286
2314
  // Batch size in kg via the shared quantityToKg (mass units convert directly;
2287
2315
  // volume units use the formula's rolled-up density). This is the SAME path the