set_stroke_color
Set the stroke color of a Figma node by providing red, green, and blue values. Optionally adjust alpha and stroke weight for precise border control.
Instructions
Set the stroke color of a node in Figma (defaults: opacity 1, weight 1)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nodeId | Yes | The ID of the node to modify | |
| r | Yes | Red component (0-1) | |
| g | Yes | Green component (0-1) | |
| b | Yes | Blue component (0-1) | |
| a | No | Alpha component (0-1) | |
| strokeWeight | No | Stroke weight >= 0) |
Implementation Reference
- The main tool handler for 'set_stroke_color'. Registers the MCP tool with Zod schema for nodeId, r, g, b (required), a and strokeWeight (optional). Handler validates inputs, applies defaults (opacity=1, weight=1), and calls sendCommandToFigma with the command payload.
// Set Stroke Color Tool server.tool( "set_stroke_color", "Set the stroke color of a node in Figma (defaults: opacity 1, weight 1)", { nodeId: z.string().describe("The ID of the node to modify"), r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"), g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"), b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"), a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"), strokeWeight: z.coerce.number().min(0).optional().describe("Stroke weight >= 0)"), }, async ({ nodeId, r, g, b, a, strokeWeight }) => { try { if (r === undefined || g === undefined || b === undefined) { throw new Error("RGB components (r, g, b) are required and cannot be undefined"); } const colorInput: Color = { r, g, b, a }; const colorWithDefaults = applyColorDefaults(colorInput); const strokeWeightWithDefault = applyDefault(strokeWeight, FIGMA_DEFAULTS.stroke.weight); const result = await sendCommandToFigma("set_stroke_color", { nodeId, color: colorWithDefaults, strokeWeight: strokeWeightWithDefault, }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Set stroke color of node "${typedResult.name}" to RGBA(${r}, ${g}, ${b}, ${colorWithDefaults.a}) with weight ${strokeWeightWithDefault}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting stroke color: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - Input schema definition for the 'set_stroke_color' tool using Zod. Defines required parameters: nodeId (string), r, g, b (numbers 0-1), and optional: a (alpha 0-1), strokeWeight (>=0).
{ nodeId: z.string().describe("The ID of the node to modify"), r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"), g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"), b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"), a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"), strokeWeight: z.coerce.number().min(0).optional().describe("Stroke weight >= 0)"), }, - src/talk_to_figma_mcp/tools/modification-tools.ts:63-111 (registration)Registration of the tool via server.tool('set_stroke_color', ...) as part of the registerModificationTools function. This registers the tool name, description, schema, and handler on the MCP server.
server.tool( "set_stroke_color", "Set the stroke color of a node in Figma (defaults: opacity 1, weight 1)", { nodeId: z.string().describe("The ID of the node to modify"), r: z.coerce.number().min(0).max(1).describe("Red component (0-1)"), g: z.coerce.number().min(0).max(1).describe("Green component (0-1)"), b: z.coerce.number().min(0).max(1).describe("Blue component (0-1)"), a: z.coerce.number().min(0).max(1).optional().describe("Alpha component (0-1)"), strokeWeight: z.coerce.number().min(0).optional().describe("Stroke weight >= 0)"), }, async ({ nodeId, r, g, b, a, strokeWeight }) => { try { if (r === undefined || g === undefined || b === undefined) { throw new Error("RGB components (r, g, b) are required and cannot be undefined"); } const colorInput: Color = { r, g, b, a }; const colorWithDefaults = applyColorDefaults(colorInput); const strokeWeightWithDefault = applyDefault(strokeWeight, FIGMA_DEFAULTS.stroke.weight); const result = await sendCommandToFigma("set_stroke_color", { nodeId, color: colorWithDefaults, strokeWeight: strokeWeightWithDefault, }); const typedResult = result as { name: string }; return { content: [ { type: "text", text: `Set stroke color of node "${typedResult.name}" to RGBA(${r}, ${g}, ${b}, ${colorWithDefaults.a}) with weight ${strokeWeightWithDefault}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error setting stroke color: ${error instanceof Error ? error.message : String(error)}`, }, ], }; } } ); - Helper utilities used by the stroke color tool: FIGMA_DEFAULTS (opacity=1, stroke weight=1), applyDefault (provides fallback value), and applyColorDefaults (fills in missing alpha with default opacity).
import { Color, ColorWithDefaults } from '../types/color'; export const FIGMA_DEFAULTS = { color: { opacity: 1, }, stroke: { weight: 1, } } as const; export function applyDefault<T>(value: T | undefined, defaultValue: T): T { return value !== undefined ? value : defaultValue; } export function applyColorDefaults(color: Color): ColorWithDefaults { return { r: color.r, g: color.g, b: color.b, a: applyDefault(color.a, FIGMA_DEFAULTS.color.opacity) }; } - Type definition for FigmaCommand, which includes 'set_stroke_color' as a valid command type for the Figma plugin WebSocket communication.
export type FigmaCommand = | "get_document_info" | "get_selection" | "get_node_info" | "create_rectangle" | "create_frame" | "create_text" | "create_ellipse" | "create_polygon" | "create_star" | "create_vector" | "create_line" | "set_fill_color" | "set_stroke_color" | "move_node"