plm-upload-mcp 1.3.7 → 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 +20 -11
  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()
@@ -225,6 +225,9 @@ async function uploadOne({ path, sku, skuName, category, bucket, filename = base
225
225
  bucket,
226
226
  // The pick goes on with the upload: set-category afterwards needs View files for the file's guessed category.
227
227
  ...(category ? { category } : {}),
228
+ // The edge writes the component.file_uploaded history row (with these fields).
229
+ ...(docType ? { docType } : {}),
230
+ ...(auditExtra ? { audit: auditExtra } : {}),
228
231
  })
229
232
  if (synced?.error) throw new Error(synced.error)
230
233
 
@@ -249,7 +252,6 @@ async function readDrawing(componentId, sku, fileId, filename) {
249
252
  } catch (e) {
250
253
  res = { error: e instanceof Error ? e.message : String(e) }
251
254
  }
252
- if (res.written) await audit(componentId, 'component.drawing_extracted', { file: filename, extracted: res.extracted ?? null })
253
255
  return readOutcome(res, sku)
254
256
  }
255
257
 
@@ -345,16 +347,18 @@ server.registerTool(
345
347
  description: "Lists the files currently in a component's Google Drive folder in the PLM, by SKU.",
346
348
  inputSchema: {
347
349
  sku: z.string().describe('Component SKU, e.g. MNT-1234-A0.'),
348
- 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)."),
349
351
  },
350
352
  annotations: { readOnlyHint: true, openWorldHint: true },
351
353
  },
352
- async ({ sku, bucket = 'main' }) => {
353
- 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') })
354
357
  const files = Array.isArray(data?.files) ? data.files : []
355
358
  if (!data?.connected) {
356
359
  return { content: [{ type: 'text', text: `Drive not connected or no folder for ${sku}.` }], structuredContent: { connected: false, files: [] } }
357
360
  }
361
+ if (!data.folder) return { content: [{ type: 'text', text: `No Drive folder for ${sku} yet.` }], structuredContent: { connected: true, folder: null, files: [] } }
358
362
  const lines = files.map((x) => `• ${x.name}${x.appProperties?.plmCategory ? ` [${x.appProperties.plmCategory}]` : ''}`)
359
363
  return {
360
364
  content: [{ type: 'text', text: files.length ? `${sku} — ${files.length} file(s):\n${lines.join('\n')}` : `${sku} — folder is empty.` }],
@@ -478,12 +482,11 @@ server.registerTool(
478
482
  for (const [path, kind] of [[drawing_pdf, 'DRAWING'], [step, 'STEP']]) {
479
483
  if (!path) continue
480
484
  const name = basename(path)
481
- const up = await uploadOne({ path, sku: created.new_sku, skuName: c.name, bucket: 'staging' })
482
- files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
483
- await audit(created.new_id, 'component.file_uploaded', {
484
- file: name,
485
- ...(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,
486
488
  })
489
+ files.push({ ...up, name_issue: fileNameIssue(name, created.new_sku) })
487
490
  if (kind === 'DRAWING' && up.driveFileId) read = await readDrawing(created.new_id, created.new_sku, up.driveFileId, name)
488
491
  lines.push(`✓ ${name}${kind === 'DRAWING' ? readLine(read) : ''}${issueLine(files.at(-1).name_issue)}`)
489
492
  }
@@ -580,7 +583,13 @@ server.registerTool(
580
583
  } else {
581
584
  params.limit = String(limit)
582
585
  params.offset = String(offset)
583
- 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
+ }
584
593
  if (category) params.category = `eq.${category}`
585
594
  if (status) params.status = `eq.${status}`
586
595
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plm-upload-mcp",
3
- "version": "1.3.7",
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"],