@mediagraph/mcp 1.0.5 → 1.0.7

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 (2) hide show
  1. package/dist/index.js +61 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -329,26 +329,38 @@ var TokenStore = class {
329
329
  * Save tokens to encrypted file
330
330
  */
331
331
  save(data) {
332
- const dir = dirname(this.filePath);
333
- if (!existsSync(dir)) {
334
- mkdirSync(dir, { recursive: true, mode: 448 });
332
+ try {
333
+ const dir = dirname(this.filePath);
334
+ console.error(`[TokenStore] Saving tokens to: ${this.filePath}`);
335
+ if (!existsSync(dir)) {
336
+ console.error(`[TokenStore] Creating directory: ${dir}`);
337
+ mkdirSync(dir, { recursive: true, mode: 448 });
338
+ }
339
+ const encrypted = this.encrypt(JSON.stringify(data));
340
+ writeFileSync(this.filePath, encrypted, { mode: 384 });
341
+ console.error(`[TokenStore] Tokens saved successfully`);
342
+ } catch (error) {
343
+ console.error(`[TokenStore] Failed to save tokens:`, error);
344
+ throw error;
335
345
  }
336
- const encrypted = this.encrypt(JSON.stringify(data));
337
- writeFileSync(this.filePath, encrypted, { mode: 384 });
338
346
  }
339
347
  /**
340
348
  * Load tokens from encrypted file
341
349
  */
342
350
  load() {
351
+ console.error(`[TokenStore] Loading tokens from: ${this.filePath}`);
343
352
  if (!existsSync(this.filePath)) {
353
+ console.error(`[TokenStore] Token file does not exist`);
344
354
  return null;
345
355
  }
346
356
  try {
347
357
  const encrypted = readFileSync(this.filePath);
348
358
  const decrypted = this.decrypt(encrypted);
349
- return JSON.parse(decrypted);
359
+ const data = JSON.parse(decrypted);
360
+ console.error(`[TokenStore] Tokens loaded for: ${data.userEmail || "unknown"}`);
361
+ return data;
350
362
  } catch (error) {
351
- console.error("Failed to load tokens:", error);
363
+ console.error("[TokenStore] Failed to load tokens:", error);
352
364
  return null;
353
365
  }
354
366
  }
@@ -2547,7 +2559,10 @@ var uploadTools = {
2547
2559
  definitions: [
2548
2560
  {
2549
2561
  name: "upload_file",
2550
- description: `Upload a file from the local filesystem to Mediagraph.
2562
+ description: `Upload a file to Mediagraph. Supports two modes:
2563
+ 1. Local file: Provide file_path for files on the user's local filesystem
2564
+ 2. Direct upload: Provide file_data (base64-encoded) with filename for files from other sources
2565
+
2551
2566
  This creates a new asset in the user's Mediagraph library.
2552
2567
  Supports images, videos, audio, documents, and other media files.
2553
2568
  The file will be processed and thumbnails/previews generated automatically.`,
@@ -2558,12 +2573,20 @@ The file will be processed and thumbnails/previews generated automatically.`,
2558
2573
  type: "string",
2559
2574
  description: "Absolute path to the file on the local filesystem"
2560
2575
  },
2576
+ file_data: {
2577
+ type: "string",
2578
+ description: "Base64-encoded file content (use this when file_path is not available)"
2579
+ },
2580
+ filename: {
2581
+ type: "string",
2582
+ description: "Filename with extension (required when using file_data)"
2583
+ },
2561
2584
  storage_folder_id: {
2562
2585
  type: "number",
2563
2586
  description: "Optional: ID of the storage folder to upload into"
2564
2587
  }
2565
2588
  },
2566
- required: ["file_path"]
2589
+ required: []
2567
2590
  }
2568
2591
  },
2569
2592
  {
@@ -2591,22 +2614,39 @@ All files are uploaded in a single upload session.`,
2591
2614
  handlers: {
2592
2615
  async upload_file(args, { client: client2 }) {
2593
2616
  const filePath = args.file_path;
2594
- let fileStats;
2595
- try {
2596
- fileStats = await stat(filePath);
2597
- } catch {
2598
- return errorResult(`File not found: ${filePath}`);
2599
- }
2600
- if (!fileStats.isFile()) {
2601
- return errorResult(`Not a file: ${filePath}`);
2617
+ const fileDataB64 = args.file_data;
2618
+ const providedFilename = args.filename;
2619
+ let fileData;
2620
+ let filename;
2621
+ let fileSize;
2622
+ if (fileDataB64) {
2623
+ if (!providedFilename) {
2624
+ return errorResult("filename is required when using file_data");
2625
+ }
2626
+ fileData = Buffer.from(fileDataB64, "base64");
2627
+ filename = providedFilename;
2628
+ fileSize = fileData.length;
2629
+ } else if (filePath) {
2630
+ let fileStats;
2631
+ try {
2632
+ fileStats = await stat(filePath);
2633
+ } catch {
2634
+ return errorResult(`File not found: ${filePath}`);
2635
+ }
2636
+ if (!fileStats.isFile()) {
2637
+ return errorResult(`Not a file: ${filePath}`);
2638
+ }
2639
+ fileData = await readFile(filePath);
2640
+ filename = basename(filePath);
2641
+ fileSize = fileStats.size;
2642
+ } else {
2643
+ return errorResult("Either file_path or file_data (with filename) is required");
2602
2644
  }
2603
- const fileData = await readFile(filePath);
2604
- const filename = basename(filePath);
2605
2645
  const contentType = getMimeType(filename);
2606
2646
  const upload = await client2.createUpload();
2607
2647
  const preparedAsset = await client2.prepareAssetUpload(upload.guid, {
2608
2648
  filename,
2609
- file_size: fileStats.size,
2649
+ file_size: fileSize,
2610
2650
  created_via: "mcp"
2611
2651
  });
2612
2652
  await client2.uploadToSignedUrl(preparedAsset.signed_upload_url, fileData, contentType);
@@ -3308,14 +3348,7 @@ server.setRequestHandler(ListResourceTemplatesRequestSchema, async () => {
3308
3348
  };
3309
3349
  });
3310
3350
  server.setRequestHandler(ListResourcesRequestSchema, async () => {
3311
- let token = await getAccessToken();
3312
- if (!token) {
3313
- const authSuccess = await runAutoAuth();
3314
- if (!authSuccess) {
3315
- return { resources: [] };
3316
- }
3317
- token = await getAccessToken();
3318
- }
3351
+ const token = await getAccessToken();
3319
3352
  if (!token) {
3320
3353
  return { resources: [] };
3321
3354
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mediagraph/mcp",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "MCP server for Mediagraph - Media Asset Management Platform",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",