figma-mcp-server 0.1.0 → 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.
Files changed (31) hide show
  1. package/README.md +40 -40
  2. package/mcpServer.js +51 -33
  3. package/package.json +3 -3
  4. package/tools/figma/figma-api/create-dev-resources-for-a-file.js +95 -0
  5. package/tools/figma/figma-api/{create-variable-collection.js → create-variable-collections-for-a-file.js} +12 -13
  6. package/tools/figma/figma-api/get-a-published-component-by-key.js +66 -0
  7. package/tools/figma/figma-api/get-a-published-component-set-by-key.js +66 -0
  8. package/tools/figma/figma-api/get-a-published-library-by-id.js +66 -0
  9. package/tools/figma/figma-api/get-a-published-style-by-key.js +66 -0
  10. package/tools/figma/figma-api/{get-all-webhooks-for-team.js → get-current-user.js} +10 -10
  11. package/tools/figma/figma-api/{get-design-node.js → get-file-nodes.js} +17 -15
  12. package/tools/figma/figma-api/get-file-version-history.js +66 -0
  13. package/tools/figma/figma-api/{get-design.js → get-file.js} +8 -8
  14. package/tools/figma/figma-api/{get-image-node.js → get-image-fills.js} +17 -17
  15. package/tools/figma/figma-api/{get-library-analytics.js → get-library-action-analytics.js} +12 -12
  16. package/tools/figma/figma-api/{get-actions-analytics.js → get-library-usage-analytics.js} +12 -13
  17. package/tools/figma/figma-api/list-comments-on-a-file.js +66 -0
  18. package/tools/figma/figma-api/{get-dev-resources.js → list-component-sets-in-a-file.js} +11 -11
  19. package/tools/figma/figma-api/list-components-in-a-file.js +66 -0
  20. package/tools/figma/figma-api/list-dev-resources-for-a-file.js +66 -0
  21. package/tools/figma/figma-api/{get-project-files.js → list-files-in-a-project.js} +12 -11
  22. package/tools/figma/figma-api/{get-team-projects.js → list-projects-in-a-team.js} +11 -11
  23. package/tools/figma/figma-api/{add-webhook.js → list-published-libraries.js} +11 -12
  24. package/tools/figma/figma-api/{get-file-comments.js → list-styles-in-a-file.js} +11 -11
  25. package/tools/figma/figma-api/{get-images.js → list-variables-for-a-file.js} +13 -13
  26. package/tools/figma/figma-api/post-a-comment-to-a-file.js +102 -0
  27. package/tools/paths.js +23 -17
  28. package/tools/figma/figma-api/delete-webhook.js +0 -64
  29. package/tools/figma/figma-api/post-a-new-comment.js +0 -89
  30. package/tools/figma/figma-api/post-dev-resource.js +0 -93
  31. package/tools/figma/figma-api/reply-to-comment.js +0 -84
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to list components in 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 components from.
6
+ * @returns {Promise<Object>} - The list of components in the specified Figma file.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/v1/files/${file_key}/components`;
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 listing components in file:', error);
37
+ return { error: 'An error occurred while listing components in the file.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for listing components in a Figma file.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'list_components',
51
+ description: 'List components in a specific Figma file.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ file_key: {
56
+ type: 'string',
57
+ description: 'The key of the Figma file to retrieve components from.'
58
+ }
59
+ },
60
+ required: ['file_key']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Function to list development resources 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 development resources for.
6
+ * @returns {Promise<Object>} - The result of the development resources request.
7
+ */
8
+ const executeFunction = async ({ file_key }) => {
9
+ const baseUrl = 'https://api.figma.com';
10
+ const token = process.env.FIGMA_API_KEY;
11
+ try {
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/v1/files/${file_key}/dev_resources`;
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 listing development resources:', error);
37
+ return { error: 'An error occurred while listing development resources.' };
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Tool configuration for listing development resources for a Figma file.
43
+ * @type {Object}
44
+ */
45
+ const apiTool = {
46
+ function: executeFunction,
47
+ definition: {
48
+ type: 'function',
49
+ function: {
50
+ name: 'list_dev_resources',
51
+ description: 'List development resources for a specific Figma file.',
52
+ parameters: {
53
+ type: 'object',
54
+ properties: {
55
+ file_key: {
56
+ type: 'string',
57
+ description: 'The key of the Figma file to retrieve development resources for.'
58
+ }
59
+ },
60
+ required: ['file_key']
61
+ }
62
+ }
63
+ }
64
+ };
65
+
66
+ export { apiTool };
@@ -1,16 +1,17 @@
1
1
  /**
2
- * Function to get project files from Figma.
2
+ * Function to list files in a specified Figma project.
3
3
  *
4
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.
5
+ * @param {string} args.project_id - The ID of the project to list files from.
6
+ * @returns {Promise<Object>} - The result of the files listing.
7
7
  */
8
8
  const executeFunction = async ({ project_id }) => {
9
- const baseUrl = 'https://api.figma.com/v1';
9
+ const baseUrl = 'https://api.figma.com';
10
10
  const token = process.env.FIGMA_API_KEY;
11
+
11
12
  try {
12
13
  // Construct the URL for the request
13
- const url = `${baseUrl}/projects/${project_id}/files`;
14
+ const url = `${baseUrl}/v1/projects/${project_id}/files`;
14
15
 
15
16
  // Set up headers for the request
16
17
  const headers = {
@@ -33,13 +34,13 @@ const executeFunction = async ({ project_id }) => {
33
34
  const data = await response.json();
34
35
  return data;
35
36
  } catch (error) {
36
- console.error('Error retrieving project files:', error);
37
- return { error: 'An error occurred while retrieving project files.' };
37
+ console.error('Error listing files in project:', error);
38
+ return { error: 'An error occurred while listing files in the project.' };
38
39
  }
39
40
  };
40
41
 
41
42
  /**
42
- * Tool configuration for getting project files from Figma.
43
+ * Tool configuration for listing files in a Figma project.
43
44
  * @type {Object}
44
45
  */
45
46
  const apiTool = {
@@ -47,14 +48,14 @@ const apiTool = {
47
48
  definition: {
48
49
  type: 'function',
49
50
  function: {
50
- name: 'get_project_files',
51
- description: 'Retrieve files associated with a specific project in Figma.',
51
+ name: 'list_files_in_project',
52
+ description: 'List files in a specified Figma project.',
52
53
  parameters: {
53
54
  type: 'object',
54
55
  properties: {
55
56
  project_id: {
56
57
  type: 'string',
57
- description: 'The ID of the project to retrieve files from.'
58
+ description: 'The ID of the project to list files from.'
58
59
  }
59
60
  },
60
61
  required: ['project_id']
@@ -1,16 +1,16 @@
1
1
  /**
2
- * Function to get projects associated with a specific team in Figma.
2
+ * Function to list projects in a specified team on Figma.
3
3
  *
4
4
  * @param {Object} args - Arguments for the request.
5
- * @param {string} args.team_id - The ID of the team whose projects are to be retrieved.
6
- * @returns {Promise<Object>} - The list of projects associated with the team.
5
+ * @param {string} args.team_id - The ID of the team for which to list projects.
6
+ * @returns {Promise<Object>} - The list of projects within the specified team.
7
7
  */
8
8
  const executeFunction = async ({ team_id }) => {
9
- const baseUrl = 'https://api.figma.com/v1';
9
+ const baseUrl = 'https://api.figma.com';
10
10
  const token = process.env.FIGMA_API_KEY;
11
11
  try {
12
12
  // Construct the URL for the request
13
- const url = `${baseUrl}/teams/${team_id}/projects`;
13
+ const url = `${baseUrl}/v1/teams/${team_id}/projects`;
14
14
 
15
15
  // Set up headers for the request
16
16
  const headers = {
@@ -33,13 +33,13 @@ const executeFunction = async ({ team_id }) => {
33
33
  const data = await response.json();
34
34
  return data;
35
35
  } catch (error) {
36
- console.error('Error retrieving team projects:', error);
37
- return { error: 'An error occurred while retrieving team projects.' };
36
+ console.error('Error listing projects:', error);
37
+ return { error: 'An error occurred while listing projects.' };
38
38
  }
39
39
  };
40
40
 
41
41
  /**
42
- * Tool configuration for getting team projects in Figma.
42
+ * Tool configuration for listing projects in a team on Figma.
43
43
  * @type {Object}
44
44
  */
45
45
  const apiTool = {
@@ -47,14 +47,14 @@ const apiTool = {
47
47
  definition: {
48
48
  type: 'function',
49
49
  function: {
50
- name: 'get_team_projects',
51
- description: 'Retrieve projects associated with a specific team in Figma.',
50
+ name: 'list_projects_in_team',
51
+ description: 'List all projects within a specified team on Figma.',
52
52
  parameters: {
53
53
  type: 'object',
54
54
  properties: {
55
55
  team_id: {
56
56
  type: 'string',
57
- description: 'The ID of the team whose projects are to be retrieved.'
57
+ description: 'The ID of the team for which to list projects.'
58
58
  }
59
59
  },
60
60
  required: ['team_id']
@@ -1,21 +1,20 @@
1
1
  /**
2
- * Function to add a webhook in Figma.
2
+ * Function to list published libraries in Figma.
3
3
  *
4
- * @returns {Promise<Object>} - The result of the webhook addition.
4
+ * @returns {Promise<Array>} - A promise that resolves to an array of published libraries.
5
5
  */
6
6
  const executeFunction = async () => {
7
- const webhookUrl = 'https://api.figma.com/v2/webhooks';
7
+ const baseUrl = 'https://api.figma.com/v1/libraries/published';
8
8
  const token = process.env.FIGMA_API_KEY;
9
9
  try {
10
10
  // Set up headers for the request
11
11
  const headers = {
12
- 'X-Figma-Token': token,
13
- 'Content-Type': 'application/json'
12
+ 'X-Figma-Token': token
14
13
  };
15
14
 
16
15
  // Perform the fetch request
17
- const response = await fetch(webhookUrl, {
18
- method: 'POST',
16
+ const response = await fetch(baseUrl, {
17
+ method: 'GET',
19
18
  headers
20
19
  });
21
20
 
@@ -29,13 +28,13 @@ const executeFunction = async () => {
29
28
  const data = await response.json();
30
29
  return data;
31
30
  } catch (error) {
32
- console.error('Error adding webhook:', error);
33
- return { error: 'An error occurred while adding the webhook.' };
31
+ console.error('Error listing published libraries:', error);
32
+ return { error: 'An error occurred while listing published libraries.' };
34
33
  }
35
34
  };
36
35
 
37
36
  /**
38
- * Tool configuration for adding a webhook in Figma.
37
+ * Tool configuration for listing published libraries in Figma.
39
38
  * @type {Object}
40
39
  */
41
40
  const apiTool = {
@@ -43,8 +42,8 @@ const apiTool = {
43
42
  definition: {
44
43
  type: 'function',
45
44
  function: {
46
- name: 'add_webhook',
47
- description: 'Add a webhook in Figma.',
45
+ name: 'list_published_libraries',
46
+ description: 'Returns all published libraries available to the authenticated user.',
48
47
  parameters: {
49
48
  type: 'object',
50
49
  properties: {},
@@ -1,17 +1,17 @@
1
1
  /**
2
- * Function to get comments for a specific Figma file.
2
+ * Function to list styles in a specific Figma file.
3
3
  *
4
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.
5
+ * @param {string} args.file_key - The key of the Figma file to retrieve styles from.
6
+ * @returns {Promise<Object>} - The response containing styles from the specified Figma file.
7
7
  */
8
8
  const executeFunction = async ({ file_key }) => {
9
- const baseUrl = 'https://api.figma.com/v1';
9
+ const baseUrl = 'https://api.figma.com';
10
10
  const token = process.env.FIGMA_API_KEY;
11
11
 
12
12
  try {
13
13
  // Construct the URL for the request
14
- const url = `${baseUrl}/files/${file_key}/comments`;
14
+ const url = `${baseUrl}/v1/files/${file_key}/styles`;
15
15
 
16
16
  // Set up headers for the request
17
17
  const headers = {
@@ -34,13 +34,13 @@ const executeFunction = async ({ file_key }) => {
34
34
  const data = await response.json();
35
35
  return data;
36
36
  } catch (error) {
37
- console.error('Error getting file comments:', error);
38
- return { error: 'An error occurred while retrieving file comments.' };
37
+ console.error('Error listing styles in the Figma file:', error);
38
+ return { error: 'An error occurred while listing styles in the Figma file.' };
39
39
  }
40
40
  };
41
41
 
42
42
  /**
43
- * Tool configuration for getting comments from a Figma file.
43
+ * Tool configuration for listing styles in a Figma file.
44
44
  * @type {Object}
45
45
  */
46
46
  const apiTool = {
@@ -48,14 +48,14 @@ const apiTool = {
48
48
  definition: {
49
49
  type: 'function',
50
50
  function: {
51
- name: 'get_file_comments',
52
- description: 'Retrieve comments associated with a specific Figma file.',
51
+ name: 'list_styles_in_file',
52
+ description: 'List styles in a specific Figma file.',
53
53
  parameters: {
54
54
  type: 'object',
55
55
  properties: {
56
56
  file_key: {
57
57
  type: 'string',
58
- description: 'The key of the Figma file to retrieve comments from.'
58
+ description: 'The key of the Figma file to retrieve styles from.'
59
59
  }
60
60
  },
61
61
  required: ['file_key']
@@ -1,16 +1,16 @@
1
1
  /**
2
- * Function to retrieve images associated with a Figma file.
2
+ * Function to list variables for a specific Figma file.
3
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.
4
+ * @param {Object} args - Arguments for the request.
5
+ * @param {string} args.file_key - The key of the Figma file for which to list variables.
6
+ * @returns {Promise<Object>} - The response containing the variable collections and variables defined in the specified Figma file.
7
7
  */
8
8
  const executeFunction = async ({ file_key }) => {
9
- const baseUrl = 'https://api.figma.com/v1';
9
+ const baseUrl = 'https://api.figma.com';
10
10
  const token = process.env.FIGMA_API_KEY;
11
11
  try {
12
- // Construct the URL for the image retrieval
13
- const url = `${baseUrl}/files/${file_key}/images`;
12
+ // Construct the URL for the request
13
+ const url = `${baseUrl}/v1/files/${file_key}/variables`;
14
14
 
15
15
  // Set up headers for the request
16
16
  const headers = {
@@ -33,13 +33,13 @@ const executeFunction = async ({ file_key }) => {
33
33
  const data = await response.json();
34
34
  return data;
35
35
  } catch (error) {
36
- console.error('Error retrieving images:', error);
37
- return { error: 'An error occurred while retrieving images.' };
36
+ console.error('Error listing variables for the file:', error);
37
+ return { error: 'An error occurred while listing variables for the file.' };
38
38
  }
39
39
  };
40
40
 
41
41
  /**
42
- * Tool configuration for retrieving images from Figma.
42
+ * Tool configuration for listing variables for a Figma file.
43
43
  * @type {Object}
44
44
  */
45
45
  const apiTool = {
@@ -47,14 +47,14 @@ const apiTool = {
47
47
  definition: {
48
48
  type: 'function',
49
49
  function: {
50
- name: 'get_images',
51
- description: 'Retrieve images associated with a Figma file.',
50
+ name: 'list_file_variables',
51
+ description: 'List variables for a specific Figma file.',
52
52
  parameters: {
53
53
  type: 'object',
54
54
  properties: {
55
55
  file_key: {
56
56
  type: 'string',
57
- description: 'The Figma file key representing the specific Figma file from which images are to be retrieved.'
57
+ description: 'The key of the Figma file for which to list variables.'
58
58
  }
59
59
  },
60
60
  required: ['file_key']
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Function to post a comment to a Figma file.
3
+ *
4
+ * @param {Object} args - Arguments for the comment.
5
+ * @param {string} args.file_key - The key of the Figma file to comment on.
6
+ * @param {string} args.message - The message of the comment.
7
+ * @param {Object} [args.client_meta] - Optional metadata for the comment's location.
8
+ * @param {number} [args.client_meta.x] - The x-coordinate for the comment.
9
+ * @param {number} [args.client_meta.y] - The y-coordinate for the comment.
10
+ * @param {string} [args.client_meta.node_id] - The node ID for the comment.
11
+ * @returns {Promise<Object>} - The result of the comment posting.
12
+ */
13
+ const executeFunction = async ({ file_key, message, client_meta = {} }) => {
14
+ const baseUrl = 'https://api.figma.com';
15
+ const token = process.env.FIGMA_API_KEY;
16
+
17
+ try {
18
+ // Construct the URL for posting a comment
19
+ const url = `${baseUrl}/v1/files/${file_key}/comments`;
20
+
21
+ // Set up headers for the request
22
+ const headers = {
23
+ 'X-Figma-Token': token,
24
+ 'Content-Type': 'application/json'
25
+ };
26
+
27
+ // Prepare the body of the request
28
+ const body = JSON.stringify({
29
+ message,
30
+ client_meta
31
+ });
32
+
33
+ // Perform the fetch request
34
+ const response = await fetch(url, {
35
+ method: 'POST',
36
+ headers,
37
+ body
38
+ });
39
+
40
+ // Check if the response was successful
41
+ if (!response.ok) {
42
+ const errorData = await response.json();
43
+ throw new Error(errorData);
44
+ }
45
+
46
+ // Parse and return the response data
47
+ const data = await response.json();
48
+ return data;
49
+ } catch (error) {
50
+ console.error('Error posting comment to Figma file:', error);
51
+ return { error: 'An error occurred while posting the comment.' };
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Tool configuration for posting comments to a Figma file.
57
+ * @type {Object}
58
+ */
59
+ const apiTool = {
60
+ function: executeFunction,
61
+ definition: {
62
+ type: 'function',
63
+ function: {
64
+ name: 'post_comment',
65
+ description: 'Post a comment to a Figma file.',
66
+ parameters: {
67
+ type: 'object',
68
+ properties: {
69
+ file_key: {
70
+ type: 'string',
71
+ description: 'The key of the Figma file to comment on.'
72
+ },
73
+ message: {
74
+ type: 'string',
75
+ description: 'The message of the comment.'
76
+ },
77
+ client_meta: {
78
+ type: 'object',
79
+ properties: {
80
+ x: {
81
+ type: 'number',
82
+ description: 'The x-coordinate for the comment.'
83
+ },
84
+ y: {
85
+ type: 'number',
86
+ description: 'The y-coordinate for the comment.'
87
+ },
88
+ node_id: {
89
+ type: 'string',
90
+ description: 'The node ID for the comment.'
91
+ }
92
+ },
93
+ description: 'Optional metadata for the comment\'s location.'
94
+ }
95
+ },
96
+ required: ['file_key', 'message']
97
+ }
98
+ }
99
+ }
100
+ };
101
+
102
+ export { apiTool };
package/tools/paths.js CHANGED
@@ -1,19 +1,25 @@
1
1
  export const toolPaths = [
2
- 'figma/figma-api/get-all-webhooks-for-team.js',
3
- 'figma/figma-api/add-webhook.js',
4
- 'figma/figma-api/delete-webhook.js',
5
- 'figma/figma-api/get-library-analytics.js',
6
- 'figma/figma-api/get-dev-resources.js',
7
- 'figma/figma-api/get-design.js',
8
- 'figma/figma-api/get-actions-analytics.js',
9
- 'figma/figma-api/get-image-node.js',
10
- 'figma/figma-api/get-team-projects.js',
11
- 'figma/figma-api/get-project-files.js',
12
- 'figma/figma-api/get-file-comments.js',
13
- 'figma/figma-api/post-dev-resource.js',
14
- 'figma/figma-api/get-images.js',
15
- 'figma/figma-api/create-variable-collection.js',
16
- 'figma/figma-api/get-design-node.js',
17
- 'figma/figma-api/post-a-new-comment.js',
18
- 'figma/figma-api/reply-to-comment.js'
2
+ 'figma/figma-api/list-published-libraries.js',
3
+ 'figma/figma-api/get-a-published-component-by-key.js',
4
+ 'figma/figma-api/get-file.js',
5
+ 'figma/figma-api/list-component-sets-in-a-file.js',
6
+ 'figma/figma-api/list-dev-resources-for-a-file.js',
7
+ 'figma/figma-api/get-a-published-library-by-id.js',
8
+ 'figma/figma-api/list-components-in-a-file.js',
9
+ 'figma/figma-api/get-library-usage-analytics.js',
10
+ 'figma/figma-api/list-comments-on-a-file.js',
11
+ 'figma/figma-api/get-image-fills.js',
12
+ 'figma/figma-api/list-variables-for-a-file.js',
13
+ 'figma/figma-api/get-file-version-history.js',
14
+ 'figma/figma-api/list-files-in-a-project.js',
15
+ 'figma/figma-api/get-library-action-analytics.js',
16
+ 'figma/figma-api/create-variable-collections-for-a-file.js',
17
+ 'figma/figma-api/get-file-nodes.js',
18
+ 'figma/figma-api/get-a-published-style-by-key.js',
19
+ 'figma/figma-api/get-current-user.js',
20
+ 'figma/figma-api/create-dev-resources-for-a-file.js',
21
+ 'figma/figma-api/list-styles-in-a-file.js',
22
+ 'figma/figma-api/list-projects-in-a-team.js',
23
+ 'figma/figma-api/get-a-published-component-set-by-key.js',
24
+ 'figma/figma-api/post-a-comment-to-a-file.js'
19
25
  ];
@@ -1,64 +0,0 @@
1
- /**
2
- * Function to delete a specific webhook from Figma.
3
- *
4
- * @param {Object} args - Arguments for the deletion.
5
- * @param {string} args.webhook_id - The ID of the webhook to delete.
6
- * @returns {Promise<Object>} - The result of the deletion operation.
7
- */
8
- const executeFunction = async ({ webhook_id }) => {
9
- const baseUrl = 'https://api.figma.com/v1';
10
- const token = process.env.FIGMA_API_KEY;
11
- const webhookUrl = `${baseUrl}/webhooks/${webhook_id}`;
12
-
13
- try {
14
- // Set up headers for the request
15
- const headers = {
16
- 'X-Figma-Token': token
17
- };
18
-
19
- // Perform the fetch request
20
- const response = await fetch(webhookUrl, {
21
- method: 'DELETE',
22
- headers
23
- });
24
-
25
- // Check if the response was successful
26
- if (!response.ok) {
27
- const errorData = await response.json();
28
- throw new Error(errorData);
29
- }
30
-
31
- // Return the response data (should be empty for successful deletion)
32
- return {};
33
- } catch (error) {
34
- console.error('Error deleting webhook:', error);
35
- return { error: 'An error occurred while deleting the webhook.' };
36
- }
37
- };
38
-
39
- /**
40
- * Tool configuration for deleting a webhook from Figma.
41
- * @type {Object}
42
- */
43
- const apiTool = {
44
- function: executeFunction,
45
- definition: {
46
- type: 'function',
47
- function: {
48
- name: 'delete_webhook',
49
- description: 'Delete a specific webhook from Figma.',
50
- parameters: {
51
- type: 'object',
52
- properties: {
53
- webhook_id: {
54
- type: 'string',
55
- description: 'The ID of the webhook to delete.'
56
- }
57
- },
58
- required: ['webhook_id']
59
- }
60
- }
61
- }
62
- };
63
-
64
- export { apiTool };