Skip to main content
Glama

ensure_variable

Create or reuse a Figma variable idempotently by specifying collection, name, type, and mode values. Handles duplicates and ensures mode coverage.

Instructions

Idempotent variable creation — populates values_by_mode in one shot.

Prefer this over create_variable — re-running with the same args returns the existing variable instead of creating a duplicate.

Behavior (spec §3.1):

  • Exactly 1 variable with (collection_id, name, type) in target collection → idempotent reuse.

  • 0 in target, matches in OTHER collections → create new in target + warning NAME_EXISTS_OUTSIDE_TARGET_COLLECTION.

  • 0 anywhere → create new.

  • 2+ in target collection (Figma allows duplicates) → fail SAME_COLLECTION_NAME_DUPLICATE.

values_by_mode keys can be either mode NAMES (e.g. "Light") or modeIds (e.g. "1:0"). Each value must match the variable type (hex/RGBA for COLOR, number for FLOAT, string for STRING, boolean for BOOLEAN).

Omit idempotency_key — the handler computes it canonically from (collection_id, name, type, values_by_mode). Pass it only if you need strict concurrency-safety validation (LLMs should not try to compute SHA-256 inline; placeholder strings are rejected).

Mode coverage policy (spec §6.2):

  • mode_coverage_required: 'all' (default) — every mode in the collection must have an explicit value. set_fill / bind_variable will REJECT bindings that fall through to a missing mode (MISSING_MODE_VALUES).

  • mode_coverage_required: 'opt-in-fallback' — fallback to default mode is intended. Bindings emit FALLBACK_BINDING warning instead of failing. Caller MUST provide fallback_reason containing the structured phrase "fallback to <mode_name>" (machine-greppable).

Returns {data: {variable_id, name, type, collection_id, mode_coverage[], mode_coverage_required, reused?: true}, warnings?: [...]}.

Examples: ensure_variable({collection_id: "VariableCollectionId:1:2", name: "Text/Primary", type: "COLOR", values_by_mode: {Light: "#111", Dark: "#EEE"}}) ensure_variable({collection_id: "VariableCollectionId:1:2", name: "Spacing/desktop", type: "FLOAT", values_by_mode: {Desktop: 24}, mode_coverage_required: "opt-in-fallback", fallback_reason: "Desktop-only metric; fallback to Desktop in Mobile mode."})

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collection_idYesTarget VariableCollectionId — strict ID, no name lookup.
nameYesVariable name (slashes denote hierarchy).
typeYesVariable type
values_by_modeYesMap of mode name OR modeId → value. Hex strings allowed for COLOR.
idempotency_keyNoOptional. Handler auto-computes canonically if omitted. Pass only if you need strict concurrency-safety validation against the SHA-256 formula in spec §3.1.
mode_coverage_requiredNoMode coverage policy — "all" (default; every mode must have explicit value) or "opt-in-fallback" (allow fallback, requires fallback_reason).
fallback_reasonNoREQUIRED iff mode_coverage_required="opt-in-fallback". Must contain the structured phrase "fallback to <mode_name>". Persisted on the variable for audit trail.
Behavior5/5

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

With no annotations, the description fully bears the burden of behavioral transparency. It explains idempotent behavior in detail (four bullet-pointed cases), return structure, and special handling of mode coverage and fallback scenarios. The description is comprehensive and leaves no ambiguity about the tool's behavior.

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

Conciseness4/5

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

The description is relatively long but justified by the tool's complexity (7 parameters, nested objects, multiple behavioral cases). It is well-structured with clear sections and bullet points. Every sentence adds value, though some minor redundancy exists in repeating parameter details already in the schema. Overall, it strikes a good balance between completeness and conciseness.

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

Completeness5/5

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

Given the tool's complexity (7 parameters, nested objects, no output schema), the description provides complete coverage. It explains the return value structure, behavioral edge cases, and mode coverage policy in detail. The absence of annotations and output schema is fully compensated by the rich description, making the tool easy to use correctly.

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, but the description adds significant value beyond the schema. It clarifies that values_by_mode keys can be mode names or modeIds, explains the type matching requirement, and provides examples of valid values. The description also expands on the mode_coverage_required and fallback_reason parameters with behavioral details not present in the schema.

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 it is for idempotent variable creation, specifying the action (create variable) and resource (variable), and explicitly distinguishes from the sibling tool create_variable by recommending 'Prefer this over create_variable'. The verb 'ensure' combined with the behavior description gives a specific, non-ambiguous purpose.

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

Usage Guidelines5/5

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

The description explicitly recommends preferring this tool over create_variable, explains when to use idempotency_key (only for strict concurrency-safety), and details mode coverage policy with explicit conditions for 'all' versus 'opt-in-fallback'. It provides clear context for when to use and when not to use alternatives.

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/musepy/genable'

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