Skip to main content
Glama
paragdesai1

Cursor Talk to Figma MCP

by paragdesai1

read_my_design

Retrieve detailed information about selected elements in Figma designs, including node specifications and properties, for design analysis and integration workflows.

Instructions

Get detailed information about the current selection in Figma, including all node details

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool registration for 'read_my_design'. Defines the tool with no input parameters and handler that forwards the command to Figma plugin via sendCommandToFigma and returns the JSON result.
    server.tool(
      "read_my_design",
      "Get detailed information about the current selection in Figma, including all node details",
      {},
      async () => {
        try {
          const result = await sendCommandToFigma("read_my_design", {});
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(result)
              }
            ]
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error getting node info: ${error instanceof Error ? error.message : String(error)
                  }`,
              },
            ],
          };
        }
      }
    );
  • Core handler function 'readMyDesign' that processes the current Figma selection: loads nodes, exports them as JSON using Figma's JSON_REST_V1 format, filters with filterFigmaNode, and returns array of processed node documents.
    async function readMyDesign() {
      try {
        // Load all selected nodes in parallel
        const nodes = await Promise.all(
          figma.currentPage.selection.map((node) => figma.getNodeByIdAsync(node.id))
        );
    
        // Filter out any null values (nodes that weren't found)
        const validNodes = nodes.filter((node) => node !== null);
    
        // Export all valid nodes in parallel
        const responses = await Promise.all(
          validNodes.map(async (node) => {
            const response = await node.exportAsync({
              format: "JSON_REST_V1",
            });
            return {
              nodeId: node.id,
              document: filterFigmaNode(response.document),
            };
          })
        );
    
        return responses;
      } catch (error) {
        throw new Error(`Error getting nodes info: ${error.message}`);
      }
    }
  • Helper function filterFigmaNode recursively processes Figma node data: skips VECTOR nodes, converts RGBA colors to HEX using rgbaToHex, removes boundVariables/imageRef, extracts relevant properties like fills/strokes/children/style/bbox for serialization.
    function filterFigmaNode(node) {
      if (node.type === "VECTOR") {
        return null;
      }
    
      var filtered = {
        id: node.id,
        name: node.name,
        type: node.type,
      };
    
      if (node.fills && node.fills.length > 0) {
        filtered.fills = node.fills.map((fill) => {
          var processedFill = Object.assign({}, fill);
          delete processedFill.boundVariables;
          delete processedFill.imageRef;
    
          if (processedFill.gradientStops) {
            processedFill.gradientStops = processedFill.gradientStops.map(
              (stop) => {
                var processedStop = Object.assign({}, stop);
                if (processedStop.color) {
                  processedStop.color = rgbaToHex(processedStop.color);
                }
                delete processedStop.boundVariables;
                return processedStop;
              }
            );
          }
    
          if (processedFill.color) {
            processedFill.color = rgbaToHex(processedFill.color);
          }
    
          return processedFill;
        });
      }
    
      if (node.strokes && node.strokes.length > 0) {
        filtered.strokes = node.strokes.map((stroke) => {
          var processedStroke = Object.assign({}, stroke);
          delete processedStroke.boundVariables;
          if (processedStroke.color) {
            processedStroke.color = rgbaToHex(processedStroke.color);
          }
          return processedStroke;
        });
      }
    
      if (node.cornerRadius !== undefined) {
        filtered.cornerRadius = node.cornerRadius;
      }
    
      if (node.absoluteBoundingBox) {
        filtered.absoluteBoundingBox = node.absoluteBoundingBox;
      }
    
      if (node.characters) {
        filtered.characters = node.characters;
      }
    
      if (node.style) {
        filtered.style = {
          fontFamily: node.style.fontFamily,
          fontStyle: node.style.fontStyle,
          fontWeight: node.style.fontWeight,
          fontSize: node.style.fontSize,
          textAlignHorizontal: node.style.textAlignHorizontal,
          letterSpacing: node.style.letterSpacing,
          lineHeightPx: node.style.lineHeightPx,
        };
      }
    
      if (node.children) {
        filtered.children = node.children
          .map((child) => {
            return filterFigmaNode(child);
          })
          .filter((child) => {
            return child !== null;
          });
      }
    
      return filtered;
    }
  • Helper function rgbaToHex converts Figma RGBA color objects to hexadecimal strings, omitting alpha if fully opaque.
    function rgbaToHex(color: any): string {
      // skip if color is already hex
      if (color.startsWith('#')) {
        return color;
      }
    
      const r = Math.round(color.r * 255);
      const g = Math.round(color.g * 255);
      const b = Math.round(color.b * 255);
      const a = Math.round(color.a * 255);
    
      return `#${r.toString(16).padStart(2, '0')}${g.toString(16).padStart(2, '0')}${b.toString(16).padStart(2, '0')}${a === 255 ? '' : a.toString(16).padStart(2, '0')}`;
    }
    
    function filterFigmaNode(node: any) {
      // Skip VECTOR type nodes
      if (node.type === "VECTOR") {
        return null;
      }
    
      const filtered: any = {
        id: node.id,
        name: node.name,
        type: node.type,
      };
    
      if (node.fills && node.fills.length > 0) {
        filtered.fills = node.fills.map((fill: any) => {
          const processedFill = { ...fill };
    
          // Remove boundVariables and imageRef
          delete processedFill.boundVariables;
          delete processedFill.imageRef;
    
          // Process gradientStops if present
          if (processedFill.gradientStops) {
            processedFill.gradientStops = processedFill.gradientStops.map((stop: any) => {
              const processedStop = { ...stop };
              // Convert color to hex if present
              if (processedStop.color) {
                processedStop.color = rgbaToHex(processedStop.color);
              }
              // Remove boundVariables
              delete processedStop.boundVariables;
              return processedStop;
            });
          }
    
          // Convert solid fill colors to hex
          if (processedFill.color) {
            processedFill.color = rgbaToHex(processedFill.color);
          }
    
          return processedFill;
        });
      }
    
      if (node.strokes && node.strokes.length > 0) {
        filtered.strokes = node.strokes.map((stroke: any) => {
          const processedStroke = { ...stroke };
          // Remove boundVariables
          delete processedStroke.boundVariables;
          // Convert color to hex if present
  • Dispatch handler in handleCommand switch statement that routes 'read_my_design' commands to the readMyDesign function.
          return await readMyDesign();
        case "create_rectangle":
          return await createRectangle(params);
        case "create_frame":
          return await createFrame(params);
        case "create_text":
          return await createText(params);
        case "set_fill_color":
          return await setFillColor(params);
        case "set_stroke_color":
          return await setStrokeColor(params);
        case "move_node":
          return await moveNode(params);
        case "resize_node":
          return await resizeNode(params);
        case "delete_node":
          return await deleteNode(params);
        case "delete_multiple_nodes":
          return await deleteMultipleNodes(params);
        case "get_styles":
          return await getStyles();
        case "get_local_components":
          return await getLocalComponents();
        // case "get_team_components":
        //   return await getTeamComponents();
        case "create_component_instance":
          return await createComponentInstance(params);
        case "export_node_as_image":
          return await exportNodeAsImage(params);
        case "set_corner_radius":
          return await setCornerRadius(params);
        case "set_text_content":
          return await setTextContent(params);
        case "clone_node":
          return await cloneNode(params);
        case "scan_text_nodes":
          return await scanTextNodes(params);
        case "set_multiple_text_contents":
          return await setMultipleTextContents(params);
        case "get_annotations":
          return await getAnnotations(params);
        case "set_annotation":
          return await setAnnotation(params);
        case "scan_nodes_by_types":
          return await scanNodesByTypes(params);
        case "set_multiple_annotations":
          return await setMultipleAnnotations(params);
        case "set_layout_mode":
          return await setLayoutMode(params);
        case "set_padding":
          return await setPadding(params);
        case "set_axis_align":
          return await setAxisAlign(params);
        case "set_layout_sizing":
          return await setLayoutSizing(params);
        case "set_item_spacing":
          return await setItemSpacing(params);
        default:
          throw new Error(`Unknown command: ${command}`);
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv1.0.0
    • removedInput schema / additionalProperties
      Removed value: -false
  2. First observed

TDQS

A3.6/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Since 'Get' indicates a read-only operation, the basic behavior is clear, and there is no annotation contradiction. But with no annotations and no output schema, the description does not disclose edge cases such as behavior with an empty selection, whether children are included, or what 'all node details' concretely covers.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single front-loaded sentence communicates the tool's purpose without wasted words. 'Including all node details' is slightly redundant with 'detailed information,' but the overall structure is clean and immediately actionable.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a zero-parameter tool, the description is adequate for a basic invocation and clearly identifies the subject as the current selection. However, it leaves sibling-tool differentiation unaddressed and does not describe the return shape or selection edge cases, so it is not fully complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has zero parameters and an empty input schema, so the description cannot add parameter-level meaning. A baseline of 4 is appropriate because parameter semantics are irrelevant here.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the action ('Get') and the resource ('current selection in Figma'), with 'including all node details' signaling a comprehensive read. It does not explicitly distinguish itself from similar sibling tools like get_selection or get_node_info, so it falls short of a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool should be used when an agent needs detailed information about the current selection. However, it provides no explicit guidance about when to prefer this over get_selection, get_node_info, or get_nodes_info, and it names no alternatives or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.