figma-mcp-server 0.1.0 → 0.1.2
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/.env.example +1 -0
- package/Dockerfile +21 -2
- package/README.md +40 -40
- package/mcpServer.js +59 -35
- package/package.json +5 -4
- package/smithery.yaml +39 -0
- 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
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function to list comments on a Figma file.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} args - Arguments for the comment listing.
|
|
5
|
+
* @param {string} args.file_key - The key of the Figma file to list comments from.
|
|
6
|
+
* @returns {Promise<Array>} - A promise that resolves to an array of comments.
|
|
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 API request
|
|
13
|
+
const url = `${baseUrl}/v1/files/${file_key}/comments`;
|
|
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.comments || [];
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error('Error listing comments on the Figma file:', error);
|
|
37
|
+
return { error: 'An error occurred while listing comments.' };
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Tool configuration for listing comments on a Figma file.
|
|
43
|
+
* @type {Object}
|
|
44
|
+
*/
|
|
45
|
+
const apiTool = {
|
|
46
|
+
function: executeFunction,
|
|
47
|
+
definition: {
|
|
48
|
+
type: 'function',
|
|
49
|
+
function: {
|
|
50
|
+
name: 'list_comments',
|
|
51
|
+
description: 'List comments on a Figma file.',
|
|
52
|
+
parameters: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
file_key: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
description: 'The key of the Figma file to list comments from.'
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
required: ['file_key']
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { apiTool };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Function to
|
|
2
|
+
* Function to list component sets in a specific Figma file.
|
|
3
3
|
*
|
|
4
4
|
* @param {Object} args - Arguments for the request.
|
|
5
|
-
* @param {string} args.file_key - The
|
|
6
|
-
* @returns {Promise<Object>} - The
|
|
5
|
+
* @param {string} args.file_key - The key of the Figma file to retrieve component sets from.
|
|
6
|
+
* @returns {Promise<Object>} - The response containing the list of component sets.
|
|
7
7
|
*/
|
|
8
8
|
const executeFunction = async ({ file_key }) => {
|
|
9
|
-
const baseUrl = 'https://api.figma.com
|
|
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}/
|
|
14
|
+
const url = `${baseUrl}/v1/files/${file_key}/component_sets`;
|
|
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
|
|
38
|
-
return { error: 'An error occurred while
|
|
37
|
+
console.error('Error listing component sets:', error);
|
|
38
|
+
return { error: 'An error occurred while listing component sets.' };
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Tool configuration for
|
|
43
|
+
* Tool configuration for listing component sets 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: '
|
|
52
|
-
description: '
|
|
51
|
+
name: 'list_component_sets',
|
|
52
|
+
description: 'List all component sets published 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
|
|
58
|
+
description: 'The key of the Figma file to retrieve component sets from.'
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
61
|
required: ['file_key']
|
|
@@ -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
|
|
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
|
|
6
|
-
* @returns {Promise<Object>} - The
|
|
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
|
|
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
|
|
37
|
-
return { error: 'An error occurred while
|
|
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
|
|
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: '
|
|
51
|
-
description: '
|
|
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
|
|
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
|
|
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
|
|
6
|
-
* @returns {Promise<Object>} - The list of projects
|
|
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
|
|
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
|
|
37
|
-
return { error: 'An error occurred while
|
|
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
|
|
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: '
|
|
51
|
-
description: '
|
|
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
|
|
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
|
|
2
|
+
* Function to list published libraries in Figma.
|
|
3
3
|
*
|
|
4
|
-
* @returns {Promise<
|
|
4
|
+
* @returns {Promise<Array>} - A promise that resolves to an array of published libraries.
|
|
5
5
|
*/
|
|
6
6
|
const executeFunction = async () => {
|
|
7
|
-
const
|
|
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(
|
|
18
|
-
method: '
|
|
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
|
|
33
|
-
return { error: 'An error occurred while
|
|
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
|
|
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: '
|
|
47
|
-
description: '
|
|
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
|
|
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
|
|
6
|
-
* @returns {Promise<Object>} - The
|
|
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
|
|
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}/
|
|
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
|
|
38
|
-
return { error: 'An error occurred while
|
|
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
|
|
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: '
|
|
52
|
-
description: '
|
|
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
|
|
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
|
|
2
|
+
* Function to list variables for a specific Figma file.
|
|
3
3
|
*
|
|
4
|
-
* @param {Object} args - Arguments for the
|
|
5
|
-
* @param {string} args.file_key - The
|
|
6
|
-
* @returns {Promise<Object>} - The
|
|
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
|
|
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
|
|
13
|
-
const url = `${baseUrl}/files/${file_key}/
|
|
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
|
|
37
|
-
return { error: 'An error occurred while
|
|
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
|
|
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: '
|
|
51
|
-
description: '
|
|
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
|
|
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 };
|