plm-upload-mcp 1.5.0 → 1.6.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.
Files changed (3) hide show
  1. package/README.md +15 -0
  2. package/index.mjs +83 -17
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -65,6 +65,21 @@ for an empty folder: an upload makes the folder too.
65
65
 
66
66
  - `skus`: array of component SKUs
67
67
 
68
+ ### `create_drive_folder` (Lucas and Benjamin only)
69
+ Creates a folder path anywhere in the PLM Shared Drive, like `mkdir -p`. A new folder at
70
+ the drive root may not hold `[` (it would be read as a part). The PLM refuses everyone but Lucas and Benjamin.
71
+
72
+ - `path`: folder path from the drive root, e.g. `Templates/Drawing`
73
+ - `drive`: `main` (default) or `staging`
74
+
75
+ ### `create_component` (Lucas and Benjamin only)
76
+ Creates a component the same as the PLM's New component form, plus its `[SKU] Name` Drive
77
+ folder. Without `sku` it takes the next number (staging: a T number). The PLM refuses everyone but Lucas and Benjamin.
78
+
79
+ - `name`, `category` (3 letters), `sku_type` (`component` / `assembly` / `consumable` / `other`)
80
+ - `staging`: default `true`
81
+ - `sku`: optional, the SKU to use instead of the next number (required for `other`)
82
+
68
83
  ### `uprev_component`
69
84
  Uprevs a staging prototype to its next X revision (`MNT-1234-X1` → `MNT-1234-X2`), the
70
85
  same as **Uprev** in the PLM: a new component carrying the old one's details, with its
package/index.mjs CHANGED
@@ -159,13 +159,15 @@ function nextRev(sku) {
159
159
  return { newSku: `${m[1]}-${m[2]}-X${Number(m[3]) + 1}` }
160
160
  }
161
161
 
162
- /** Why a drawing PDF or STEP named `name` breaks the naming rule
163
- * `[SKU] Part Name REV0X` for `sku`; null when it follows it or is another
164
- * file type. A prompt only: the upload still goes ahead. */
165
- function fileNameIssue(name, sku) {
166
- const stem = /^(.*)\.(pdf|step|stp)$/i.exec(name)?.[1]
167
- 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) {
168
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(/\.[^.]+$/, '')
169
171
  const ok = stem.toUpperCase().startsWith(head) && /^\S.* REV\d{2}$/i.test(stem.slice(head.length))
170
172
  return ok ? null : `${name} is not named "[${sku}] Part Name REV0X".`
171
173
  }
@@ -192,17 +194,19 @@ function drawingWarnings(read, newSku, prev) {
192
194
  return out
193
195
  }
194
196
 
195
- /** 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. */
196
198
  function readOutcome(res, sku) {
197
- 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
198
201
  if (!res.written) {
199
202
  const text = res.extracted?.is_lionsbot === false
200
203
  ? 'Not a LionsBot drawing, nothing read'
201
204
  : `Drawing says ${res.sku_check?.drawing_sku ?? 'no SKU'}, not ${sku}: nothing read`
202
- return { ok: false, text, listed: false }
205
+ return { ok: false, text, listed: false, lionsbot }
203
206
  }
204
207
  return {
205
208
  ok: true,
209
+ lionsbot,
206
210
  text: `Drawing read${res.extracted?.rev ? ` · REV ${res.extracted.rev}` : ''}`,
207
211
  listed: IM_METHOD.test(res.extracted?.manufacturing_method ?? '') && isXRev(sku),
208
212
  }
@@ -287,7 +291,7 @@ const readLine = (read) => (read ? ` · ${read.text}${read.listed ? ' · now in
287
291
  const issueLine = (issue) => (issue ? `\n ⚠ ${issue} Tell the user.` : '')
288
292
 
289
293
  // --- Server ------------------------------------------------------------------
290
- const server = new McpServer({ name: 'plm-upload', version: '1.3.2' })
294
+ const server = new McpServer({ name: 'plm-upload', version: '1.6.0' })
291
295
 
292
296
  server.registerTool(
293
297
  'upload_files',
@@ -301,8 +305,9 @@ server.registerTool(
301
305
  "the same name replaces it in place rather than duplicating. A PDF is then read like a PLM " +
302
306
  "upload: a LionsBot drawing of that SKU fills the part's title-block fields (material, colour, " +
303
307
  "drawing REV, method), which lists an injection moulded X revision in Injection Mold Staging. " +
304
- "PDF and STEP names should read `[SKU] Part Name REV0X` (e.g. `[SKN-0176-X1] DEPTH CAMERA COVER " +
305
- "LEFT REV00.pdf`); one that doesn't is still uploaded but comes back with a name_issue: tell the user. " +
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. " +
306
311
  "You must supply the SKU for each file — the caller's own tooling (e.g. a SolidWorks MCP) " +
307
312
  "already knows each part's SKU.",
308
313
  inputSchema: {
@@ -333,7 +338,7 @@ server.registerTool(
333
338
  if (!c) throw new Error('not in the PLM, nothing uploaded (create the component first)')
334
339
  const up = await uploadOne({ path: f.path, sku: c.sku, skuName: c.name, category: f.category, bucket: driveOf(c) })
335
340
  const read = isPdf(up.file) && up.driveFileId ? await readDrawing(c.id, c.sku, up.driveFileId, up.file) : undefined
336
- 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) })
337
342
  } catch (e) {
338
343
  results.push({ ok: false, file: basename(f.path), sku, error: e instanceof Error ? e.message : String(e) })
339
344
  }
@@ -418,6 +423,66 @@ server.registerTool(
418
423
  },
419
424
  )
420
425
 
426
+ // Lucas and Benjamin only: the PLM edge refuses everyone else (access.ts mayDriveAnywhere).
427
+ const refusedReply = (e) => ({ content: [{ type: 'text', text: e instanceof Error ? e.message : String(e) }], isError: true })
428
+
429
+ server.registerTool(
430
+ 'create_drive_folder',
431
+ {
432
+ title: 'Create a folder anywhere in the PLM Drive (Lucas and Benjamin only)',
433
+ description:
434
+ 'Creates a folder path anywhere in the PLM Google Shared Drive, like mkdir -p: each missing folder of ' +
435
+ '`path` (from the drive root) is made, existing ones are reused. A new folder at the drive root may not ' +
436
+ 'hold "[" (it would be read as a part): use create_component for a part. Only Lucas and Benjamin may call it; the PLM ' +
437
+ 'refuses everyone else.',
438
+ inputSchema: {
439
+ path: z.string().min(1).describe('Folder path from the drive root, e.g. "Templates/Drawing".'),
440
+ drive: z.enum(['main', 'staging']).default('main').describe('The main drive or the staging drive.'),
441
+ },
442
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
443
+ },
444
+ async ({ path, drive }) => {
445
+ try {
446
+ const r = await edgeJson({ action: 'create-drive-folder', path, bucket: drive })
447
+ const made = r.created?.length ? `created ${r.created.join(' / ')}` : 'already there'
448
+ return { content: [{ type: 'text', text: `✓ ${path} (${drive}): ${made} ${r.folderUrl}` }], structuredContent: { drive, ...r } }
449
+ } catch (e) {
450
+ return refusedReply(e)
451
+ }
452
+ },
453
+ )
454
+
455
+ server.registerTool(
456
+ 'create_component',
457
+ {
458
+ title: 'Create a PLM component and its Drive folder (Lucas and Benjamin only)',
459
+ description:
460
+ 'Creates a component in the PLM, the same as its New component form, and its `[SKU] Name` Drive ' +
461
+ 'folder. Leave `sku` out to take the next number: a staging part gets a T number (MNT-T000123), a main ' +
462
+ 'component CAT-####-A0, an assembly CAT-#####-01, a consumable CAT-####. Only Lucas and Benjamin may call it; the PLM ' +
463
+ 'refuses everyone else.',
464
+ inputSchema: {
465
+ name: z.string().min(1).describe('Part name.'),
466
+ category: z.string().regex(/^[A-Za-z]{3}$/).describe('Three-letter category code, e.g. MNT.'),
467
+ sku_type: z.enum(['component', 'assembly', 'consumable', 'other']).describe('SKU type.'),
468
+ staging: z.boolean().default(true).describe('true = a staging (draft) part on the staging drive.'),
469
+ sku: z.string().optional().describe('The SKU to use instead of the next number (required for type other).'),
470
+ },
471
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
472
+ },
473
+ async ({ name, category, sku_type, staging, sku }) => {
474
+ const row = { name: name.trim(), category: category.toUpperCase(), sku_type, staging, ...(sku ? { sku: sku.trim().toUpperCase() } : {}) }
475
+ try {
476
+ const r = await edgeJson({ action: 'create-component', row, mint: !sku })
477
+ const c = r.component
478
+ const folder = r.folder?.folderUrl ? `folder ${r.folder.folderUrl}` : `no folder: ${r.folder?.error ?? 'Drive not connected'}`
479
+ return { content: [{ type: 'text', text: `✓ ${c.sku} ${c.name} (${c.staging ? 'staging' : 'main'}), ${folder}` }], structuredContent: r }
480
+ } catch (e) {
481
+ return refusedReply(e)
482
+ }
483
+ },
484
+ )
485
+
421
486
  server.registerTool(
422
487
  'uprev_component',
423
488
  {
@@ -497,7 +562,7 @@ server.registerTool(
497
562
  path, sku: created.new_sku, skuName: c.name, bucket: 'staging', docType: kind,
498
563
  audit: kind === 'DRAWING' ? { drawing_sku: drawing?.sku ?? null, drawing_rev: drawing?.rev ?? null, warnings } : undefined,
499
564
  })
500
- files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
565
+ files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku, kind === 'DRAWING') })
501
566
  if (kind === 'DRAWING' && up.driveFileId) read = await readDrawing(created.new_id, created.new_sku, up.driveFileId, name)
502
567
  lines.push(`✓ ${name}${kind === 'DRAWING' ? readLine(read) : ''}${issueLine(files.at(-1).name_issue)}`)
503
568
  }
@@ -799,9 +864,10 @@ if (process.argv.includes('--selftest')) {
799
864
  assert(JSON.stringify(stagingFilter('all')) === '{}', 'all -> no filter')
800
865
  // ported rules (same cases as the PLM's injectionMould.test.ts)
801
866
  assert(fileNameIssue('[SKN-0176-X1] DEPTH CAMERA COVER LEFT REV00.STEP', 'SKN-0176-X1') === null, 'named right')
802
- assert(fileNameIssue('notes.xlsx', 'SKN-0176-X1') === null, 'other file type not checked')
803
- assert(fileNameIssue('[SKN-0176-X1] DEPTH CAMERA COVER LEFT.pdf', 'SKN-0176-X1'), 'no REV flagged')
804
- assert(fileNameIssue('[SKN-0176-X0] DEPTH CAMERA COVER LEFT REV00.pdf', 'SKN-0176-X1'), 'other rev flagged')
867
+ assert(fileNameIssue('[SKN-0176-X1] Datasheet 2420R.pdf', 'SKN-0176-X1') === null, 'other file: SKU in front is enough')
868
+ assert(fileNameIssue('notes.xlsx', 'SKN-0176-X1'), 'other file without the SKU flagged')
869
+ assert(fileNameIssue('[SKN-0176-X1] DEPTH CAMERA COVER LEFT.pdf', 'SKN-0176-X1', true), 'drawing without REV flagged')
870
+ assert(fileNameIssue('[SKN-0176-X0] DEPTH CAMERA COVER LEFT REV00.pdf', 'SKN-0176-X1', true), 'other rev flagged')
805
871
  assert(nextRev('MNT-1234-X1').newSku === 'MNT-1234-X2', 'X1 -> X2')
806
872
  assert(nextRev('MNT-1234-X9').newSku === 'MNT-1234-X10' && nextRev('MNT-1234-X98').newSku === 'MNT-1234-X99', 'X9 → X10, X98 → X99')
807
873
  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.5.0",
3
+ "version": "1.6.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"],