figma-mcp-server 0.0.0-alpha.1 → 0.1.0

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.
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Function to get actions analytics for a specific library file in Figma.
3
+ *
4
+ * @param {Object} args - Arguments for the request.
5
+ * @param {string} args.library_file_key - The key of the library file for which to retrieve actions analytics.
6
+ * @returns {Promise<Object>} - The actions analytics related to the library file.
7
+ */
8
+ const executeFunction = async ({ library_file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+
12
+ try {
13
+ // Construct the URL for the request
14
+ const url = `${baseUrl}/analytics/libraries/${library_file_key}/actions`;
15
+
16
+ // Set up headers for the request
17
+ const headers = {
18
+ 'X-Figma-Token': token
19
+ };
20
+
21
+ // Perform the fetch request
22
+ const response = await fetch(url, {
23
+ method: 'GET',
24
+ headers
25
+ });
26
+
27
+ // Check if the response was successful
28
+ if (!response.ok) {
29
+ const errorData = await response.json();
30
+ throw new Error(errorData);
31
+ }
32
+
33
+ // Parse and return the response data
34
+ const data = await response.json();
35
+ return data;
36
+ } catch (error) {
37
+ console.error('Error getting actions analytics:', error);
38
+ return { error: 'An error occurred while retrieving actions analytics.' };
39
+ }
40
+ };
41
+
42
+ /**
43
+ * Tool configuration for getting actions analytics for a library file in Figma.
44
+ * @type {Object}
45
+ */
46
+ const apiTool = {
47
+ function: executeFunction,
48
+ definition: {
49
+ type: 'function',
50
+ function: {
51
+ name: 'get_actions_analytics',
52
+ description: 'Retrieve actions analytics for a specific library file in Figma.',
53
+ parameters: {
54
+ type: 'object',
55
+ properties: {
56
+ library_file_key: {
57
+ type: 'string',
58
+ description: 'The key of the library file for which to retrieve actions analytics.'
59
+ }
60
+ },
61
+ required: ['library_file_key']
62
+ }
63
+ }
64
+ }
65
+ };
66
+
67
+ export { apiTool };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Function to get all webhooks for a team in Figma.
3
+ *
4
+ * @returns {Promise<Object>} - The result of the webhook retrieval.
5
+ */
6
+ const executeFunction = async () => {
7
+ const webhookUrl = 'https://api.figma.com/v2/webhooks';
8
+ const token = process.env.FIGMA_API_KEY;
9
+ try {
10
+ // Set up headers for the request
11
+ const headers = {
12
+ 'X-Figma-Token': token
13
+ };
14
+
15
+ // Perform the fetch request
16
+ const response = await fetch(webhookUrl, {
17
+ method: 'GET',
18
+ headers
19
+ });
20
+
21
+ // Check if the response was successful
22
+ if (!response.ok) {
23
+ const errorData = await response.text();
24
+ throw new Error(errorData);
25
+ }
26
+
27
+ // Parse and return the response data
28
+ const data = await response.json();
29
+ return data;
30
+ } catch (error) {
31
+ console.error('Error retrieving webhooks:', error);
32
+ return { error: 'An error occurred while retrieving webhooks.' };
33
+ }
34
+ };
35
+
36
+ /**
37
+ * Tool configuration for getting all webhooks for a team in Figma.
38
+ * @type {Object}
39
+ */
40
+ const apiTool = {
41
+ function: executeFunction,
42
+ definition: {
43
+ type: 'function',
44
+ function: {
45
+ name: 'get_all_webhooks',
46
+ description: 'Retrieve all webhooks for a team in Figma.',
47
+ parameters: {
48
+ type: 'object',
49
+ properties: {},
50
+ required: []
51
+ }
52
+ }
53
+ }
54
+ };
55
+
56
+ export { apiTool };
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Function to retrieve information about specific nodes in a Figma file.
3
+ *
4
+ * @param {Object} args - Arguments for the node retrieval.
5
+ * @param {string} args.file_key - The key of the Figma file.
6
+ * @param {string} args.node_id - The IDs of the nodes to retrieve, comma-separated.
7
+ * @returns {Promise<Object>} - The result of the node retrieval.
8
+ */
9
+ const executeFunction = async ({ file_key, node_id }) => {
10
+ const baseUrl = 'https://api.figma.com/v1';
11
+ const token = process.env.FIGMA_API_KEY;
12
+
13
+ try {
14
+ // Construct the URL for the API request
15
+ const url = `${baseUrl}/files/${file_key}/nodes?ids=${node_id}`;
16
+
17
+ // Set up headers for the request
18
+ const headers = {
19
+ 'X-Figma-Token': token
20
+ };
21
+
22
+ // Perform the fetch request
23
+ const response = await fetch(url, {
24
+ method: 'GET',
25
+ headers
26
+ });
27
+
28
+ // Check if the response was successful
29
+ if (!response.ok) {
30
+ const errorData = await response.json();
31
+ throw new Error(errorData);
32
+ }
33
+
34
+ // Parse and return the response data
35
+ const data = await response.json();
36
+ return data;
37
+ } catch (error) {
38
+ console.error('Error retrieving node information:', error);
39
+ return { error: 'An error occurred while retrieving node information.' };
40
+ }
41
+ };
42
+
43
+ /**
44
+ * Tool configuration for retrieving node information from a Figma file.
45
+ * @type {Object}
46
+ */
47
+ const apiTool = {
48
+ function: executeFunction,
49
+ definition: {
50
+ type: 'function',
51
+ function: {
52
+ name: 'get_design_node',
53
+ description: 'Retrieve information about specific nodes in a Figma file.',
54
+ parameters: {
55
+ type: 'object',
56
+ properties: {
57
+ file_key: {
58
+ type: 'string',
59
+ description: 'The key of the Figma file.'
60
+ },
61
+ node_id: {
62
+ type: 'string',
63
+ description: 'The IDs of the nodes to retrieve, comma-separated.'
64
+ }
65
+ },
66
+ required: ['file_key', 'node_id']
67
+ }
68
+ }
69
+ }
70
+ };
71
+
72
+ export { apiTool };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to retrieve a Figma file by its unique file key.
3
+ *
4
+ * @param {Object} args - Arguments for the file retrieval.
5
+ * @param {string} args.file_key - The unique identifier of the Figma file.
6
+ * @returns {Promise<Object>} - The result of the file retrieval.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/files/${file_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.err || 'An error occurred while retrieving the file.');
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 Figma file:', error);
37
+ return { error: 'An error occurred while retrieving the Figma file.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for retrieving a Figma file.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'get_design',
51
+ description: 'Retrieve a Figma file by its unique file key.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ file_key: {
56
+ type: 'string',
57
+ description: 'The unique identifier of the Figma file.'
58
+ }
59
+ },
60
+ required: ['file_key']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Function to retrieve development resources for a specific Figma file.
3
+ *
4
+ * @param {Object} args - Arguments for the request.
5
+ * @param {string} args.file_key - The unique key of the Figma file.
6
+ * @returns {Promise<Object>} - The details of the development resources related to the specified file.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+
12
+ try {
13
+ // Construct the URL for the request
14
+ const url = `${baseUrl}/files/${file_key}/dev_resources`;
15
+
16
+ // Set up headers for the request
17
+ const headers = {
18
+ 'X-Figma-Token': token
19
+ };
20
+
21
+ // Perform the fetch request
22
+ const response = await fetch(url, {
23
+ method: 'GET',
24
+ headers
25
+ });
26
+
27
+ // Check if the response was successful
28
+ if (!response.ok) {
29
+ const errorData = await response.json();
30
+ throw new Error(errorData);
31
+ }
32
+
33
+ // Parse and return the response data
34
+ const data = await response.json();
35
+ return data;
36
+ } catch (error) {
37
+ console.error('Error retrieving development resources:', error);
38
+ return { error: 'An error occurred while retrieving development resources.' };
39
+ }
40
+ };
41
+
42
+ /**
43
+ * Tool configuration for retrieving development resources from Figma.
44
+ * @type {Object}
45
+ */
46
+ const apiTool = {
47
+ function: executeFunction,
48
+ definition: {
49
+ type: 'function',
50
+ function: {
51
+ name: 'get_dev_resources',
52
+ description: 'Retrieve development resources for a specific Figma file.',
53
+ parameters: {
54
+ type: 'object',
55
+ properties: {
56
+ file_key: {
57
+ type: 'string',
58
+ description: 'The unique key of the Figma file.'
59
+ }
60
+ },
61
+ required: ['file_key']
62
+ }
63
+ }
64
+ }
65
+ };
66
+
67
+ export { apiTool };
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Function to get comments for a specific Figma file.
3
+ *
4
+ * @param {Object} args - Arguments for the request.
5
+ * @param {string} args.file_key - The key of the Figma file to retrieve comments from.
6
+ * @returns {Promise<Object>} - The comments associated with the specified file.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+
12
+ try {
13
+ // Construct the URL for the request
14
+ const url = `${baseUrl}/files/${file_key}/comments`;
15
+
16
+ // Set up headers for the request
17
+ const headers = {
18
+ 'X-Figma-Token': token
19
+ };
20
+
21
+ // Perform the fetch request
22
+ const response = await fetch(url, {
23
+ method: 'GET',
24
+ headers
25
+ });
26
+
27
+ // Check if the response was successful
28
+ if (!response.ok) {
29
+ const errorData = await response.json();
30
+ throw new Error(errorData);
31
+ }
32
+
33
+ // Parse and return the response data
34
+ const data = await response.json();
35
+ return data;
36
+ } catch (error) {
37
+ console.error('Error getting file comments:', error);
38
+ return { error: 'An error occurred while retrieving file comments.' };
39
+ }
40
+ };
41
+
42
+ /**
43
+ * Tool configuration for getting comments from a Figma file.
44
+ * @type {Object}
45
+ */
46
+ const apiTool = {
47
+ function: executeFunction,
48
+ definition: {
49
+ type: 'function',
50
+ function: {
51
+ name: 'get_file_comments',
52
+ description: 'Retrieve comments associated with a specific Figma file.',
53
+ parameters: {
54
+ type: 'object',
55
+ properties: {
56
+ file_key: {
57
+ type: 'string',
58
+ description: 'The key of the Figma file to retrieve comments from.'
59
+ }
60
+ },
61
+ required: ['file_key']
62
+ }
63
+ }
64
+ }
65
+ };
66
+
67
+ export { apiTool };
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Function to retrieve images from Figma using a specific file key and optional image IDs.
3
+ *
4
+ * @param {Object} args - Arguments for the image retrieval.
5
+ * @param {string} args.file_key - The key of the Figma file.
6
+ * @param {string} [args.ids] - A comma-separated list of specific image IDs to fetch.
7
+ * @returns {Promise<Object>} - The result of the image retrieval.
8
+ */
9
+ const executeFunction = async ({ file_key, ids }) => {
10
+ const baseUrl = 'https://api.figma.com/v1';
11
+ const token = process.env.FIGMA_API_KEY;
12
+ try {
13
+ // Construct the URL with the file key and optional image IDs
14
+ const url = new URL(`${baseUrl}/images/${file_key}`);
15
+ if (ids) {
16
+ url.searchParams.append('ids', ids);
17
+ }
18
+
19
+ // Set up headers for the request
20
+ const headers = {
21
+ 'X-Figma-Token': token
22
+ };
23
+
24
+ // Perform the fetch request
25
+ const response = await fetch(url.toString(), {
26
+ method: 'GET',
27
+ headers
28
+ });
29
+
30
+ // Check if the response was successful
31
+ if (!response.ok) {
32
+ const errorData = await response.json();
33
+ throw new Error(errorData);
34
+ }
35
+
36
+ // Parse and return the response data
37
+ const data = await response.json();
38
+ return data;
39
+ } catch (error) {
40
+ console.error('Error retrieving images from Figma:', error);
41
+ return { error: 'An error occurred while retrieving images from Figma.' };
42
+ }
43
+ };
44
+
45
+ /**
46
+ * Tool configuration for retrieving images from Figma.
47
+ * @type {Object}
48
+ */
49
+ const apiTool = {
50
+ function: executeFunction,
51
+ definition: {
52
+ type: 'function',
53
+ function: {
54
+ name: 'get_image_node',
55
+ description: 'Retrieve images from Figma using a specific file key and optional image IDs.',
56
+ parameters: {
57
+ type: 'object',
58
+ properties: {
59
+ file_key: {
60
+ type: 'string',
61
+ description: 'The key of the Figma file.'
62
+ },
63
+ ids: {
64
+ type: 'string',
65
+ description: 'A comma-separated list of specific image IDs to fetch.'
66
+ }
67
+ },
68
+ required: ['file_key']
69
+ }
70
+ }
71
+ }
72
+ };
73
+
74
+ export { apiTool };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to retrieve images associated with a Figma file.
3
+ *
4
+ * @param {Object} args - Arguments for the image retrieval.
5
+ * @param {string} args.file_key - The Figma file key representing the specific Figma file from which images are to be retrieved.
6
+ * @returns {Promise<Object>} - The result of the image retrieval.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the image retrieval
13
+ const url = `${baseUrl}/files/${file_key}/images`;
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 images:', error);
37
+ return { error: 'An error occurred while retrieving images.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for retrieving images from Figma.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'get_images',
51
+ description: 'Retrieve images associated with a Figma file.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ file_key: {
56
+ type: 'string',
57
+ description: 'The Figma file key representing the specific Figma file from which images are to be retrieved.'
58
+ }
59
+ },
60
+ required: ['file_key']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to get library analytics from Figma.
3
+ *
4
+ * @param {Object} args - Arguments for the library analytics request.
5
+ * @param {string} args.library_file_key - The unique identifier of the library file.
6
+ * @returns {Promise<Object>} - The result of the library analytics request.
7
+ */
8
+ const executeFunction = async ({ library_file_key }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/analytics/libraries/${library_file_key}/usages`;
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 getting library analytics:', error);
37
+ return { error: 'An error occurred while retrieving library analytics.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for getting library analytics from Figma.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'get_library_analytics',
51
+ description: 'Retrieve library analytics from Figma.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ library_file_key: {
56
+ type: 'string',
57
+ description: 'The unique identifier of the library file.'
58
+ }
59
+ },
60
+ required: ['library_file_key']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to get project files from Figma.
3
+ *
4
+ * @param {Object} args - Arguments for the request.
5
+ * @param {string} args.project_id - The ID of the project to retrieve files from.
6
+ * @returns {Promise<Object>} - The list of files associated with the specified project.
7
+ */
8
+ const executeFunction = async ({ project_id }) => {
9
+ const baseUrl = 'https://api.figma.com/v1';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/projects/${project_id}/files`;
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 project files:', error);
37
+ return { error: 'An error occurred while retrieving project files.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for getting project files from Figma.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'get_project_files',
51
+ description: 'Retrieve files associated with a specific project in Figma.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ project_id: {
56
+ type: 'string',
57
+ description: 'The ID of the project to retrieve files from.'
58
+ }
59
+ },
60
+ required: ['project_id']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };