Skip to main content
Glama

figma_execute

Execute JavaScript within the Figma Plugin API sandbox to read design data or perform targeted modifications. Use for safe operations like retrieving node properties or updating specific attributes.

Instructions

Execute arbitrary JavaScript in the Figma Plugin API sandbox. Powerful and direct — use with care.

Prerequisites: Requires Figma bridge running and plugin connected. The code runs inside the Figma plugin context (not Node.js), so Node APIs (fs, path, etc.) are not available. Only the Figma Plugin API and standard browser globals are accessible.

Returns on success: The return value of the last expression in the code, JSON-serialized. Non-serializable values (functions, DOM nodes) are omitted.

Error behavior: Throws "Figma not connected" if no plugin is connected. Runtime errors in the plugin sandbox are caught and returned as { error: string, stack: string }.

IMPORTANT — this tool is powerful and can cause destructive mutations to the Figma file:

  • Safe read operations: node.getSharedPluginData(), figma.currentPage.selection, node.name, node.type, getting fills/effects

  • Safe targeted mutations: renaming nodes, updating a fill color, setting a variable binding on a single node

  • Do NOT use for full component creation — use create_spec + generate_code instead, which produces versioned, spec-traceable components

  • Do NOT replace entire frames or delete page-level frames with this tool

  • Do NOT call figma.closePlugin() — this terminates the bridge connection

Example safe reads:

  • figma.currentPage.selection.map(n => ({ id: n.id, name: n.name }))

  • figma.getNodeById('123:456')?.name

  • figma.currentPage.children.map(n => n.name)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesJavaScript to execute in the Figma Plugin API sandbox. Must be a valid JS expression or statement block. The return value (last expression result) is JSON-serialized and returned. Has access to the full Figma Plugin API (figma.*, PageNode, FrameNode, etc.) but not Node.js APIs.
Behavior5/5

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

Since no annotations are provided, the description carries the full burden of behavioral disclosure. It thoroughly describes behavioral traits: prerequisites (Figma bridge, plugin connection), execution context (plugin sandbox, no Node.js APIs), return behavior (JSON-serialized last expression, handling of non-serializable values), error behavior (specific error messages and error object structure), and destructive potential (with detailed do's and don'ts).

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 appropriately sized and well-structured with clear sections (prerequisites, returns, error behavior, important warnings, examples). While comprehensive, every sentence earns its place by providing critical information. The front-loaded warning about power and care sets appropriate expectations immediately.

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 high complexity (executing arbitrary JavaScript in a sandbox with destructive potential) and absence of both annotations and output schema, the description provides exceptional completeness. It covers prerequisites, execution context, return behavior, error handling, safety guidelines, and concrete examples—everything needed for safe and effective use.

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 its single parameter, providing a baseline score of 3. The description adds significant value by elaborating on the parameter's semantics: it specifies that the code runs in the Figma Plugin API sandbox with access to specific APIs (figma.*, PageNode, etc.) but not Node.js APIs, and provides concrete examples of safe reads that help illustrate valid code patterns.

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 explicitly states the tool's purpose: 'Execute arbitrary JavaScript in the Figma Plugin API sandbox.' It specifies the exact action (execute JavaScript) and resource (Figma Plugin API sandbox), and clearly distinguishes it from sibling tools by emphasizing its direct, low-level nature versus higher-level tools like create_spec and generate_code.

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 provides extensive guidance on when to use this tool versus alternatives. It explicitly states prerequisites (Figma bridge running, plugin connected), recommends specific use cases (safe reads, targeted mutations), and explicitly warns against using it for full component creation (pointing to create_spec + generate_code) and destructive operations like deleting page-level frames.

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/sarveshsea/m-moire'

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