Skip to main content
Glama

figma-mcp

main.cpython-313.pyc8.05 kB
� ���g���~�SSKrSSKrSSKrSSKrSSKJr SSKJr SSKrSSK J r SSK J r Sr \S:Xa\ "5 gg)�N)�Path)�transform_figma_json)� load_dotenv)�FastMCPc��^^^^ �[5 [S5n[R"SS9nUR S[ SS9 UR 5nUR=(d [R"S5mT(d![S5 [R"S 5 SS [ S [4U4S jjjmS mS [ S[ 4U4Sjjm UR5S [ S[[ 4U4Sjj5nUR5S [ S[ S[ 4U 4Sjj5nUR5S [ S[[ 4UU4Sjj5n[S5 UR#5 g)z"Entry point for the figma-mcp CLI.�figmazFigma MCP Python Server)� descriptionz--figma-api-keyz6Figma API token to use instead of environment variable)�type�help�FIGMA_API_TOKENzlError: Figma API token not provided. Please set FIGMA_API_TOKEN environment variable or use --figma-api-key.��file_key� download_filec�4>�ST0nSU3n[R"X2S9nURS:waSSUR30$UR5nU(a/[ US3S5n[R "XVS S 9 SSS5 U$U$!,(df  U$=f) N� X-Figma-Token�https://api.figma.com/v1/files/��headers���errorzFailed to fetch Figma file: z.json�w�)�indent)�requests�get� status_code�json�open�dump)rrr�url�response� figma_data�fr s ��D/Users/jasonzhou/Documents/GitHub/figma-mcp-python/figma_mcp/main.py�fetch_figma_file�main.<locals>.fetch_figma_file(s����"�O�4��/��z�:���<�<��5�� � � �3� &��;�H�<P�<P�;Q�R�S� S��]�]�_� � ��� �%�(�#�.�!�� � �*��2�/���z��/�.���s �&B� Bc�>^^�/mUU4SjmSU;a T"US5 T$)Nc �6>�SU;a�URS/5H{nSU;ajURS5(aTTRURS5URSS5URS5URSS5S.5 T"U5 M} gg) N�children�transitionNodeID�id�name�Unnamed�transitionDurationr)� sourceNodeID�sourceNodeName� targetNodeID� interaction)r�append)�node�child� connections�traverse_nodess ��r$r7�Cmain.<locals>.extract_prototype_connections.<locals>.traverse_nodes;s�����T�!�!�X�X�j�"�5�E�)�U�2�u�y�y�AS�7T�7T�#�*�*�,1�I�I�d�O�.3�i�i�� �.J�,1�I�I�6H�,I�+0�9�9�5I�1�+M� ,�� #�5�)�6�"��document�)r"r6r7s @@r$�extract_prototype_connections�+main.<locals>.extract_prototype_connections8s*���� � *� �� #� �:�j�1� 2��r9�node_idsc�>�ST0nSUSU3n[R"X2S9nURS:waSSUR30$UR5$)Nrrz /nodes?ids=rrrzFailed to fetch Figma nodes: )rrrr)rr>rr r!r s �r$�fetch_figma_nodes�main.<locals>.fetch_figma_nodesMsa���"�O�4��/��z��X�J�O���<�<��5�� � � �3� &��<�X�=Q�=Q�<R�S�T� T��}�}��r9�returnc ��>�T"U5nSU;aSUS0/$/nURS05R5H:up4URUURSS5URSS5S.5 M< U$)z�Get components available in a Figma file Args: file_key (str): The file key found in the shared Figma URL Returns: list[dict]: List of components found in the Figma file r� componentsr,zUnnamed Componentr �)r+r,r )r�itemsr3)rr"rD� component_id�component_datar%s �r$�get_components�main.<locals>.get_componentsXs����&�h�/� � �j� ��j��1�2�3� 3�� �,6�N�N�<��,L�,R�,R�,T� (�L� � � �"�&�*�*�6�3F�G�-�1�1�-��D�� �-U��r9�node_idc�,>^�SU;aSU;aURSS5nT"X5nSU;aSUS0$U4SjmURS05R5H4up4URS5(dMT"USU5nU(dM2Us $ 0$)a8Get a specific node from a Figma file Args: file_key (str): The file key found in the shared Figma URL, e.g. if url is https://www.figma.com/proto/do4pJqHwNwH1nBrrscu6Ld/Untitled?page-id=0%3A1&node-id=0-3&viewport=361%2C361%2C0.08&t=9SVttILbgMlPWuL0-1&scaling=min-zoom&content-scaling=fixed&starting-point-node-id=0%3A3, then the file key is do4pJqHwNwH1nBrrscu6Ld node_id (str): The ID of the node to retrieve, has to be in format x:x, e.g. in url it will be like 0-3, but it should be 0:3 Returns: dict: The node data if found, empty dict if not found �-�:rc�,>�[U[5(aMURS5U:Xa [U5$UR 5Hup#T"X15nU(dMUs $ g[U[ 5(aUHnT"XQ5nU(dMUs $ g)Nr+)� isinstance�dictrrrF�list)�data� target_id�key�value�result�item�find_node_by_ids �r$rY�/main.<locals>.get_node.<locals>.find_node_by_id�s�����$��%�%��8�8�D�>�Y�.�/��5�5�"&�*�*�,�J�C�,�U�>�F��v�%� �#/�� �D�$�'�'� �D�,�T�=�F��v�%� �!� r9�nodesr:)�replacerrF)rrKr!�node_key� node_datar4rYr@s @�r$�get_node�main.<locals>.get_nodeps���� �'�>�c��0��o�o�c�3�/�G�$�X�7�� �h� ��X�g�.�/� /� �&$,�<�<���#<�#B�#B�#D� �H��}�}�Z�(�(�&�y��'<�g�F���4��K� $E� � r9c�D>�T"U5nSU;aSUS0/$T"U5nU$)a�Get workflows available in a Figma file Args: file_key (str): The file key found in the shared Figma URL, e.g. if url is https://www.figma.com/proto/do4pJqHwNwH1nBrrscu6Ld/Untitled?page-id=0%3A1&node-id=0-3&viewport=361%2C361%2C0.08&t=9SVttILbgMlPWuL0-1&scaling=min-zoom&content-scaling=fixed&starting-point-node-id=0%3A3, then the file key is do4pJqHwNwH1nBrrscu6Ld Returns: list[dict]: List of workflow connections found in the Figma file rr;)rr"r6r<r%s ��r$� get_workflow�main.<locals>.get_workflow�s:���&�h�/� � �j� ��j��1�2�3� 3�3�J�?� ��r9zStarting Figma MCP server...N)F)rr�argparse�ArgumentParser� add_argument�str� parse_args� figma_api_key�os�getenv�print�sys�exit�bool�toolrRrQ�start) �mcp�parser�argsrIr_rbr r<r%r@s @@@@r$�mainrusT����M� �'� �C�� $� $�1J� K�F� ���� � E��� � � � �D��(�(�H�B�I�I�6G�,H�O� � �|�}� ���� ��3��t��� �*�C��3�� �X�X�Z�����d�����. �X�X�Z�,�3�,��,��,��,�\ �X�X�Z��s��t�D�z����" � (�*��I�I�Kr9�__main__)rmrjrdr�pathlibr�figma_mcp.clean_noderr�dotenvr�mcp.server.fastmcprru�__name__r;r9r$�<module>r|s=�� � �� ��6���&�b�J �z���F�r9

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JayZeeDesign/figma-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server