import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { sendCommandToFigma } from "../communication";
import { logger } from "../logger";
/**
* Register prototyping-related MCP tools
*/
export function registerPrototypingTools(server: McpServer): void {
// Get Reactions
server.tool(
"get_reactions",
"Get all prototyping reactions (interactions) from specified nodes",
{
nodeIds: z
.array(z.string())
.describe("Array of node IDs to get reactions from"),
},
async ({ nodeIds }) => {
try {
const result = await sendCommandToFigma("get_reactions", { nodeIds });
return {
content: [
{
type: "text",
text: JSON.stringify(result),
},
],
};
} catch (error) {
logger.error("Error getting reactions", error);
return {
content: [
{
type: "text",
text: `Error getting reactions: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
}
},
);
// Set Default Connector
server.tool(
"set_default_connector",
"Set the default connector for prototyping connections",
{
connectorId: z
.string()
.optional()
.describe("The ID of the connector to use as default"),
},
async ({ connectorId }) => {
try {
const result = await sendCommandToFigma<{ success: boolean }>(
"set_default_connector",
{ connectorId },
);
return {
content: [
{
type: "text",
text: result.success
? `Set default connector to ${connectorId ?? "none"}`
: "Failed to set default connector",
},
],
};
} catch (error) {
logger.error("Error setting default connector", error);
return {
content: [
{
type: "text",
text: `Error setting default connector: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
}
},
);
// Create Connections
server.tool(
"create_connections",
"Create prototyping connections between nodes",
{
connections: z
.array(
z.object({
startNodeId: z.string().describe("The ID of the start node"),
endNodeId: z
.string()
.describe("The ID of the end/destination node"),
text: z
.string()
.optional()
.describe("Optional label text for the connection"),
}),
)
.describe("Array of connections to create"),
},
async ({ connections }) => {
try {
const result = await sendCommandToFigma<{
success: boolean;
createdCount: number;
}>("create_connections", { connections });
return {
content: [
{
type: "text",
text: `Created ${result.createdCount} connections`,
},
],
};
} catch (error) {
logger.error("Error creating connections", error);
return {
content: [
{
type: "text",
text: `Error creating connections: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
}
},
);
}