@nbakka/mcp-appium 2.0.51 → 2.0.53

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 +40 -19
  2. package/package.json +1 -1
package/lib/server.js CHANGED
@@ -15,7 +15,7 @@ const png_1 = require("./png");
15
15
  const image_utils_1 = require("./image-utils");
16
16
  const { google } = require('googleapis');
17
17
  const axios = require('axios');
18
- import OpenAI from "openai";
18
+ const OpenAI = require("openai");
19
19
  const getAgentVersion = () => {
20
20
  const json = require("../package.json");
21
21
  return json.version;
@@ -476,20 +476,33 @@ const createMcpServer = () => {
476
476
  }
477
477
 
478
478
  // ----------------------
479
- // Helper: Extract File ID
479
+ // Helper: Extract File ID & Node ID
480
480
  // ----------------------
481
- function extractFileIdFromUrl(url) {
481
+ function extractFileAndNodeId(url) {
482
482
  const patterns = [
483
483
  /figma\.com\/file\/([a-zA-Z0-9]+)/,
484
484
  /figma\.com\/design\/([a-zA-Z0-9]+)/,
485
485
  /figma\.com\/proto\/([a-zA-Z0-9]+)/
486
486
  ];
487
487
 
488
+ let fileId = null;
488
489
  for (const pattern of patterns) {
489
490
  const match = url.match(pattern);
490
- if (match) return match[1];
491
+ if (match) {
492
+ fileId = match[1];
493
+ break;
494
+ }
495
+ }
496
+
497
+ // Extract node-id if present
498
+ const nodeMatch = url.match(/[?&]node-id=([^&]+)/);
499
+ let nodeId = null;
500
+ if (nodeMatch) {
501
+ // Replace dash with colon (Figma expects 13:5951 instead of 13-5951)
502
+ nodeId = decodeURIComponent(nodeMatch[1]).replace(/-/g, ":");
491
503
  }
492
- return null;
504
+
505
+ return { fileId, nodeId };
493
506
  }
494
507
 
495
508
  // ----------------------
@@ -510,31 +523,38 @@ tool(
510
523
 
511
524
  if (!figmaToken) throw new Error("Figma API token missing in figma.json");
512
525
 
513
- // Extract file ID from URL
514
- const fileId = extractFileIdFromUrl(figmaUrl);
526
+ // Extract fileId and nodeId from URL
527
+ const { fileId, nodeId } = extractFileAndNodeId(figmaUrl);
515
528
  if (!fileId) throw new Error("Invalid Figma URL - cannot extract fileId");
516
529
 
517
- // Get file structure to find frames
518
- const fileResponse = await axios.get(
519
- `https://api.figma.com/v1/files/${fileId}`,
520
- { headers: { "X-Figma-Token": figmaToken } }
521
- );
530
+ let idsToExport = [];
522
531
 
523
- const frameIds = [];
524
- fileResponse.data.document.children?.forEach(page => {
525
- page.children?.forEach(child => {
526
- if (child.type === "FRAME") frameIds.push(child.id);
532
+ if (nodeId) {
533
+ // Use node-id directly from URL
534
+ idsToExport = [nodeId];
535
+ } else {
536
+ // Fallback: scan file to collect all top-level frames
537
+ const fileResponse = await axios.get(
538
+ `https://api.figma.com/v1/files/${fileId}`,
539
+ { headers: { "X-Figma-Token": figmaToken } }
540
+ );
541
+
542
+ fileResponse.data.document.children?.forEach(page => {
543
+ page.children?.forEach(child => {
544
+ if (child.type === "FRAME") idsToExport.push(child.id);
545
+ });
527
546
  });
528
- });
529
547
 
530
- if (frameIds.length === 0) throw new Error("No frames found in Figma file");
548
+ if (idsToExport.length === 0)
549
+ throw new Error("No frames found in Figma file");
550
+ }
531
551
 
532
552
  // Request PDF export
533
553
  const exportResponse = await axios.get(
534
554
  `https://api.figma.com/v1/images/${fileId}`,
535
555
  {
536
556
  headers: { "X-Figma-Token": figmaToken },
537
- params: { ids: frameIds.join(","), format: "pdf" }
557
+ params: { ids: idsToExport.join(","), format: "pdf" }
538
558
  }
539
559
  );
540
560
 
@@ -558,6 +578,7 @@ tool(
558
578
  }
559
579
  );
560
580
 
581
+
561
582
  // ----------------------
562
583
  // TOOL 2: Upload PDF to OpenAI with Jira Info
563
584
  // ----------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nbakka/mcp-appium",
3
- "version": "2.0.51",
3
+ "version": "2.0.53",
4
4
  "description": "Appium MCP",
5
5
  "engines": {
6
6
  "node": ">=18"