plm-upload-mcp 1.3.6 → 1.3.8

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 +1 -1
  2. package/index.mjs +22 -15
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -88,7 +88,7 @@ Example ask: *"Uprev MNT-1234-X1 with C:\exports\bracket.pdf and C:\exports\brac
88
88
  Lists the files currently in a component's Drive folder.
89
89
 
90
90
  - `sku`: component SKU
91
- - `bucket`: `main` (default) or `staging`
91
+ - `bucket`: `main` or `staging` (default: the part's own drive)
92
92
 
93
93
  ## Read-only tools
94
94
 
package/index.mjs CHANGED
@@ -198,7 +198,7 @@ function readOutcome(res, sku) {
198
198
  }
199
199
 
200
200
  /** store bytes → storagePath, then upload → mirror into the SKU's Drive folder. */
201
- async function uploadOne({ path, sku, skuName, category, bucket, filename = basename(path) }) {
201
+ async function uploadOne({ path, sku, skuName, category, bucket, filename = basename(path), docType, audit: auditExtra }) {
202
202
  const bytes = await readFile(path) // throws ENOENT with the path — surfaced per-file below
203
203
  const mimeType = mimeFor(filename)
204
204
  const token = await getToken()
@@ -223,13 +223,14 @@ async function uploadOne({ path, sku, skuName, category, bucket, filename = base
223
223
  filename,
224
224
  mimeType,
225
225
  bucket,
226
+ // The pick goes on with the upload: set-category afterwards needs View files for the file's guessed category.
227
+ ...(category ? { category } : {}),
228
+ // The edge writes the component.file_uploaded history row (with these fields).
229
+ ...(docType ? { docType } : {}),
230
+ ...(auditExtra ? { audit: auditExtra } : {}),
226
231
  })
227
232
  if (synced?.error) throw new Error(synced.error)
228
233
 
229
- if (category && synced?.driveFileId) {
230
- await edgeJson({ action: 'set-category', fileId: synced.driveFileId, category }).catch(() => {})
231
- }
232
-
233
234
  return {
234
235
  file: filename,
235
236
  sku,
@@ -251,7 +252,6 @@ async function readDrawing(componentId, sku, fileId, filename) {
251
252
  } catch (e) {
252
253
  res = { error: e instanceof Error ? e.message : String(e) }
253
254
  }
254
- if (res.written) await audit(componentId, 'component.drawing_extracted', { file: filename, extracted: res.extracted ?? null })
255
255
  return readOutcome(res, sku)
256
256
  }
257
257
 
@@ -347,16 +347,18 @@ server.registerTool(
347
347
  description: "Lists the files currently in a component's Google Drive folder in the PLM, by SKU.",
348
348
  inputSchema: {
349
349
  sku: z.string().describe('Component SKU, e.g. MNT-1234-A0.'),
350
- bucket: z.enum(['main', 'staging']).optional().describe("'main' (default) or 'staging'."),
350
+ bucket: z.enum(['main', 'staging']).optional().describe("'main' or 'staging' (default: the part's own drive)."),
351
351
  },
352
352
  annotations: { readOnlyHint: true, openWorldHint: true },
353
353
  },
354
- async ({ sku, bucket = 'main' }) => {
355
- const data = await edgeJson({ action: 'list', sku, bucket })
354
+ async ({ sku, bucket }) => {
355
+ const c = bucket ? null : await findComponent(sku)
356
+ const data = await edgeJson({ action: 'list', sku, bucket: bucket ?? (c ? driveOf(c) : 'main') })
356
357
  const files = Array.isArray(data?.files) ? data.files : []
357
358
  if (!data?.connected) {
358
359
  return { content: [{ type: 'text', text: `Drive not connected or no folder for ${sku}.` }], structuredContent: { connected: false, files: [] } }
359
360
  }
361
+ if (!data.folder) return { content: [{ type: 'text', text: `No Drive folder for ${sku} yet.` }], structuredContent: { connected: true, folder: null, files: [] } }
360
362
  const lines = files.map((x) => `• ${x.name}${x.appProperties?.plmCategory ? ` [${x.appProperties.plmCategory}]` : ''}`)
361
363
  return {
362
364
  content: [{ type: 'text', text: files.length ? `${sku} — ${files.length} file(s):\n${lines.join('\n')}` : `${sku} — folder is empty.` }],
@@ -480,12 +482,11 @@ server.registerTool(
480
482
  for (const [path, kind] of [[drawing_pdf, 'DRAWING'], [step, 'STEP']]) {
481
483
  if (!path) continue
482
484
  const name = basename(path)
483
- const up = await uploadOne({ path, sku: created.new_sku, skuName: c.name, bucket: 'staging' })
484
- files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
485
- await audit(created.new_id, 'component.file_uploaded', {
486
- file: name,
487
- ...(kind === 'DRAWING' ? { drawing_sku: drawing?.sku ?? null, drawing_rev: drawing?.rev ?? null, warnings } : {}),
485
+ const up = await uploadOne({
486
+ path, sku: created.new_sku, skuName: c.name, bucket: 'staging', docType: kind,
487
+ audit: kind === 'DRAWING' ? { drawing_sku: drawing?.sku ?? null, drawing_rev: drawing?.rev ?? null, warnings } : undefined,
488
488
  })
489
+ files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
489
490
  if (kind === 'DRAWING' && up.driveFileId) read = await readDrawing(created.new_id, created.new_sku, up.driveFileId, name)
490
491
  lines.push(`✓ ${name}${kind === 'DRAWING' ? readLine(read) : ''}${issueLine(files.at(-1).name_issue)}`)
491
492
  }
@@ -582,7 +583,13 @@ server.registerTool(
582
583
  } else {
583
584
  params.limit = String(limit)
584
585
  params.offset = String(offset)
585
- if (search) params.or = `(sku.ilike.*${search}*,name.ilike.*${search}*)`
586
+ // Port of the PLM's ilikeOr (src/hooks/useSearch.ts): % and _ literal, the value double-quoted (escaping
587
+ // \ and ") so a comma or parenthesis in the search can't break the filter.
588
+ if (search) {
589
+ const pattern = `%${search.replace(/[%_]/g, (m) => '\\' + m)}%`
590
+ const v = `"${pattern.replace(/[\\"]/g, (m) => '\\' + m)}"`
591
+ params.or = `(sku.ilike.${v},name.ilike.${v})`
592
+ }
586
593
  if (category) params.category = `eq.${category}`
587
594
  if (status) params.status = `eq.${status}`
588
595
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plm-upload-mcp",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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"],