figma-mcp-server 0.1.0-beta.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +51 -44
- package/mcpServer.js +51 -33
- package/package.json +3 -3
- package/tools/figma/figma-api/create-dev-resources-for-a-file.js +95 -0
- package/tools/figma/figma-api/{create-variable-collection.js → create-variable-collections-for-a-file.js} +12 -13
- package/tools/figma/figma-api/get-a-published-component-by-key.js +66 -0
- package/tools/figma/figma-api/get-a-published-component-set-by-key.js +66 -0
- package/tools/figma/figma-api/get-a-published-library-by-id.js +66 -0
- package/tools/figma/figma-api/get-a-published-style-by-key.js +66 -0
- package/tools/figma/figma-api/{get-all-webhooks-for-team.js → get-current-user.js} +10 -10
- package/tools/figma/figma-api/{get-design-node.js → get-file-nodes.js} +17 -15
- package/tools/figma/figma-api/get-file-version-history.js +66 -0
- package/tools/figma/figma-api/{get-design.js → get-file.js} +8 -8
- package/tools/figma/figma-api/{get-image-node.js → get-image-fills.js} +17 -17
- package/tools/figma/figma-api/{get-library-analytics.js → get-library-action-analytics.js} +12 -12
- package/tools/figma/figma-api/{get-actions-analytics.js → get-library-usage-analytics.js} +12 -13
- package/tools/figma/figma-api/list-comments-on-a-file.js +66 -0
- package/tools/figma/figma-api/{get-dev-resources.js → list-component-sets-in-a-file.js} +11 -11
- package/tools/figma/figma-api/list-components-in-a-file.js +66 -0
- package/tools/figma/figma-api/list-dev-resources-for-a-file.js +66 -0
- package/tools/figma/figma-api/{get-project-files.js → list-files-in-a-project.js} +12 -11
- package/tools/figma/figma-api/{get-team-projects.js → list-projects-in-a-team.js} +11 -11
- package/tools/figma/figma-api/{add-webhook.js → list-published-libraries.js} +11 -12
- package/tools/figma/figma-api/{get-file-comments.js → list-styles-in-a-file.js} +11 -11
- package/tools/figma/figma-api/{get-images.js → list-variables-for-a-file.js} +13 -13
- package/tools/figma/figma-api/post-a-comment-to-a-file.js +102 -0
- package/tools/paths.js +23 -17
- package/tools/figma/figma-api/delete-webhook.js +0 -64
- package/tools/figma/figma-api/post-a-new-comment.js +0 -89
- package/tools/figma/figma-api/post-dev-resource.js +0 -93
- package/tools/figma/figma-api/reply-to-comment.js +0 -84
package/README.md
CHANGED
|
@@ -1,63 +1,52 @@
|
|
|
1
1
|
# Figma MCP Server
|
|
2
|
-
MCP server for Figma
|
|
2
|
+
A simple MCP server for Figma
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
In the `.env` file, set the `FIGMA_API_KEY` to your Figma API key.
|
|
6
|
-
|
|
7
|
-
```
|
|
8
|
-
FIGMA_API_KEY=
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
### Install
|
|
4
|
+
## Install
|
|
12
5
|
Install the server
|
|
13
6
|
|
|
14
|
-
```
|
|
7
|
+
```bash
|
|
15
8
|
git clone https://github.com/planetabhi/figma-mcp-server.git
|
|
16
9
|
cd figma-mcp-server
|
|
17
10
|
pnpm i
|
|
18
11
|
```
|
|
19
12
|
|
|
20
|
-
###
|
|
21
|
-
|
|
13
|
+
### Set tool environment variable
|
|
14
|
+
Create a `.env` file and set the `FIGMA_API_KEY` to your Figma API key.
|
|
22
15
|
|
|
23
|
-
```
|
|
24
|
-
|
|
16
|
+
```bash
|
|
17
|
+
FIGMA_API_KEY=
|
|
25
18
|
```
|
|
26
19
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
The MCP Server (`mcpServer.js`) exposes your Figma API tools to MCP-compatible clients.
|
|
30
|
-
|
|
31
|
-
### Run with Postman
|
|
32
|
-
|
|
33
|
-
Postman desktop app is the easiest way to run and test MCP servers.
|
|
20
|
+
> To generate a new personal access token, log in to your Figma account, then from the top-left menu, head to Settings, click on the security tab, find the Personal access tokens section, and click Generate new token to open the configuration modal where you can set the expiration and scopes before clicking Generate token.
|
|
34
21
|
|
|
35
|
-
|
|
22
|
+
### List All Tools
|
|
23
|
+
List descriptions and parameters from all available tools
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
25
|
+
```bash
|
|
26
|
+
pnpm list-tools
|
|
27
|
+
```
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
## Run the MCP Server
|
|
42
30
|
|
|
43
|
-
|
|
31
|
+
### Find node and server path
|
|
44
32
|
|
|
45
|
-
```
|
|
33
|
+
```bash
|
|
34
|
+
# Find node path
|
|
46
35
|
which node
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
2. Find `mcpServer.js` path:
|
|
50
36
|
|
|
51
|
-
|
|
37
|
+
# Get the absolute path of the MCP server
|
|
52
38
|
realpath mcpServer.js
|
|
53
39
|
```
|
|
54
40
|
|
|
55
|
-
|
|
41
|
+
|
|
42
|
+
### Run with Claude Desktop
|
|
43
|
+
|
|
44
|
+
1. Open Claude Desktop → **Settings** → **Developers** → **Edit Config** and add your server:
|
|
56
45
|
|
|
57
46
|
```json
|
|
58
47
|
{
|
|
59
48
|
"mcpServers": {
|
|
60
|
-
"
|
|
49
|
+
"figma-mcp-server": {
|
|
61
50
|
"command": "<absolute_path_to_node>",
|
|
62
51
|
"args": ["<absolute_path_to_mcpServer.js>"]
|
|
63
52
|
}
|
|
@@ -65,41 +54,59 @@ realpath mcpServer.js
|
|
|
65
54
|
}
|
|
66
55
|
```
|
|
67
56
|
|
|
68
|
-
Restart Claude Desktop to activate
|
|
57
|
+
2. Restart Claude Desktop to activate config change.
|
|
58
|
+
|
|
59
|
+
> To try it out in Claude Desktop, first enable the `get_file_nodes` tool from the tools list. Copy a design node link from a Figma file, then paste it into Claude Desktop prompt. It will return the design node data and other information.
|
|
60
|
+
|
|
61
|
+
### Run in Postman
|
|
62
|
+
|
|
63
|
+
1. Choose an existing workspace or create a new one.
|
|
64
|
+
2. Select New > MCP. Postman opens a new MCP request in a new tab.
|
|
65
|
+
3. Select the server's communication method STDIO.
|
|
66
|
+
4. Enter the server's command and arguments.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Create a new MCP request and add the server's command and arguments
|
|
70
|
+
STDIO <absolute_path_to_node> <absolute_path_to_mcpServer.js>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
> [Postman collection](https://www.postman.com/doitagain/workspace/figma/collection/68369062465421c338809955?action=share&creator=17652550).
|
|
74
|
+
|
|
75
|
+
---
|
|
69
76
|
|
|
70
|
-
###
|
|
77
|
+
### Misc
|
|
71
78
|
|
|
72
|
-
#### Docker Deployment
|
|
79
|
+
#### Docker Deployment
|
|
73
80
|
|
|
74
81
|
For production deployments, you can use Docker:
|
|
75
82
|
|
|
76
83
|
**1. Build Docker image**
|
|
77
84
|
|
|
78
|
-
```
|
|
79
|
-
docker build -t
|
|
85
|
+
```bash
|
|
86
|
+
docker build -t figma-mcp-server .
|
|
80
87
|
```
|
|
81
88
|
|
|
82
|
-
**2. Claude Desktop
|
|
89
|
+
**2. Claude Desktop integration**
|
|
83
90
|
|
|
84
91
|
Add Docker server configuration to Claude Desktop (Settings → Developers → Edit Config):
|
|
85
92
|
|
|
86
93
|
```json
|
|
87
94
|
{
|
|
88
95
|
"mcpServers": {
|
|
89
|
-
"
|
|
96
|
+
"figma-mcp-server": {
|
|
90
97
|
"command": "docker",
|
|
91
|
-
"args": ["run", "-i", "--rm", "--env-file=.env", "
|
|
98
|
+
"args": ["run", "-i", "--rm", "--env-file=.env", "figma-mcp-server"]
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
}
|
|
95
102
|
```
|
|
96
103
|
|
|
97
|
-
> Add your environment variables
|
|
104
|
+
> Add your environment variables inside the `.env` file.
|
|
98
105
|
|
|
99
106
|
#### Server-Sent Events (SSE)
|
|
100
107
|
|
|
101
108
|
To run the server with Server-Sent Events (SSE) support, use the `--sse` flag:
|
|
102
109
|
|
|
103
|
-
```
|
|
110
|
+
```bash
|
|
104
111
|
node mcpServer.js --sse
|
|
105
112
|
```
|
package/mcpServer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
|
|
2
3
|
import dotenv from "dotenv";
|
|
3
4
|
import express from "express";
|
|
4
5
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
@@ -36,32 +37,7 @@ async function transformTools(tools) {
|
|
|
36
37
|
.filter(Boolean);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
async function
|
|
40
|
-
const args = process.argv.slice(2);
|
|
41
|
-
const isSSE = args.includes("--sse");
|
|
42
|
-
|
|
43
|
-
const server = new Server(
|
|
44
|
-
{
|
|
45
|
-
name: SERVER_NAME,
|
|
46
|
-
version: "0.1.0",
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
capabilities: {
|
|
50
|
-
tools: {},
|
|
51
|
-
},
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
server.onerror = (error) => console.error("[Error]", error);
|
|
56
|
-
|
|
57
|
-
// Gracefully shutdown on SIGINT
|
|
58
|
-
process.on("SIGINT", async () => {
|
|
59
|
-
await server.close();
|
|
60
|
-
process.exit(0);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const tools = await discoverTools();
|
|
64
|
-
|
|
40
|
+
async function setupServerHandlers(server, tools) {
|
|
65
41
|
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
66
42
|
tools: await transformTools(tools),
|
|
67
43
|
}));
|
|
@@ -69,15 +45,12 @@ async function run() {
|
|
|
69
45
|
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
70
46
|
const toolName = request.params.name;
|
|
71
47
|
const tool = tools.find((t) => t.definition.function.name === toolName);
|
|
72
|
-
|
|
73
48
|
if (!tool) {
|
|
74
49
|
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${toolName}`);
|
|
75
50
|
}
|
|
76
|
-
|
|
77
51
|
const args = request.params.arguments;
|
|
78
52
|
const requiredParameters =
|
|
79
53
|
tool.definition?.function?.parameters?.required || [];
|
|
80
|
-
|
|
81
54
|
for (const requiredParameter of requiredParameters) {
|
|
82
55
|
if (!(requiredParameter in args)) {
|
|
83
56
|
throw new McpError(
|
|
@@ -86,7 +59,6 @@ async function run() {
|
|
|
86
59
|
);
|
|
87
60
|
}
|
|
88
61
|
}
|
|
89
|
-
|
|
90
62
|
try {
|
|
91
63
|
const result = await tool.function(args);
|
|
92
64
|
return {
|
|
@@ -105,17 +77,42 @@ async function run() {
|
|
|
105
77
|
);
|
|
106
78
|
}
|
|
107
79
|
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async function run() {
|
|
83
|
+
const args = process.argv.slice(2);
|
|
84
|
+
const isSSE = args.includes("--sse");
|
|
85
|
+
const tools = await discoverTools();
|
|
108
86
|
|
|
109
87
|
if (isSSE) {
|
|
110
88
|
const app = express();
|
|
111
89
|
const transports = {};
|
|
90
|
+
const servers = {};
|
|
112
91
|
|
|
113
92
|
app.get("/sse", async (_req, res) => {
|
|
93
|
+
// Create a new Server instance for each session
|
|
94
|
+
const server = new Server(
|
|
95
|
+
{
|
|
96
|
+
name: SERVER_NAME,
|
|
97
|
+
version: "0.1.0",
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
capabilities: {
|
|
101
|
+
tools: {},
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
server.onerror = (error) => console.error("[Error]", error);
|
|
106
|
+
await setupServerHandlers(server, tools);
|
|
107
|
+
|
|
114
108
|
const transport = new SSEServerTransport("/messages", res);
|
|
115
109
|
transports[transport.sessionId] = transport;
|
|
110
|
+
servers[transport.sessionId] = server;
|
|
116
111
|
|
|
117
|
-
res.on("close", () => {
|
|
112
|
+
res.on("close", async () => {
|
|
118
113
|
delete transports[transport.sessionId];
|
|
114
|
+
await server.close();
|
|
115
|
+
delete servers[transport.sessionId];
|
|
119
116
|
});
|
|
120
117
|
|
|
121
118
|
await server.connect(transport);
|
|
@@ -124,11 +121,12 @@ async function run() {
|
|
|
124
121
|
app.post("/messages", async (req, res) => {
|
|
125
122
|
const sessionId = req.query.sessionId;
|
|
126
123
|
const transport = transports[sessionId];
|
|
124
|
+
const server = servers[sessionId];
|
|
127
125
|
|
|
128
|
-
if (transport) {
|
|
126
|
+
if (transport && server) {
|
|
129
127
|
await transport.handlePostMessage(req, res);
|
|
130
128
|
} else {
|
|
131
|
-
res.status(400).send("No transport found for sessionId");
|
|
129
|
+
res.status(400).send("No transport/server found for sessionId");
|
|
132
130
|
}
|
|
133
131
|
});
|
|
134
132
|
|
|
@@ -137,6 +135,26 @@ async function run() {
|
|
|
137
135
|
console.log(`[SSE Server] running on port ${port}`);
|
|
138
136
|
});
|
|
139
137
|
} else {
|
|
138
|
+
// stdio mode: single server instance
|
|
139
|
+
const server = new Server(
|
|
140
|
+
{
|
|
141
|
+
name: SERVER_NAME,
|
|
142
|
+
version: "0.1.0",
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
capabilities: {
|
|
146
|
+
tools: {},
|
|
147
|
+
},
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
server.onerror = (error) => console.error("[Error]", error);
|
|
151
|
+
await setupServerHandlers(server, tools);
|
|
152
|
+
|
|
153
|
+
process.on("SIGINT", async () => {
|
|
154
|
+
await server.close();
|
|
155
|
+
process.exit(0);
|
|
156
|
+
});
|
|
157
|
+
|
|
140
158
|
const transport = new StdioServerTransport();
|
|
141
159
|
await server.connect(transport);
|
|
142
160
|
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "figma-mcp-server",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "MCP server for Figma",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A simple MCP server for Figma",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"list-tools": "node index.js tools"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@modelcontextprotocol/sdk": "^1.12.
|
|
11
|
+
"@modelcontextprotocol/sdk": "^1.12.1",
|
|
12
12
|
"commander": "^14.0.0",
|
|
13
13
|
"dotenv": "^16.5.0",
|
|
14
14
|
"express": "^5.1.0"
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to create development resources for a Figma file.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args - Arguments for creating development resources.
|
|
5
|
+
* @param {string} args.file_key - The key of the Figma file.
|
|
6
|
+
* @param {string} args.node_id - The node ID for the resource.
|
|
7
|
+
* @param {string} args.name - The name of the development resource.
|
|
8
|
+
* @param {string} args.url - The URL for the development resource.
|
|
9
|
+
* @returns {Promise<Object>} - The result of the resource creation.
|
|
10
|
+
*/
|
|
11
|
+
const executeFunction = async ({ file_key, node_id, name, url }) => {
|
|
12
|
+
const baseUrl = 'https://api.figma.com';
|
|
13
|
+
const token = process.env.FIGMA_API_KEY;
|
|
14
|
+
try {
|
|
15
|
+
// Construct the URL for the API request
|
|
16
|
+
const url = `${baseUrl}/v1/files/${file_key}/dev_resources`;
|
|
17
|
+
|
|
18
|
+
// Set up headers for the request
|
|
19
|
+
const headers = {
|
|
20
|
+
'X-Figma-Token': token,
|
|
21
|
+
'Content-Type': 'application/json'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Create the body for the request
|
|
25
|
+
const body = JSON.stringify({
|
|
26
|
+
dev_resources: [
|
|
27
|
+
{
|
|
28
|
+
name,
|
|
29
|
+
url,
|
|
30
|
+
file_key,
|
|
31
|
+
node_id
|
|
32
|
+
}
|
|
33
|
+
]
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Perform the fetch request
|
|
37
|
+
const response = await fetch(url, {
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers,
|
|
40
|
+
body
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Check if the response was successful
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const errorData = await response.json();
|
|
46
|
+
throw new Error(errorData);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Parse and return the response data
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
return data;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Error creating development resources:', error);
|
|
54
|
+
return { error: 'An error occurred while creating development resources.' };
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Tool configuration for creating development resources for a Figma file.
|
|
60
|
+
* @type {Object}
|
|
61
|
+
*/
|
|
62
|
+
const apiTool = {
|
|
63
|
+
function: executeFunction,
|
|
64
|
+
definition: {
|
|
65
|
+
type: 'function',
|
|
66
|
+
function: {
|
|
67
|
+
name: 'create_dev_resources',
|
|
68
|
+
description: 'Create development resources for a Figma file.',
|
|
69
|
+
parameters: {
|
|
70
|
+
type: 'object',
|
|
71
|
+
properties: {
|
|
72
|
+
file_key: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
description: 'The key of the Figma file.'
|
|
75
|
+
},
|
|
76
|
+
node_id: {
|
|
77
|
+
type: 'string',
|
|
78
|
+
description: 'The node ID for the resource.'
|
|
79
|
+
},
|
|
80
|
+
name: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
description: 'The name of the development resource.'
|
|
83
|
+
},
|
|
84
|
+
url: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
description: 'The URL for the development resource.'
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
required: ['file_key', 'node_id', 'name', 'url']
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { apiTool };
|
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Function to create
|
|
2
|
+
* Function to create variable collections for a Figma file.
|
|
3
3
|
*
|
|
4
|
-
* @param {Object} args - Arguments for creating
|
|
4
|
+
* @param {Object} args - Arguments for creating variable collections.
|
|
5
5
|
* @param {string} args.file_key - The key of the Figma file where the variable collection will be created.
|
|
6
|
-
* @param {string} args.name - The name of the
|
|
6
|
+
* @param {string} args.name - The name of the variable collection to create.
|
|
7
7
|
* @returns {Promise<Object>} - The result of the variable collection creation.
|
|
8
8
|
*/
|
|
9
9
|
const executeFunction = async ({ file_key, name }) => {
|
|
10
|
-
const baseUrl = 'https://api.figma.com
|
|
10
|
+
const baseUrl = 'https://api.figma.com';
|
|
11
11
|
const token = process.env.FIGMA_API_KEY;
|
|
12
|
-
|
|
13
12
|
try {
|
|
14
13
|
// Construct the URL for the request
|
|
15
|
-
const url = `${baseUrl}/files/${file_key}/variables`;
|
|
14
|
+
const url = `${baseUrl}/v1/files/${file_key}/variables`;
|
|
16
15
|
|
|
17
16
|
// Set up headers for the request
|
|
18
17
|
const headers = {
|
|
@@ -20,7 +19,7 @@ const executeFunction = async ({ file_key, name }) => {
|
|
|
20
19
|
'Content-Type': 'application/json'
|
|
21
20
|
};
|
|
22
21
|
|
|
23
|
-
//
|
|
22
|
+
// Define the body of the request
|
|
24
23
|
const body = JSON.stringify({
|
|
25
24
|
variableCollections: [
|
|
26
25
|
{
|
|
@@ -47,13 +46,13 @@ const executeFunction = async ({ file_key, name }) => {
|
|
|
47
46
|
const data = await response.json();
|
|
48
47
|
return data;
|
|
49
48
|
} catch (error) {
|
|
50
|
-
console.error('Error creating variable
|
|
51
|
-
return { error: 'An error occurred while creating
|
|
49
|
+
console.error('Error creating variable collections:', error);
|
|
50
|
+
return { error: 'An error occurred while creating variable collections.' };
|
|
52
51
|
}
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
/**
|
|
56
|
-
* Tool configuration for creating
|
|
55
|
+
* Tool configuration for creating variable collections in a Figma file.
|
|
57
56
|
* @type {Object}
|
|
58
57
|
*/
|
|
59
58
|
const apiTool = {
|
|
@@ -61,8 +60,8 @@ const apiTool = {
|
|
|
61
60
|
definition: {
|
|
62
61
|
type: 'function',
|
|
63
62
|
function: {
|
|
64
|
-
name: '
|
|
65
|
-
description: 'Create
|
|
63
|
+
name: 'create_variable_collections',
|
|
64
|
+
description: 'Create variable collections for a Figma file.',
|
|
66
65
|
parameters: {
|
|
67
66
|
type: 'object',
|
|
68
67
|
properties: {
|
|
@@ -72,7 +71,7 @@ const apiTool = {
|
|
|
72
71
|
},
|
|
73
72
|
name: {
|
|
74
73
|
type: 'string',
|
|
75
|
-
description: 'The name of the
|
|
74
|
+
description: 'The name of the variable collection to create.'
|
|
76
75
|
}
|
|
77
76
|
},
|
|
78
77
|
required: ['file_key', 'name']
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to get metadata for a published component in Figma by its key.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args - Arguments for the request.
|
|
5
|
+
* @param {string} args.key - The key of the component to retrieve.
|
|
6
|
+
* @returns {Promise<Object>} - The metadata of the published component.
|
|
7
|
+
*/
|
|
8
|
+
const executeFunction = async ({ key }) => {
|
|
9
|
+
const baseUrl = 'https://api.figma.com/v1/components';
|
|
10
|
+
const token = process.env.FIGMA_API_KEY;
|
|
11
|
+
try {
|
|
12
|
+
// Construct the URL with the component key
|
|
13
|
+
const url = `${baseUrl}/${key}`;
|
|
14
|
+
|
|
15
|
+
// Set up headers for the request
|
|
16
|
+
const headers = {
|
|
17
|
+
'X-Figma-Token': token
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Perform the fetch request
|
|
21
|
+
const response = await fetch(url, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Check if the response was successful
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorData = await response.json();
|
|
29
|
+
throw new Error(errorData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse and return the response data
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
return data;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error retrieving component metadata:', error);
|
|
37
|
+
return { error: 'An error occurred while retrieving component metadata.' };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tool configuration for retrieving component metadata from Figma.
|
|
43
|
+
* @type {Object}
|
|
44
|
+
*/
|
|
45
|
+
const apiTool = {
|
|
46
|
+
function: executeFunction,
|
|
47
|
+
definition: {
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: {
|
|
50
|
+
name: 'get_published_component_by_key',
|
|
51
|
+
description: 'Retrieve metadata for a published component by its key.',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
key: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'The key of the component to retrieve.'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ['key']
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { apiTool };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to get metadata for a published component set by its key from Figma.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args - Arguments for the request.
|
|
5
|
+
* @param {string} args.key - The key of the component set to retrieve.
|
|
6
|
+
* @returns {Promise<Object>} - The metadata for the component set.
|
|
7
|
+
*/
|
|
8
|
+
const executeFunction = async ({ key }) => {
|
|
9
|
+
const baseUrl = 'https://api.figma.com';
|
|
10
|
+
const token = process.env.FIGMA_API_KEY;
|
|
11
|
+
try {
|
|
12
|
+
// Construct the URL with the component set key
|
|
13
|
+
const url = `${baseUrl}/v1/component_sets/${key}`;
|
|
14
|
+
|
|
15
|
+
// Set up headers for the request
|
|
16
|
+
const headers = {
|
|
17
|
+
'X-Figma-Token': token
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Perform the fetch request
|
|
21
|
+
const response = await fetch(url, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Check if the response was successful
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorData = await response.json();
|
|
29
|
+
throw new Error(errorData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse and return the response data
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
return data;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error retrieving component set metadata:', error);
|
|
37
|
+
return { error: 'An error occurred while retrieving component set metadata.' };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tool configuration for retrieving component set metadata from Figma.
|
|
43
|
+
* @type {Object}
|
|
44
|
+
*/
|
|
45
|
+
const apiTool = {
|
|
46
|
+
function: executeFunction,
|
|
47
|
+
definition: {
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: {
|
|
50
|
+
name: 'get_component_set',
|
|
51
|
+
description: 'Retrieve metadata for a published component set by its key.',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
key: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'The key of the component set to retrieve.'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ['key']
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { apiTool };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to get metadata for a published library in Figma by its ID.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args - Arguments for the library retrieval.
|
|
5
|
+
* @param {string} args.library_id - The ID of the library to retrieve.
|
|
6
|
+
* @returns {Promise<Object>} - The metadata of the published library.
|
|
7
|
+
*/
|
|
8
|
+
const executeFunction = async ({ library_id }) => {
|
|
9
|
+
const baseUrl = 'https://api.figma.com';
|
|
10
|
+
const token = process.env.FIGMA_API_KEY;
|
|
11
|
+
try {
|
|
12
|
+
// Construct the URL with the library ID
|
|
13
|
+
const url = `${baseUrl}/v1/libraries/${library_id}`;
|
|
14
|
+
|
|
15
|
+
// Set up headers for the request
|
|
16
|
+
const headers = {
|
|
17
|
+
'X-Figma-Token': token
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Perform the fetch request
|
|
21
|
+
const response = await fetch(url, {
|
|
22
|
+
method: 'GET',
|
|
23
|
+
headers
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Check if the response was successful
|
|
27
|
+
if (!response.ok) {
|
|
28
|
+
const errorData = await response.json();
|
|
29
|
+
throw new Error(errorData);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Parse and return the response data
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
return data;
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error retrieving library metadata:', error);
|
|
37
|
+
return { error: 'An error occurred while retrieving library metadata.' };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tool configuration for retrieving library metadata in Figma.
|
|
43
|
+
* @type {Object}
|
|
44
|
+
*/
|
|
45
|
+
const apiTool = {
|
|
46
|
+
function: executeFunction,
|
|
47
|
+
definition: {
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: {
|
|
50
|
+
name: 'get_library_by_id',
|
|
51
|
+
description: 'Retrieve metadata for a published library by its ID.',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
library_id: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'The ID of the library to retrieve.'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ['library_id']
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { apiTool };
|