import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { sendCommandToFigma } from "../communication";
import { logger } from "../logger";
/**
* Register document-related MCP tools
*/
export function registerDocumentTools(server: McpServer): void {
// Get Document Info
server.tool(
"get_document_info",
"Get detailed information about the current Figma document including name, pages, and current page details",
{},
async () => {
try {
const result = await sendCommandToFigma("get_document_info", {});
return {
content: [
{
type: "text",
text: JSON.stringify(result),
},
],
};
} catch (error) {
logger.error("Error getting document info", error);
return {
content: [
{
type: "text",
text: `Error getting document info: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
}
},
);
// Get Selection
server.tool(
"get_selection",
"Get information about the currently selected nodes in Figma",
{},
async () => {
try {
const result = await sendCommandToFigma("get_selection", {});
return {
content: [
{
type: "text",
text: JSON.stringify(result),
},
],
};
} catch (error) {
logger.error("Error getting selection", error);
return {
content: [
{
type: "text",
text: `Error getting selection: ${
error instanceof Error ? error.message : String(error)
}`,
},
],
};
}
},
);
}