join_channel
Enable communication with Figma by joining a specific channel, allowing Cursor AI to programmatically interact with and modify Figma designs.
Instructions
Join a specific channel to communicate with Figma
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {},
"type": "object"
}
Implementation Reference
- src/talk_to_figma_mcp/server.ts:2403-2448 (registration)MCP tool registration for 'join_channel', including schema (channel param), handler logic that validates input and calls joinChannel helper.server.tool( "join_channel", "Join a specific channel to communicate with Figma", { channel: z.string().describe("The name of the channel to join").default(""), }, async ({ channel }) => { try { if (!channel) { // If no channel provided, ask the user for input return { content: [ { type: "text", text: "Please provide a channel name to join:", }, ], followUp: { tool: "join_channel", description: "Join the specified channel", }, }; } await joinChannel(channel); return { content: [ { type: "text", text: `Successfully joined channel: ${channel}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error joining channel: ${error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Handler helper function 'joinChannel' that sends the 'join' command via sendCommandToFigma to the WebSocket server and updates currentChannel state.async function joinChannel(channelName: string): Promise<void> { if (!ws || ws.readyState !== WebSocket.OPEN) { throw new Error("Not connected to Figma"); } try { await sendCommandToFigma("join", { channel: channelName }); currentChannel = channelName; logger.info(`Joined channel: ${channelName}`); } catch (error) { logger.error(`Failed to join channel: ${error instanceof Error ? error.message : String(error)}`); throw error; } }
- Core helper 'sendCommandToFigma' with special handling for 'join' command (used by joinChannel), sends WebSocket message to socket.ts server on port 3055.function sendCommandToFigma( command: FigmaCommand, params: unknown = {}, timeoutMs: number = 30000 ): 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 } : { 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)); }); }