import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { createLogger } from "../logger";
const logger = createLogger({ service: "mcp-server:figma" });
/**
* Registers Figma-related tools with the MCP server
*/
export function registerFigmaTools(server: McpServer): void {
server.registerTool(
"figma_get_document",
{
title: "Get Figma Document",
description:
"Retrieves information about the current Figma document or a specific node",
inputSchema: {
nodeId: z
.string()
.optional()
.describe("Optional node ID to get specific node info"),
},
},
async (args) => {
const { nodeId } = args;
logger.info("figma_get_document called", { nodeId });
try {
// TODO: Implement actual Figma communication
return {
content: [
{
type: "text",
text: nodeId
? `Document info for node: ${nodeId} (not yet implemented)`
: "Document info (not yet implemented)",
},
],
};
} catch (error) {
logger.error("figma_get_document error", error);
return {
content: [
{
type: "text",
text: `Error getting document info: ${error instanceof Error ? error.message : "Unknown error"}`,
},
],
};
}
},
);
server.registerTool(
"figma_create_rectangle",
{
title: "Create Rectangle",
description: "Creates a rectangle in the current Figma document",
inputSchema: {
x: z.number().optional().default(0).describe("X position"),
y: z.number().optional().default(0).describe("Y position"),
width: z
.number()
.optional()
.default(100)
.describe("Width of the rectangle"),
height: z
.number()
.optional()
.default(100)
.describe("Height of the rectangle"),
color: z
.object({
r: z.number().min(0).max(1),
g: z.number().min(0).max(1),
b: z.number().min(0).max(1),
})
.optional()
.describe("RGB color values (0-1)"),
},
},
async (args) => {
const { x, y, width, height, color } = args;
logger.info("figma_create_rectangle called", {
x,
y,
width,
height,
color,
});
try {
// TODO: Implement actual Figma communication
return {
content: [
{
type: "text",
text: `Rectangle creation requested at (${x}, ${y}) with size ${width}x${height} (not yet implemented)`,
},
],
};
} catch (error) {
logger.error("figma_create_rectangle error", error);
return {
content: [
{
type: "text",
text: `Error creating rectangle: ${error instanceof Error ? error.message : "Unknown error"}`,
},
],
};
}
},
);
}