plm-upload-mcp 1.4.0 → 1.5.1
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 +35 -18
- 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
|
|
|
@@ -148,13 +159,15 @@ function nextRev(sku) {
|
|
|
148
159
|
return { newSku: `${m[1]}-${m[2]}-X${Number(m[3]) + 1}` }
|
|
149
160
|
}
|
|
150
161
|
|
|
151
|
-
/** Why a
|
|
152
|
-
* `[SKU] Part Name REV0X
|
|
153
|
-
*
|
|
154
|
-
function fileNameIssue(name, sku) {
|
|
155
|
-
const stem = /^(.*)\.(pdf|step|stp)$/i.exec(name)?.[1]
|
|
156
|
-
if (stem === undefined) return null
|
|
162
|
+
/** Why a file named `name` breaks the naming rule for `sku`; null when it follows it. A STEP, and a PDF that is a
|
|
163
|
+
* LionsBot drawing (`drawing`), is named `[SKU] Part Name REV0X`; any other file only starts with `[SKU] `.
|
|
164
|
+
* A prompt only: the upload still goes ahead. Copy of src/lib/injectionMould.ts fileNameIssue. */
|
|
165
|
+
function fileNameIssue(name, sku, drawing = false) {
|
|
157
166
|
const head = `[${sku}] `.toUpperCase()
|
|
167
|
+
if (!/\.(step|stp)$/i.test(name) && !(drawing && /\.pdf$/i.test(name))) {
|
|
168
|
+
return name.toUpperCase().startsWith(head) ? null : `${name} does not start with "[${sku}] ".`
|
|
169
|
+
}
|
|
170
|
+
const stem = name.replace(/\.[^.]+$/, '')
|
|
158
171
|
const ok = stem.toUpperCase().startsWith(head) && /^\S.* REV\d{2}$/i.test(stem.slice(head.length))
|
|
159
172
|
return ok ? null : `${name} is not named "[${sku}] Part Name REV0X".`
|
|
160
173
|
}
|
|
@@ -181,17 +194,19 @@ function drawingWarnings(read, newSku, prev) {
|
|
|
181
194
|
return out
|
|
182
195
|
}
|
|
183
196
|
|
|
184
|
-
/** What reading an uploaded drawing did; `listed` = it is now in Injection Mold Staging. */
|
|
197
|
+
/** What reading an uploaded drawing did; `listed` = it is now in Injection Mold Staging, `lionsbot` = a LionsBot title block. */
|
|
185
198
|
function readOutcome(res, sku) {
|
|
186
|
-
if (res.error) return { ok: false, text: res.error, listed: false }
|
|
199
|
+
if (res.error) return { ok: false, text: res.error, listed: false, lionsbot: false }
|
|
200
|
+
const lionsbot = res.extracted?.is_lionsbot === true
|
|
187
201
|
if (!res.written) {
|
|
188
202
|
const text = res.extracted?.is_lionsbot === false
|
|
189
203
|
? 'Not a LionsBot drawing, nothing read'
|
|
190
204
|
: `Drawing says ${res.sku_check?.drawing_sku ?? 'no SKU'}, not ${sku}: nothing read`
|
|
191
|
-
return { ok: false, text, listed: false }
|
|
205
|
+
return { ok: false, text, listed: false, lionsbot }
|
|
192
206
|
}
|
|
193
207
|
return {
|
|
194
208
|
ok: true,
|
|
209
|
+
lionsbot,
|
|
195
210
|
text: `Drawing read${res.extracted?.rev ? ` · REV ${res.extracted.rev}` : ''}`,
|
|
196
211
|
listed: IM_METHOD.test(res.extracted?.manufacturing_method ?? '') && isXRev(sku),
|
|
197
212
|
}
|
|
@@ -283,15 +298,16 @@ server.registerTool(
|
|
|
283
298
|
{
|
|
284
299
|
title: 'Upload files to PLM by SKU',
|
|
285
300
|
description:
|
|
286
|
-
"Bulk-upload local files (
|
|
301
|
+
"Bulk-upload local files (SolidWorks STEP/PDF exports, or any other file: zip, image, Word, Excel, PowerPoint…) into the LionsBot PLM. " +
|
|
287
302
|
"Each file is attached to an existing component by its SKU: it lands in PLM storage and is " +
|
|
288
303
|
"mirrored into that SKU's Google Drive folder on the part's own drive (staging or main; folder " +
|
|
289
304
|
"auto-created if missing). A SKU that is not in the PLM is refused. Re-uploading a file with " +
|
|
290
305
|
"the same name replaces it in place rather than duplicating. A PDF is then read like a PLM " +
|
|
291
306
|
"upload: a LionsBot drawing of that SKU fills the part's title-block fields (material, colour, " +
|
|
292
307
|
"drawing REV, method), which lists an injection moulded X revision in Injection Mold Staging. " +
|
|
293
|
-
"
|
|
294
|
-
"LEFT REV00.pdf`);
|
|
308
|
+
"STEP and LionsBot drawing PDF names should read `[SKU] Part Name REV0X` (e.g. `[SKN-0176-X1] DEPTH " +
|
|
309
|
+
"CAMERA COVER LEFT REV00.pdf`); any other file (datasheet, report…) only starts with `[SKU] `. One that " +
|
|
310
|
+
"doesn't is still uploaded but comes back with a name_issue: tell the user. " +
|
|
295
311
|
"You must supply the SKU for each file — the caller's own tooling (e.g. a SolidWorks MCP) " +
|
|
296
312
|
"already knows each part's SKU.",
|
|
297
313
|
inputSchema: {
|
|
@@ -301,7 +317,7 @@ server.registerTool(
|
|
|
301
317
|
path: z.string().describe('Absolute local path to the file to upload.'),
|
|
302
318
|
sku: z.string().describe('Component SKU this file belongs to, e.g. MNT-1234-A0.'),
|
|
303
319
|
category: z
|
|
304
|
-
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file', 'DFM report'])
|
|
320
|
+
.enum(['Compliance', 'Datasheet', 'Quotation', 'Software', 'Drawing', '3D file', 'DFM report', 'Other'])
|
|
305
321
|
.optional()
|
|
306
322
|
.describe('PLM file category. Leave it out and the PLM guesses one from the file name.'),
|
|
307
323
|
}),
|
|
@@ -322,7 +338,7 @@ server.registerTool(
|
|
|
322
338
|
if (!c) throw new Error('not in the PLM, nothing uploaded (create the component first)')
|
|
323
339
|
const up = await uploadOne({ path: f.path, sku: c.sku, skuName: c.name, category: f.category, bucket: driveOf(c) })
|
|
324
340
|
const read = isPdf(up.file) && up.driveFileId ? await readDrawing(c.id, c.sku, up.driveFileId, up.file) : undefined
|
|
325
|
-
results.push({ ok: true, ...up, read, name_issue: fileNameIssue(up.file, c.sku) })
|
|
341
|
+
results.push({ ok: true, ...up, read, name_issue: fileNameIssue(up.file, c.sku, !!read?.lionsbot) })
|
|
326
342
|
} catch (e) {
|
|
327
343
|
results.push({ ok: false, file: basename(f.path), sku, error: e instanceof Error ? e.message : String(e) })
|
|
328
344
|
}
|
|
@@ -486,7 +502,7 @@ server.registerTool(
|
|
|
486
502
|
path, sku: created.new_sku, skuName: c.name, bucket: 'staging', docType: kind,
|
|
487
503
|
audit: kind === 'DRAWING' ? { drawing_sku: drawing?.sku ?? null, drawing_rev: drawing?.rev ?? null, warnings } : undefined,
|
|
488
504
|
})
|
|
489
|
-
files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
|
|
505
|
+
files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku, kind === 'DRAWING') })
|
|
490
506
|
if (kind === 'DRAWING' && up.driveFileId) read = await readDrawing(created.new_id, created.new_sku, up.driveFileId, name)
|
|
491
507
|
lines.push(`✓ ${name}${kind === 'DRAWING' ? readLine(read) : ''}${issueLine(files.at(-1).name_issue)}`)
|
|
492
508
|
}
|
|
@@ -788,9 +804,10 @@ if (process.argv.includes('--selftest')) {
|
|
|
788
804
|
assert(JSON.stringify(stagingFilter('all')) === '{}', 'all -> no filter')
|
|
789
805
|
// ported rules (same cases as the PLM's injectionMould.test.ts)
|
|
790
806
|
assert(fileNameIssue('[SKN-0176-X1] DEPTH CAMERA COVER LEFT REV00.STEP', 'SKN-0176-X1') === null, 'named right')
|
|
791
|
-
assert(fileNameIssue('
|
|
792
|
-
assert(fileNameIssue('
|
|
793
|
-
assert(fileNameIssue('[SKN-0176-
|
|
807
|
+
assert(fileNameIssue('[SKN-0176-X1] Datasheet 2420R.pdf', 'SKN-0176-X1') === null, 'other file: SKU in front is enough')
|
|
808
|
+
assert(fileNameIssue('notes.xlsx', 'SKN-0176-X1'), 'other file without the SKU flagged')
|
|
809
|
+
assert(fileNameIssue('[SKN-0176-X1] DEPTH CAMERA COVER LEFT.pdf', 'SKN-0176-X1', true), 'drawing without REV flagged')
|
|
810
|
+
assert(fileNameIssue('[SKN-0176-X0] DEPTH CAMERA COVER LEFT REV00.pdf', 'SKN-0176-X1', true), 'other rev flagged')
|
|
794
811
|
assert(nextRev('MNT-1234-X1').newSku === 'MNT-1234-X2', 'X1 -> X2')
|
|
795
812
|
assert(nextRev('MNT-1234-X9').newSku === 'MNT-1234-X10' && nextRev('MNT-1234-X98').newSku === 'MNT-1234-X99', 'X9 → X10, X98 → X99')
|
|
796
813
|
assert(nextRev('MNT-1234-X99').error && nextRev('MNT-1234-A0').error, 'X99 and A0 refused')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plm-upload-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.1",
|
|
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"],
|