Skip to main content
Glama

add_variable_mode

Destructive

Add modes to Figma variable collections programmatically for Light/Dark themes, responsive breakpoints, or multi-brand variants.

Instructions

Add a new mode to an existing variable collection (e.g. Light/Dark, Desktop/Mobile).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionIdYesVariable collection ID
modeNameYesName for the new mode

Implementation Reference

  • Handler implementation for 'add_variable_mode' tool. Validates collectionId and modeName params, retrieves the variable collection, adds a new mode using collection.addMode(), commits the undo, and returns the result with collectionId, modeId, and modeName.
    case "add_variable_mode": {
      const p = request.params || {};
      if (!p.collectionId) throw new Error("collectionId is required");
      if (!p.modeName) throw new Error("modeName is required");
      const collection = await figma.variables.getVariableCollectionByIdAsync(p.collectionId);
      if (!collection) throw new Error(`Collection not found: ${p.collectionId}`);
      const modeId = collection.addMode(p.modeName);
      figma.commitUndo();
      return {
        type: request.type,
        requestId: request.requestId,
        data: { collectionId: p.collectionId, modeId, modeName: p.modeName },
      };
    }
  • Tool routing registration. The handleWriteVariableRequest (which contains add_variable_mode) is imported and integrated into the write request handler chain at line 12. This is where the tool handler is registered in the request dispatch pipeline.
    import { handleWriteVariableRequest } from "./write-variables";
    import { handleWriteComponentRequest } from "./write-components";
    import { handleWritePrototypeRequest } from "./write-prototype";
    
    export const handleWriteRequest = async (request: any) =>
      (await handleWriteCreateRequest(request)) ??
      (await handleWriteModifyRequest(request)) ??
      (await handleWriteStyleRequest(request)) ??
      (await handleWriteVariableRequest(request)) ??
      (await handleWriteComponentRequest(request)) ??
      (await handleWritePrototypeRequest(request));
  • Helper utility used by the add_variable_mode handler (and other variable operations). The hexToRgb function converts hex color strings to RGB objects with normalized values (0-1 range), used when parsing COLOR type variable values.
    // Write helpers — utilities used exclusively by write handlers.
    
    export const hexToRgb = (hex: string) => {
      const clean = hex.replace("#", "");
      return {
        r: parseInt(clean.slice(0, 2), 16) / 255,
        g: parseInt(clean.slice(2, 4), 16) / 255,
        b: parseInt(clean.slice(4, 6), 16) / 255,
        a: clean.length >= 8 ? parseInt(clean.slice(6, 8), 16) / 255 : 1,
      };
    };
Behavior3/5

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

Annotations already disclose destructiveHint=true and readOnlyHint=false. The description adds conceptual context via the Light/Dark examples but does not disclose behavioral specifics beyond annotations, such as whether existing variables automatically get null values for the new mode or if the operation can fail if the collectionId doesn't exist. No contradiction with annotations.

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?

The description is a single, efficient sentence of approximately 15 words. The parenthetical examples are high-value additions that don't add bulk. Every element earns its place with zero redundancy or filler.

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

Completeness4/5

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

Given the simple 2-parameter schema and presence of destructive annotations, the description adequately covers the core concept. However, for a destructive operation affecting collection structure, it could improve by mentioning implications for existing variables in the collection.

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?

With 100% schema description coverage, the baseline is 3. The description earns an additional point by providing concrete semantic examples (Light/Dark, Desktop/Mobile) that implicitly guide valid modeName values, even though it doesn't explicitly describe the parameters themselves since the schema already does so.

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 specific action ('Add'), resource ('mode'), and target ('existing variable collection'). The parenthetical examples (Light/Dark, Desktop/Mobile) effectively distinguish this from sibling tools like create_variable_collection or set_variable_value by clarifying that 'mode' refers to thematic/responsive variants within a collection.

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 prerequisite context by specifying 'existing' collection, suggesting the collection must already exist. However, it lacks explicit guidance on when to use this versus create_variable_collection, or warnings about side effects (e.g., that all variables in the collection may need new values for this mode).

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/vkhanhqui/figma-mcp-go'

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