plm-upload-mcp 1.3.8 → 1.4.0
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 +1 -1
- package/index.mjs +45 -20
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ Uploads one or more files, each paired with its target SKU.
|
|
|
43
43
|
- `files`: array of `{ path, sku, category? }`
|
|
44
44
|
- `path` — absolute local path to the file
|
|
45
45
|
- `sku` — component SKU, e.g. `MNT-1234-A0`; it must already exist in the PLM
|
|
46
|
-
- `category` — optional: `Compliance` | `Datasheet` | `Quotation` | `Software` | `Drawing` | `3D file` (left out = the PLM guesses from the file name)
|
|
46
|
+
- `category` — optional: `Compliance` | `Datasheet` | `Quotation` | `Software` | `Drawing` | `3D file` | `DFM report` (a PowerPoint, saved as Google Slides) (left out = the PLM guesses from the file name)
|
|
47
47
|
|
|
48
48
|
Each file lands in PLM storage and is mirrored into that SKU's Google Drive folder on
|
|
49
49
|
the part's own drive (staging or main, from the component; created automatically if it
|
package/index.mjs
CHANGED
|
@@ -301,7 +301,7 @@ server.registerTool(
|
|
|
301
301
|
path: z.string().describe('Absolute local path to the file to upload.'),
|
|
302
302
|
sku: z.string().describe('Component SKU this file belongs to, e.g. MNT-1234-A0.'),
|
|
303
303
|
category: z
|
|
304
|
-
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file'])
|
|
304
|
+
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file', 'DFM report'])
|
|
305
305
|
.optional()
|
|
306
306
|
.describe('PLM file category. Leave it out and the PLM guesses one from the file name.'),
|
|
307
307
|
}),
|
|
@@ -654,6 +654,22 @@ server.registerTool(
|
|
|
654
654
|
},
|
|
655
655
|
)
|
|
656
656
|
|
|
657
|
+
/** ASM master (PLM migration 20261118000009): a product BOM's rows with each ASM row's parts right under it, every
|
|
658
|
+
* BOM in its own sort order; `total_quantity` = quantity × the ASM rows above it, `in_asm` / `asm_depth` on a part
|
|
659
|
+
* inside an ASM. Copy of the PLM's supabase/functions/drive-library/asm.ts unfoldAsms: change them together. */
|
|
660
|
+
export function unfoldAsms(rootBomId, rowsByBom, asmBomOf) {
|
|
661
|
+
const out = []
|
|
662
|
+
const walk = (bomId, parent, depth, factor, seen) => {
|
|
663
|
+
for (const r of [...(rowsByBom.get(bomId) ?? [])].sort((a, b) => a.sort_order - b.sort_order)) {
|
|
664
|
+
out.push({ ...r, total_quantity: Number(r.quantity) * factor, ...(parent ? { in_asm: parent.sku ?? null, asm_depth: depth } : {}) })
|
|
665
|
+
const own = r.component_id ? asmBomOf.get(r.component_id) : undefined
|
|
666
|
+
if (own && !seen.has(own)) walk(own, r, depth + 1, factor * Number(r.quantity), new Set(seen).add(own))
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
walk(rootBomId, null, 0, 1, new Set([rootBomId]))
|
|
670
|
+
return out
|
|
671
|
+
}
|
|
672
|
+
|
|
657
673
|
server.registerTool(
|
|
658
674
|
'list_boms',
|
|
659
675
|
{
|
|
@@ -663,7 +679,9 @@ server.registerTool(
|
|
|
663
679
|
"items — component SKU, name, quantity, unit, reference designator — and a derived `staging` flag: " +
|
|
664
680
|
"a product is 'staging' while its working BOM still contains any staging (unconfirmed) component, " +
|
|
665
681
|
"otherwise 'main'. By default returns working BOMs only (set include_snapshots to include saved " +
|
|
666
|
-
"snapshots) with their rows.
|
|
682
|
+
"snapshots) with their rows. A working BOM's rows include each ASM's parts right under its row " +
|
|
683
|
+
"(in_asm = that ASM's SKU, asm_depth, total_quantity = quantity x the ASM rows above it). " +
|
|
684
|
+
"Filter to one product with product_sku. Read-only.",
|
|
667
685
|
inputSchema: {
|
|
668
686
|
product_sku: z.string().optional().describe('Restrict to one product by its SAL SKU, e.g. SAL-0R3-3001.'),
|
|
669
687
|
classification: z
|
|
@@ -679,32 +697,35 @@ server.registerTool(
|
|
|
679
697
|
async ({ product_sku, classification = 'all', include_snapshots = false, include_rows = true, max_rows_per_bom = 2000 }) => {
|
|
680
698
|
// 1) BOM headers + their product.
|
|
681
699
|
const bomParams = {
|
|
682
|
-
select: 'id,name,is_snapshot,snapshot_label,product_id,created_at,product:products(sku,name,status)',
|
|
700
|
+
select: 'id,name,is_snapshot,snapshot_label,product_id,assembly_id,created_at,product:products(sku,name,status)',
|
|
683
701
|
order: 'created_at.asc',
|
|
684
702
|
}
|
|
685
703
|
if (!include_snapshots) bomParams.is_snapshot = 'eq.false'
|
|
686
704
|
const { rows: boms } = await restGet('boms', bomParams, {})
|
|
687
|
-
|
|
705
|
+
// An ASM's own BOM (no product) is no product: its rows show under each product BOM that uses it.
|
|
706
|
+
const asmBoms = boms.filter((b) => b.assembly_id && !b.is_snapshot)
|
|
707
|
+
const asmBomOf = new Map(asmBoms.map((b) => [b.assembly_id, b.id]))
|
|
708
|
+
const scoped = boms.filter((b) => b.product_id && (!product_sku || b.product?.sku === product_sku))
|
|
688
709
|
if (!scoped.length) {
|
|
689
710
|
return { content: [{ type: 'text', text: product_sku ? `No BOMs for product ${product_sku}.` : 'No BOMs found.' }], structuredContent: { products: [] } }
|
|
690
711
|
}
|
|
691
712
|
|
|
692
713
|
// 2) Rows for those BOMs, embedding each component's SKU + staging flag.
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
}
|
|
714
|
+
// Always fetched: `staging` and `row_count` come from the rows; include_rows only trims the output.
|
|
715
|
+
const byBom = new Map([...scoped, ...asmBoms].map((b) => [b.id, []]))
|
|
716
|
+
const ids = [...byBom.keys()]
|
|
717
|
+
// Chunk the in-list so the URL stays a sane length.
|
|
718
|
+
for (let i = 0; i < ids.length; i += 50) {
|
|
719
|
+
const chunk = ids.slice(i, i + 50)
|
|
720
|
+
const { rows } = await restGet('bom_rows', {
|
|
721
|
+
select:
|
|
722
|
+
'id,bom_id,component_id,quantity,unit,reference_designator,sort_order,row_type,sheet_sku:custom_fields->>_sku,sheet_name:custom_fields->>_name,component:components(sku,name,category,revision,status,staging)',
|
|
723
|
+
bom_id: `in.(${chunk.join(',')})`,
|
|
724
|
+
order: 'bom_id.asc,sort_order.asc',
|
|
725
|
+
limit: String(max_rows_per_bom * chunk.length),
|
|
726
|
+
})
|
|
727
|
+
// A row imported without a part shows its sheet SKU and name, like the API.
|
|
728
|
+
for (const r of rows) byBom.get(r.bom_id)?.push({ ...r, sku: r.component?.sku ?? r.sheet_sku ?? null, name: r.component?.name ?? r.sheet_name ?? null })
|
|
708
729
|
}
|
|
709
730
|
|
|
710
731
|
// 3) Group by product; derive staging from the working BOM's rows.
|
|
@@ -714,7 +735,7 @@ server.registerTool(
|
|
|
714
735
|
if (!products.has(key)) {
|
|
715
736
|
products.set(key, { product: b.product ?? { sku: null, id: b.product_id }, staging: false, boms: [] })
|
|
716
737
|
}
|
|
717
|
-
const rows = byBom.get(b.id) ?? []
|
|
738
|
+
const rows = b.is_snapshot ? byBom.get(b.id) ?? [] : unfoldAsms(b.id, byBom, asmBomOf)
|
|
718
739
|
const bomStaging = rows.some((r) => r.component?.staging === true)
|
|
719
740
|
// A product's class is decided by its working (non-snapshot) BOM.
|
|
720
741
|
if (!b.is_snapshot && bomStaging) products.get(key).staging = true
|
|
@@ -757,6 +778,10 @@ if (process.argv.includes('--selftest')) {
|
|
|
757
778
|
=== 'BRG-0245-X0 Bushing_260908.pdf', 'safe name unchanged')
|
|
758
779
|
const SAFE = /^[\w !\-.*'()&$@=;:+,?/]*$/
|
|
759
780
|
assert(SAFE.test(storageKeyName('a[b]c#d%e\\f"g<h>i.STEP')), 'all unsafe chars replaced')
|
|
781
|
+
// unfoldAsms: an ASM's parts under its row, totals per product, no loop
|
|
782
|
+
const u = unfoldAsms('P', new Map([['P', [{ id: 'a', sort_order: 0, component_id: 'A', quantity: 2, sku: 'ASM-00001-00' }]],
|
|
783
|
+
['A', [{ id: 'c', sort_order: 0, component_id: 'A', quantity: 3, sku: 'ASM-00001-00' }]]]), new Map([['A', 'A']]))
|
|
784
|
+
assert(u.map((r) => `${r.id}:${r.total_quantity}:${r.in_asm ?? ''}`).join() === 'a:2:,c:6:ASM-00001-00', 'unfoldAsms')
|
|
760
785
|
// stagingFilter mapping
|
|
761
786
|
assert(JSON.stringify(stagingFilter('main')) === '{"staging":"eq.false"}', 'main -> staging=false')
|
|
762
787
|
assert(JSON.stringify(stagingFilter('staging')) === '{"staging":"eq.true"}', 'staging -> staging=true')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plm-upload-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "MCP server to read the LionsBot PLM (SKU folders, component metadata, extracted drawing metadata, product & staging BOMs) bulk-upload SolidWorks exports (STEP/PDF) into it by SKU, create components' Drive folders and uprev staging prototypes.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"keywords": ["mcp", "modelcontextprotocol", "lionsbot", "plm", "solidworks"],
|