Skip to main content
Glama
arinspunk

Claude Talk to Figma MCP

by arinspunk

switch_variable_mode

Switch the variable mode on a Figma node to use values from a different mode in a variable collection. Provide node ID, collection ID, and mode ID.

Instructions

Switch the variable mode on a node for a specific collection. This changes which mode's values are used for bound variables.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nodeIdYesThe ID of the node to switch mode on
collectionIdYesThe ID of the variable collection
modeIdYesThe ID of the mode to switch to

Implementation Reference

  • The handler function for the 'switch_variable_mode' tool. It is registered as an MCP server.tool, takes nodeId, collectionId, and modeId as input parameters, sends the 'switch_variable_mode' command to Figma via WebSocket, and returns the result with mode switch confirmation.
    // Switch Variable Mode Tool
    server.tool(
      "switch_variable_mode",
      "Switch the variable mode on a node for a specific collection. This changes which mode's values are used for bound variables.",
      {
        nodeId: z.string().describe("The ID of the node to switch mode on"),
        collectionId: z.string().describe("The ID of the variable collection"),
        modeId: z.string().describe("The ID of the mode to switch to"),
      },
      async ({ nodeId, collectionId, modeId }) => {
        try {
          const result = await sendCommandToFigma("switch_variable_mode", {
            nodeId,
            collectionId,
            modeId,
          });
          const typedResult = result as { nodeName: string; collectionName: string; modeName: string };
          return {
            content: [
              {
                type: "text",
                text: `Switched to mode "${typedResult.modeName}" for collection "${typedResult.collectionName}" on node "${typedResult.nodeName}"`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error switching variable mode: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • The tool is registered via server.tool('switch_variable_mode', ...) inside registerVariableTools() in variable-tools.ts, which is called from registerTools() in tools/index.ts.
    // Switch Variable Mode Tool
    server.tool(
      "switch_variable_mode",
      "Switch the variable mode on a node for a specific collection. This changes which mode's values are used for bound variables.",
      {
        nodeId: z.string().describe("The ID of the node to switch mode on"),
        collectionId: z.string().describe("The ID of the variable collection"),
        modeId: z.string().describe("The ID of the mode to switch to"),
      },
      async ({ nodeId, collectionId, modeId }) => {
        try {
          const result = await sendCommandToFigma("switch_variable_mode", {
            nodeId,
            collectionId,
            modeId,
          });
          const typedResult = result as { nodeName: string; collectionName: string; modeName: string };
          return {
            content: [
              {
                type: "text",
                text: `Switched to mode "${typedResult.modeName}" for collection "${typedResult.collectionName}" on node "${typedResult.nodeName}"`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Error switching variable mode: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          };
        }
      }
    );
  • Zod schema for the 'switch_variable_mode' tool: three required string parameters - nodeId (the target node), collectionId (the variable collection), and modeId (the mode to switch to).
    {
      nodeId: z.string().describe("The ID of the node to switch mode on"),
      collectionId: z.string().describe("The ID of the variable collection"),
      modeId: z.string().describe("The ID of the mode to switch to"),
    },
  • The sendCommandToFigma function is the WebSocket helper that sends the 'switch_variable_mode' command string (typed as FigmaCommand) to the Figma plugin via a WebSocket connection, managing the request lifecycle with timeouts and promise resolution.
    export function sendCommandToFigma(
      command: FigmaCommand,
      params: unknown = {},
      timeoutMs: number = 300000
    ): Promise<unknown> {
      return new Promise((resolve, reject) => {
        // If not connected, try to connect first
        if (!ws || ws.readyState !== WebSocket.OPEN) {
          connectToFigma();
          reject(new Error("Not connected to Figma. Attempting to connect..."));
          return;
        }
    
        // Check if we need a channel for this command
        const requiresChannel = command !== "join";
        if (requiresChannel && !currentChannel) {
          reject(new Error("Must join a channel before sending commands"));
          return;
        }
    
        const id = uuidv4();
        const request = {
          id,
          type: command === "join" ? "join" : "message",
          ...(command === "join"
            ? { channel: (params as any).channel, sessionId: SESSION_ID }
            : { channel: currentChannel }),
          message: {
            id,
            command,
            params: {
              ...(params as any),
              commandId: id, // Include the command ID in params
            },
          },
        };
    
        // Set timeout for request
        const timeout = setTimeout(() => {
          if (pendingRequests.has(id)) {
            pendingRequests.delete(id);
            logger.error(`Request ${id} to Figma timed out after ${timeoutMs / 1000} seconds`);
            reject(new Error('Request to Figma timed out'));
          }
        }, timeoutMs);
    
        // Store the promise callbacks to resolve/reject later
        pendingRequests.set(id, {
          resolve,
          reject,
          timeout,
          lastActivity: Date.now()
        });
    
        // Send the request
        logger.info(`Sending command to Figma: ${command}`);
        logger.debug(`Request details: ${JSON.stringify(request)}`);
        ws.send(JSON.stringify(request));
      });
    }
  • The type definition for 'switch_variable_mode' as a valid FigmaCommand value in the FigmaCommand union type, ensuring type safety when sending this command via the WebSocket helper.
    | "switch_variable_mode"
    | "get_figjam_elements"
    | "create_sticky"
    | "set_sticky_text"
    | "create_shape_with_text"
    | "create_connector"
    | "create_section";
Behavior3/5

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

With no annotations, the description carries full burden. It discloses that switching changes which mode's values are used, but lacks details on persistence, side effects, or whether it affects the UI. This is adequate but not rich.

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?

Two concise sentences with no redundant information. The action is front-loaded, and every word serves a purpose.

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?

The description is adequate for a simple toggle tool but lacks details on return values, prerequisites, or reversibility. Given no output schema and no annotations, additional context (e.g., confirmation of change) would improve completeness.

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 input schema has 100% description coverage for all three parameters, providing clear IDs. The description adds context by explaining the overall effect ('changes which mode's values are used'), which goes beyond mere parameter definitions.

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

Purpose5/5

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

The description clearly states the tool switches the variable mode on a node for a specific collection, which is distinct from siblings like 'set_variable' or 'apply_variable_to_node'. The verb 'switch' and resource 'variable mode on a node' are specific and unambiguous.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, nor does it mention prerequisites or when not to use it. It only states the action without contextual usage advice.

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

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/arinspunk/claude-talk-to-figma-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server