plm-upload-mcp 1.3.9 → 1.5.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 +57 -21
- 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` | `DFM report` (a PowerPoint, saved as Google Slides) (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) | `Other` (zip, image, Word, Excel, PowerPoint…) (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
|
@@ -43,6 +43,17 @@ const MIME = {
|
|
|
43
43
|
'.png': 'image/png',
|
|
44
44
|
'.jpg': 'image/jpeg',
|
|
45
45
|
'.jpeg': 'image/jpeg',
|
|
46
|
+
'.gif': 'image/gif',
|
|
47
|
+
'.webp': 'image/webp',
|
|
48
|
+
'.zip': 'application/zip',
|
|
49
|
+
'.txt': 'text/plain',
|
|
50
|
+
'.csv': 'text/csv',
|
|
51
|
+
'.doc': 'application/msword',
|
|
52
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
53
|
+
'.xls': 'application/vnd.ms-excel',
|
|
54
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
55
|
+
'.ppt': 'application/vnd.ms-powerpoint',
|
|
56
|
+
'.pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
46
57
|
}
|
|
47
58
|
const mimeFor = (name) => MIME[extname(name).toLowerCase()] || 'application/octet-stream'
|
|
48
59
|
|
|
@@ -283,7 +294,7 @@ server.registerTool(
|
|
|
283
294
|
{
|
|
284
295
|
title: 'Upload files to PLM by SKU',
|
|
285
296
|
description:
|
|
286
|
-
"Bulk-upload local files (
|
|
297
|
+
"Bulk-upload local files (SolidWorks STEP/PDF exports, or any other file: zip, image, Word, Excel, PowerPoint…) into the LionsBot PLM. " +
|
|
287
298
|
"Each file is attached to an existing component by its SKU: it lands in PLM storage and is " +
|
|
288
299
|
"mirrored into that SKU's Google Drive folder on the part's own drive (staging or main; folder " +
|
|
289
300
|
"auto-created if missing). A SKU that is not in the PLM is refused. Re-uploading a file with " +
|
|
@@ -301,7 +312,7 @@ server.registerTool(
|
|
|
301
312
|
path: z.string().describe('Absolute local path to the file to upload.'),
|
|
302
313
|
sku: z.string().describe('Component SKU this file belongs to, e.g. MNT-1234-A0.'),
|
|
303
314
|
category: z
|
|
304
|
-
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file', 'DFM report'])
|
|
315
|
+
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file', 'DFM report', 'Other'])
|
|
305
316
|
.optional()
|
|
306
317
|
.describe('PLM file category. Leave it out and the PLM guesses one from the file name.'),
|
|
307
318
|
}),
|
|
@@ -654,6 +665,22 @@ server.registerTool(
|
|
|
654
665
|
},
|
|
655
666
|
)
|
|
656
667
|
|
|
668
|
+
/** ASM master (PLM migration 20261118000009): a product BOM's rows with each ASM row's parts right under it, every
|
|
669
|
+
* BOM in its own sort order; `total_quantity` = quantity × the ASM rows above it, `in_asm` / `asm_depth` on a part
|
|
670
|
+
* inside an ASM. Copy of the PLM's supabase/functions/drive-library/asm.ts unfoldAsms: change them together. */
|
|
671
|
+
export function unfoldAsms(rootBomId, rowsByBom, asmBomOf) {
|
|
672
|
+
const out = []
|
|
673
|
+
const walk = (bomId, parent, depth, factor, seen) => {
|
|
674
|
+
for (const r of [...(rowsByBom.get(bomId) ?? [])].sort((a, b) => a.sort_order - b.sort_order)) {
|
|
675
|
+
out.push({ ...r, total_quantity: Number(r.quantity) * factor, ...(parent ? { in_asm: parent.sku ?? null, asm_depth: depth } : {}) })
|
|
676
|
+
const own = r.component_id ? asmBomOf.get(r.component_id) : undefined
|
|
677
|
+
if (own && !seen.has(own)) walk(own, r, depth + 1, factor * Number(r.quantity), new Set(seen).add(own))
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
walk(rootBomId, null, 0, 1, new Set([rootBomId]))
|
|
681
|
+
return out
|
|
682
|
+
}
|
|
683
|
+
|
|
657
684
|
server.registerTool(
|
|
658
685
|
'list_boms',
|
|
659
686
|
{
|
|
@@ -663,7 +690,9 @@ server.registerTool(
|
|
|
663
690
|
"items — component SKU, name, quantity, unit, reference designator — and a derived `staging` flag: " +
|
|
664
691
|
"a product is 'staging' while its working BOM still contains any staging (unconfirmed) component, " +
|
|
665
692
|
"otherwise 'main'. By default returns working BOMs only (set include_snapshots to include saved " +
|
|
666
|
-
"snapshots) with their rows.
|
|
693
|
+
"snapshots) with their rows. A working BOM's rows include each ASM's parts right under its row " +
|
|
694
|
+
"(in_asm = that ASM's SKU, asm_depth, total_quantity = quantity x the ASM rows above it). " +
|
|
695
|
+
"Filter to one product with product_sku. Read-only.",
|
|
667
696
|
inputSchema: {
|
|
668
697
|
product_sku: z.string().optional().describe('Restrict to one product by its SAL SKU, e.g. SAL-0R3-3001.'),
|
|
669
698
|
classification: z
|
|
@@ -679,32 +708,35 @@ server.registerTool(
|
|
|
679
708
|
async ({ product_sku, classification = 'all', include_snapshots = false, include_rows = true, max_rows_per_bom = 2000 }) => {
|
|
680
709
|
// 1) BOM headers + their product.
|
|
681
710
|
const bomParams = {
|
|
682
|
-
select: 'id,name,is_snapshot,snapshot_label,product_id,created_at,product:products(sku,name,status)',
|
|
711
|
+
select: 'id,name,is_snapshot,snapshot_label,product_id,assembly_id,created_at,product:products(sku,name,status)',
|
|
683
712
|
order: 'created_at.asc',
|
|
684
713
|
}
|
|
685
714
|
if (!include_snapshots) bomParams.is_snapshot = 'eq.false'
|
|
686
715
|
const { rows: boms } = await restGet('boms', bomParams, {})
|
|
687
|
-
|
|
716
|
+
// An ASM's own BOM (no product) is no product: its rows show under each product BOM that uses it.
|
|
717
|
+
const asmBoms = boms.filter((b) => b.assembly_id && !b.is_snapshot)
|
|
718
|
+
const asmBomOf = new Map(asmBoms.map((b) => [b.assembly_id, b.id]))
|
|
719
|
+
const scoped = boms.filter((b) => b.product_id && (!product_sku || b.product?.sku === product_sku))
|
|
688
720
|
if (!scoped.length) {
|
|
689
721
|
return { content: [{ type: 'text', text: product_sku ? `No BOMs for product ${product_sku}.` : 'No BOMs found.' }], structuredContent: { products: [] } }
|
|
690
722
|
}
|
|
691
723
|
|
|
692
724
|
// 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
|
-
}
|
|
725
|
+
// Always fetched: `staging` and `row_count` come from the rows; include_rows only trims the output.
|
|
726
|
+
const byBom = new Map([...scoped, ...asmBoms].map((b) => [b.id, []]))
|
|
727
|
+
const ids = [...byBom.keys()]
|
|
728
|
+
// Chunk the in-list so the URL stays a sane length.
|
|
729
|
+
for (let i = 0; i < ids.length; i += 50) {
|
|
730
|
+
const chunk = ids.slice(i, i + 50)
|
|
731
|
+
const { rows } = await restGet('bom_rows', {
|
|
732
|
+
select:
|
|
733
|
+
'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)',
|
|
734
|
+
bom_id: `in.(${chunk.join(',')})`,
|
|
735
|
+
order: 'bom_id.asc,sort_order.asc',
|
|
736
|
+
limit: String(max_rows_per_bom * chunk.length),
|
|
737
|
+
})
|
|
738
|
+
// A row imported without a part shows its sheet SKU and name, like the API.
|
|
739
|
+
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
740
|
}
|
|
709
741
|
|
|
710
742
|
// 3) Group by product; derive staging from the working BOM's rows.
|
|
@@ -714,7 +746,7 @@ server.registerTool(
|
|
|
714
746
|
if (!products.has(key)) {
|
|
715
747
|
products.set(key, { product: b.product ?? { sku: null, id: b.product_id }, staging: false, boms: [] })
|
|
716
748
|
}
|
|
717
|
-
const rows = byBom.get(b.id) ?? []
|
|
749
|
+
const rows = b.is_snapshot ? byBom.get(b.id) ?? [] : unfoldAsms(b.id, byBom, asmBomOf)
|
|
718
750
|
const bomStaging = rows.some((r) => r.component?.staging === true)
|
|
719
751
|
// A product's class is decided by its working (non-snapshot) BOM.
|
|
720
752
|
if (!b.is_snapshot && bomStaging) products.get(key).staging = true
|
|
@@ -757,6 +789,10 @@ if (process.argv.includes('--selftest')) {
|
|
|
757
789
|
=== 'BRG-0245-X0 Bushing_260908.pdf', 'safe name unchanged')
|
|
758
790
|
const SAFE = /^[\w !\-.*'()&$@=;:+,?/]*$/
|
|
759
791
|
assert(SAFE.test(storageKeyName('a[b]c#d%e\\f"g<h>i.STEP')), 'all unsafe chars replaced')
|
|
792
|
+
// unfoldAsms: an ASM's parts under its row, totals per product, no loop
|
|
793
|
+
const u = unfoldAsms('P', new Map([['P', [{ id: 'a', sort_order: 0, component_id: 'A', quantity: 2, sku: 'ASM-00001-00' }]],
|
|
794
|
+
['A', [{ id: 'c', sort_order: 0, component_id: 'A', quantity: 3, sku: 'ASM-00001-00' }]]]), new Map([['A', 'A']]))
|
|
795
|
+
assert(u.map((r) => `${r.id}:${r.total_quantity}:${r.in_asm ?? ''}`).join() === 'a:2:,c:6:ASM-00001-00', 'unfoldAsms')
|
|
760
796
|
// stagingFilter mapping
|
|
761
797
|
assert(JSON.stringify(stagingFilter('main')) === '{"staging":"eq.false"}', 'main -> staging=false')
|
|
762
798
|
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.5.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"],
|