get_figjam_elements
Retrieve all FigJam elements including stickies, connectors, shapes with text, sections, and stamps from the current page to read the board's contents.
Instructions
Get all FigJam-specific elements (stickies, connectors, shapes with text, sections, stamps) on the current page. Use this to read the contents of a FigJam board.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main tool handler for 'get_figjam_elements'. Registers via server.tool() and calls sendCommandToFigma('get_figjam_elements', {}). Returns the result as JSON text.
server.tool( "get_figjam_elements", "Get all FigJam-specific elements (stickies, connectors, shapes with text, sections, stamps) on the current page. Use this to read the contents of a FigJam board.", {}, async () => { try { const result = await sendCommandToFigma("get_figjam_elements", {}); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error getting FigJam elements: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - src/talk_to_figma_mcp/tools/index.ts:17-29 (registration)The registerTools function calls registerFigJamTools(server) which registers the tool on the MCP server instance.
export function registerTools(server: McpServer): void { // Register all tool categories registerDocumentTools(server); registerCreationTools(server); registerModificationTools(server); registerTextTools(server); registerComponentTools(server); registerImageTools(server); registerSvgTools(server); registerVariableTools(server); registerFigJamTools(server); registerStyleTools(server); } - The FigmaCommand union type includes 'get_figjam_elements' as a valid command literal, used for type safety when sending commands via WebSocket.
| "get_figjam_elements" | "create_sticky" | "set_sticky_text" | "create_shape_with_text" | "create_connector" | "create_section"; - The sendCommandToFigma function sends the 'get_figjam_elements' command over WebSocket to the Figma plugin and returns a promise with the response.
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)); }); }