@nbakka/mcp-appium 2.0.46 → 2.0.47

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/lib/server.js +72 -11
  2. package/package.json +1 -1
package/lib/server.js CHANGED
@@ -523,7 +523,39 @@ tool(
523
523
  // Continue if cleanup fails
524
524
  }
525
525
 
526
- // Request PDF export of entire file
526
+ // First, get the file structure to find all top-level frames
527
+ const fileResponse = await axios.get(
528
+ `https://api.figma.com/v1/files/${fileId}`,
529
+ {
530
+ headers: {
531
+ 'X-Figma-Token': figmaToken
532
+ }
533
+ }
534
+ );
535
+
536
+ const fileData = fileResponse.data;
537
+
538
+ // Extract all top-level frame IDs
539
+ const frameIds = [];
540
+ if (fileData.document.children && Array.isArray(fileData.document.children)) {
541
+ fileData.document.children.forEach(page => {
542
+ if (page.children && Array.isArray(page.children)) {
543
+ page.children.forEach(child => {
544
+ if (child.type === 'FRAME') {
545
+ frameIds.push(child.id);
546
+ }
547
+ });
548
+ }
549
+ });
550
+ }
551
+
552
+ if (frameIds.length === 0) {
553
+ throw new Error('No frames found in the Figma file');
554
+ }
555
+
556
+ console.log(`Found ${frameIds.length} top-level frames:`, frameIds.slice(0, 5));
557
+
558
+ // Request PDF export with specific frame IDs
527
559
  const exportResponse = await axios.get(
528
560
  `https://api.figma.com/v1/images/${fileId}`,
529
561
  {
@@ -531,12 +563,23 @@ tool(
531
563
  'X-Figma-Token': figmaToken
532
564
  },
533
565
  params: {
534
- format: 'pdf'
566
+ ids: frameIds.join(','),
567
+ format: 'pdf',
568
+ use_absolute_bounds: false
535
569
  }
536
570
  }
537
571
  );
538
572
 
539
- const pdfUrl = exportResponse.data.images[fileId];
573
+ console.log('Export response:', exportResponse.data);
574
+
575
+ // For PDF export, the response structure might be different
576
+ let pdfUrl = null;
577
+ if (exportResponse.data.images) {
578
+ // Try to get PDF URL - might be under file ID or first frame ID
579
+ pdfUrl = exportResponse.data.images[fileId] ||
580
+ exportResponse.data.images[frameIds[0]] ||
581
+ Object.values(exportResponse.data.images)[0];
582
+ }
540
583
 
541
584
  if (!pdfUrl) {
542
585
  throw new Error('Failed to get PDF export URL from Figma');
@@ -557,13 +600,33 @@ Export Path: ${pdfPath}
557
600
  File: figma-export-${timestamp}.pdf`;
558
601
 
559
602
  } catch (error) {
560
- if (error.response && error.response.status === 403) {
561
- return `Error: Access denied. Please check your Figma API token and file permissions.`;
562
- } else if (error.response && error.response.status === 404) {
563
- return `Error: Figma file not found. Please check the URL and ensure the file is accessible.`;
564
- } else {
565
- return `Error exporting from Figma: ${error.message}`;
603
+ // Enhanced error logging
604
+ let errorMessage = error.message;
605
+
606
+ if (error.response) {
607
+ const status = error.response.status;
608
+ const responseData = error.response.data;
609
+
610
+ console.error('Figma API Error:', {
611
+ status,
612
+ statusText: error.response.statusText,
613
+ data: responseData,
614
+ url: error.config?.url,
615
+ params: error.config?.params
616
+ });
617
+
618
+ if (status === 400) {
619
+ errorMessage = `Bad Request (400): ${responseData?.message || responseData?.err || 'Invalid request parameters'}. This might be due to PDF export limitations or invalid frame IDs.`;
620
+ } else if (status === 403) {
621
+ return `Error: Access denied. Please check your Figma API token and file permissions.`;
622
+ } else if (status === 404) {
623
+ return `Error: Figma file not found. Please check the URL and ensure the file is accessible.`;
624
+ } else {
625
+ errorMessage = `HTTP ${status}: ${responseData?.message || responseData?.err || error.response.statusText}`;
626
+ }
566
627
  }
628
+
629
+ return `Error exporting from Figma: ${errorMessage}`;
567
630
  }
568
631
  }
569
632
  );
@@ -584,8 +647,6 @@ function extractFileIdFromUrl(url) {
584
647
  }
585
648
  return null;
586
649
  }
587
-
588
-
589
650
  return server;
590
651
  };
591
652
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbakka/mcp-appium",
3
- "version": "2.0.46",
3
+ "version": "2.0.47",
4
4
  "description": "Appium MCP",
5
5
  "engines": {
6
6
  "node": ">=18"