figma-mcp-server 2.0.1 → 2.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 (38) hide show
  1. package/LICENSE +1 -2
  2. package/README.md +12 -9
  3. package/bun.lock +77 -33
  4. package/commands/tools.ts +87 -0
  5. package/{index.js → index.ts} +2 -2
  6. package/lib/tools.ts +38 -0
  7. package/mcpServer.ts +186 -0
  8. package/package.json +19 -10
  9. package/preview.webp +0 -0
  10. package/tools/figma/figma-api/{create-dev-resources-for-a-file.js → create-dev-resources-for-a-file.ts} +9 -11
  11. package/tools/figma/figma-api/{create-variable-collections-for-a-file.js → create-variable-collections-for-a-file.ts} +7 -9
  12. package/tools/figma/figma-api/{get-a-published-component-by-key.js → get-a-published-component-by-key.ts} +7 -9
  13. package/tools/figma/figma-api/{get-a-published-component-set-by-key.js → get-a-published-component-set-by-key.ts} +7 -9
  14. package/tools/figma/figma-api/{get-a-published-library-by-id.js → get-a-published-library-by-id.ts} +7 -9
  15. package/tools/figma/figma-api/{get-a-published-style-by-key.js → get-a-published-style-by-key.ts} +7 -9
  16. package/tools/figma/figma-api/{get-current-user.js → get-current-user.ts} +6 -8
  17. package/tools/figma/figma-api/{get-file-nodes.js → get-file-nodes.ts} +7 -9
  18. package/tools/figma/figma-api/{get-file-version-history.js → get-file-version-history.ts} +7 -9
  19. package/tools/figma/figma-api/{get-file.js → get-file.ts} +7 -9
  20. package/tools/figma/figma-api/{get-image-fills.js → get-image-fills.ts} +7 -9
  21. package/tools/figma/figma-api/{get-library-action-analytics.js → get-library-action-analytics.ts} +7 -9
  22. package/tools/figma/figma-api/{get-library-usage-analytics.js → get-library-usage-analytics.ts} +7 -9
  23. package/tools/figma/figma-api/{list-comments-on-a-file.js → list-comments-on-a-file.ts} +8 -10
  24. package/tools/figma/figma-api/{list-component-sets-in-a-file.js → list-component-sets-in-a-file.ts} +7 -9
  25. package/tools/figma/figma-api/{list-components-in-a-file.js → list-components-in-a-file.ts} +7 -9
  26. package/tools/figma/figma-api/{list-dev-resources-for-a-file.js → list-dev-resources-for-a-file.ts} +7 -9
  27. package/tools/figma/figma-api/{list-files-in-a-project.js → list-files-in-a-project.ts} +7 -9
  28. package/tools/figma/figma-api/{list-projects-in-a-team.js → list-projects-in-a-team.ts} +7 -9
  29. package/tools/figma/figma-api/{list-published-libraries.js → list-published-libraries.ts} +6 -8
  30. package/tools/figma/figma-api/{list-styles-in-a-file.js → list-styles-in-a-file.ts} +7 -9
  31. package/tools/figma/figma-api/{list-variables-for-a-file.js → list-variables-for-a-file.ts} +7 -9
  32. package/tools/figma/figma-api/{post-a-comment-to-a-file.js → post-a-comment-to-a-file.ts} +7 -9
  33. package/tools/paths.ts +25 -0
  34. package/tsconfig.json +28 -0
  35. package/commands/tools.js +0 -65
  36. package/lib/tools.js +0 -12
  37. package/mcpServer.js +0 -170
  38. package/tools/paths.js +0 -25
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ library_file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ library_file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/analytics/libraries/${library_file_key}/usages`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ library_file_key }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
23
  return data;
23
- } catch (error) {
24
- console.error('Error retrieving library usage analytics:', error);
25
- return { error: 'An error occurred while retrieving library usage analytics.' };
26
- }
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/files/${file_key}/comments`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ file_key }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
- return data.comments || [];
23
- } catch (error) {
24
- console.error('Error listing comments on the Figma file:', error);
25
- return { error: 'An error occurred while listing comments.' };
26
- }
23
+ return (data as any).comments || [];
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
 
5
6
  try {
6
7
  const url = `${baseUrl}/v1/files/${file_key}/component_sets`;
@@ -15,19 +16,16 @@ const executeFunction = async ({ file_key }) => {
15
16
  });
16
17
 
17
18
  if (!response.ok) {
18
- const errorData = await response.json();
19
- throw new Error(errorData);
19
+ const errorData = await response.json() as any;
20
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
20
21
  }
21
22
 
22
23
  const data = await response.json();
23
24
  return data;
24
- } catch (error) {
25
- console.error('Error listing component sets:', error);
26
- return { error: 'An error occurred while listing component sets.' };
27
- }
25
+ } catch (error) { throw error; }
28
26
  };
29
27
 
30
- const apiTool = {
28
+ const apiTool: ApiTool = {
31
29
  function: executeFunction,
32
30
  definition: {
33
31
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/files/${file_key}/components`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ file_key }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
23
  return data;
23
- } catch (error) {
24
- console.error('Error listing components in file:', error);
25
- return { error: 'An error occurred while listing components in the file.' };
26
- }
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/files/${file_key}/dev_resources`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ file_key }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
23
  return data;
23
- } catch (error) {
24
- console.error('Error listing development resources:', error);
25
- return { error: 'An error occurred while listing development resources.' };
26
- }
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ project_id }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ project_id }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
 
5
6
  try {
6
7
  const url = `${baseUrl}/v1/projects/${project_id}/files`;
@@ -15,19 +16,16 @@ const executeFunction = async ({ project_id }) => {
15
16
  });
16
17
 
17
18
  if (!response.ok) {
18
- const errorData = await response.json();
19
- throw new Error(errorData);
19
+ const errorData = await response.json() as any;
20
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
20
21
  }
21
22
 
22
23
  const data = await response.json();
23
24
  return data;
24
- } catch (error) {
25
- console.error('Error listing files in project:', error);
26
- return { error: 'An error occurred while listing files in the project.' };
27
- }
25
+ } catch (error) { throw error; }
28
26
  };
29
27
 
30
- const apiTool = {
28
+ const apiTool: ApiTool = {
31
29
  function: executeFunction,
32
30
  definition: {
33
31
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ team_id }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ team_id }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/teams/${team_id}/projects`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ team_id }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
23
  return data;
23
- } catch (error) {
24
- console.error('Error listing projects:', error);
25
- return { error: 'An error occurred while listing projects.' };
26
- }
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
1
2
  const executeFunction = async () => {
2
3
  const baseUrl = 'https://api.figma.com/v1/libraries/published';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const headers = {
6
7
  'X-Figma-Token': token
@@ -12,19 +13,16 @@ const executeFunction = async () => {
12
13
  });
13
14
 
14
15
  if (!response.ok) {
15
- const errorData = await response.json();
16
- throw new Error(errorData);
16
+ const errorData = await response.json() as any;
17
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
17
18
  }
18
19
 
19
20
  const data = await response.json();
20
21
  return data;
21
- } catch (error) {
22
- console.error('Error listing published libraries:', error);
23
- return { error: 'An error occurred while listing published libraries.' };
24
- }
22
+ } catch (error) { throw error; }
25
23
  };
26
24
 
27
- const apiTool = {
25
+ const apiTool: ApiTool = {
28
26
  function: executeFunction,
29
27
  definition: {
30
28
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
 
5
6
  try {
6
7
  const url = `${baseUrl}/v1/files/${file_key}/styles`;
@@ -15,19 +16,16 @@ const executeFunction = async ({ file_key }) => {
15
16
  });
16
17
 
17
18
  if (!response.ok) {
18
- const errorData = await response.json();
19
- throw new Error(errorData);
19
+ const errorData = await response.json() as any;
20
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
20
21
  }
21
22
 
22
23
  const data = await response.json();
23
24
  return data;
24
- } catch (error) {
25
- console.error('Error listing styles in the Figma file:', error);
26
- return { error: 'An error occurred while listing styles in the Figma file.' };
27
- }
25
+ } catch (error) { throw error; }
28
26
  };
29
27
 
30
- const apiTool = {
28
+ const apiTool: ApiTool = {
31
29
  function: executeFunction,
32
30
  definition: {
33
31
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
  try {
5
6
  const url = `${baseUrl}/v1/files/${file_key}/variables`;
6
7
 
@@ -14,19 +15,16 @@ const executeFunction = async ({ file_key }) => {
14
15
  });
15
16
 
16
17
  if (!response.ok) {
17
- const errorData = await response.json();
18
- throw new Error(errorData);
18
+ const errorData = await response.json() as any;
19
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
19
20
  }
20
21
 
21
22
  const data = await response.json();
22
23
  return data;
23
- } catch (error) {
24
- console.error('Error listing variables for the file:', error);
25
- return { error: 'An error occurred while listing variables for the file.' };
26
- }
24
+ } catch (error) { throw error; }
27
25
  };
28
26
 
29
- const apiTool = {
27
+ const apiTool: ApiTool = {
30
28
  function: executeFunction,
31
29
  definition: {
32
30
  type: 'function',
@@ -1,6 +1,7 @@
1
- const executeFunction = async ({ file_key, message, client_meta = {} }) => {
1
+ import { ApiTool, getFigmaToken } from "../../../lib/tools.ts";
2
+ const executeFunction = async ({ file_key, message, client_meta = {} }: any) => {
2
3
  const baseUrl = 'https://api.figma.com';
3
- const token = process.env.FIGMA_API_KEY;
4
+ const token = getFigmaToken();
4
5
 
5
6
  try {
6
7
  const url = `${baseUrl}/v1/files/${file_key}/comments`;
@@ -22,19 +23,16 @@ const executeFunction = async ({ file_key, message, client_meta = {} }) => {
22
23
  });
23
24
 
24
25
  if (!response.ok) {
25
- const errorData = await response.json();
26
- throw new Error(errorData);
26
+ const errorData = await response.json() as any;
27
+ throw new Error(`Figma API Error: ${errorData.message || response.statusText}`);
27
28
  }
28
29
 
29
30
  const data = await response.json();
30
31
  return data;
31
- } catch (error) {
32
- console.error('Error posting comment to Figma file:', error);
33
- return { error: 'An error occurred while posting the comment.' };
34
- }
32
+ } catch (error) { throw error; }
35
33
  };
36
34
 
37
- const apiTool = {
35
+ const apiTool: ApiTool = {
38
36
  function: executeFunction,
39
37
  definition: {
40
38
  type: 'function',
package/tools/paths.ts ADDED
@@ -0,0 +1,25 @@
1
+ export const toolPaths = [
2
+ 'figma/figma-api/list-published-libraries.ts',
3
+ 'figma/figma-api/get-a-published-component-by-key.ts',
4
+ 'figma/figma-api/get-file.ts',
5
+ 'figma/figma-api/list-component-sets-in-a-file.ts',
6
+ 'figma/figma-api/list-dev-resources-for-a-file.ts',
7
+ 'figma/figma-api/get-a-published-library-by-id.ts',
8
+ 'figma/figma-api/list-components-in-a-file.ts',
9
+ 'figma/figma-api/get-library-usage-analytics.ts',
10
+ 'figma/figma-api/list-comments-on-a-file.ts',
11
+ 'figma/figma-api/get-image-fills.ts',
12
+ 'figma/figma-api/list-variables-for-a-file.ts',
13
+ 'figma/figma-api/get-file-version-history.ts',
14
+ 'figma/figma-api/list-files-in-a-project.ts',
15
+ 'figma/figma-api/get-library-action-analytics.ts',
16
+ 'figma/figma-api/create-variable-collections-for-a-file.ts',
17
+ 'figma/figma-api/get-file-nodes.ts',
18
+ 'figma/figma-api/get-a-published-style-by-key.ts',
19
+ 'figma/figma-api/get-current-user.ts',
20
+ 'figma/figma-api/create-dev-resources-for-a-file.ts',
21
+ 'figma/figma-api/list-styles-in-a-file.ts',
22
+ 'figma/figma-api/list-projects-in-a-team.ts',
23
+ 'figma/figma-api/get-a-published-component-set-by-key.ts',
24
+ 'figma/figma-api/post-a-comment-to-a-file.ts'
25
+ ];
package/tsconfig.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": [
4
+ "ESNext"
5
+ ],
6
+ "module": "esnext",
7
+ "target": "esnext",
8
+ "moduleResolution": "bundler",
9
+ "moduleDetection": "force",
10
+ "allowImportingTsExtensions": true,
11
+ "noEmit": true,
12
+ "composite": true,
13
+ "strict": true,
14
+ "downlevelIteration": true,
15
+ "skipLibCheck": true,
16
+ "jsx": "react-jsx",
17
+ "allowSyntheticDefaultImports": true,
18
+ "forceConsistentCasingInFileNames": true,
19
+ "allowJs": true,
20
+ "types": [
21
+ "bun-types" // Bun types
22
+ ]
23
+ },
24
+ "include": [
25
+ "**/*.ts",
26
+ "**/*.js"
27
+ ]
28
+ }
package/commands/tools.js DELETED
@@ -1,65 +0,0 @@
1
- import { discoverTools } from "../lib/tools.js";
2
-
3
- export function registerToolsCommand(program) {
4
- program
5
- .command("tools")
6
- .description("List all available API tools")
7
- .action(async () => {
8
- const tools = await discoverTools();
9
- if (tools.length === 0) {
10
- console.log("No tools found. Tools should be organized as:");
11
- console.log("tools/workspace/collection/request.js\n");
12
- return;
13
- }
14
-
15
- console.log("\nAvailable Tools:\n");
16
-
17
- // Group tools by workspace/collection
18
- const groupedTools = tools.reduce((acc, tool) => {
19
- // Extract workspace and collection from path
20
- const parts = tool.path.split("/");
21
- const workspace = parts[1] || "Unknown Workspace";
22
- const collection = parts[2] || "Unknown Collection";
23
-
24
- if (!acc[workspace]) acc[workspace] = {};
25
- if (!acc[workspace][collection]) acc[workspace][collection] = [];
26
-
27
- acc[workspace][collection].push(tool);
28
- return acc;
29
- }, {});
30
-
31
- // Print tools in a hierarchical structure
32
- for (const [workspace, collections] of Object.entries(groupedTools)) {
33
- console.log(`Workspace: ${workspace}`);
34
- for (const [collection, tools] of Object.entries(collections)) {
35
- console.log(` Collection: ${collection}`);
36
- tools.forEach(
37
- ({
38
- definition: {
39
- function: { name, description, parameters },
40
- },
41
- }) => {
42
- console.log(` ${name}`);
43
- console.log(
44
- ` Description: ${description || "No description provided"}`
45
- );
46
- if (parameters?.properties) {
47
- console.log(" Parameters:");
48
- Object.entries(parameters.properties).forEach(
49
- ([name, details]) => {
50
- console.log(
51
- ` - ${name}: ${
52
- details.description || "No description"
53
- }`
54
- );
55
- }
56
- );
57
- }
58
- console.log("");
59
- }
60
- );
61
- }
62
- console.log("");
63
- }
64
- });
65
- }
package/lib/tools.js DELETED
@@ -1,12 +0,0 @@
1
- import { toolPaths } from "../tools/paths.js";
2
-
3
- export async function discoverTools() {
4
- const toolPromises = toolPaths.map(async (file) => {
5
- const module = await import(`../tools/${file}`);
6
- return {
7
- ...module.apiTool,
8
- path: file,
9
- };
10
- });
11
- return Promise.all(toolPromises);
12
- }