Skip to main content
Glama

OpenSCAD MCP Server

by jhacksman
stl_exporter.cpython-312.pyc6.45 kB
� H��g����ddlZddlZddlZddlZddlmZmZmZmZddl m Z eje �Z Gd�d�Zy)�N)�Dict�Any�Optional�Tuple)� STLValidatorc ���eZdZdZdefd�Zddedeeeefde ee eeffd�Z ddedeeeefd eeeefdeeeffd �Z d ed eeefdefd �Z d ed edefd�Zy)� STLExporterzA Handles STL file export and validation for 3D printing. � output_dirc��||_||_tjj |d�|_tj |j d��y)z� Initialize the STL exporter. Args: openscad_wrapper: Instance of OpenSCADWrapper for generating STL files output_dir: Directory to store output files �stlT)�exist_okN)�openscad_wrapperr �os�path�join�stl_dir�makedirs)�selfrr s �:/home/ubuntu/openscad-mcp-server/src/utils/stl_exporter.py�__init__zSTLExporter.__init__s=��!1���$����w�w�|�|�J��6�� � � � �D�L�L�4�0�N� scad_file� parameters�returnc��� |jj||�}tj|�\}}|sctj d|���tj |�\}}|rtj|�\}}ntjd|���|||fS#t$r9}tjdt|����ddt|�fcYd}~Sd}~wwxYw)a Export a SCAD file to STL format. Args: scad_file: Path to the SCAD file parameters: Optional parameters to override in the SCAD file Returns: Tuple of (stl_file_path, is_valid, error_message) zSTL validation failed: zSTL repair failed: zError exporting STL: �FN) r� generate_stlr� validate_stl�logger�warning� repair_stl�error� Exception�str) rrr�stl_file�is_validr"�repair_success� repair_error�es r� export_stlzSTLExporter.export_stls��� %��,�,�9�9�)�Z�P�H�+�7�7��A�O�H�e�����!8���@�A�0<�/F�/F�x�/P�,�� �!�&2�&?�&?��&I�O�H�e��L�L�#6�|�n�!E�F��X�u�,� ,��� %� �L�L�0��Q���9� :��u�c�!�f�$� $�� %�s�BB � C"�).C�C"�C"�metadatac��|j||�\}}}d}|r|r|j||�}|r1tjj |�j d�dnt tj��}||||||d�S)ai Export a SCAD file to STL format and include metadata. Args: scad_file: Path to the SCAD file parameters: Optional parameters to override in the SCAD file metadata: Optional metadata to include with the STL file Returns: Dictionary with STL file information N�.r)�model_idr%r&r"� metadata_filer+) r*�_create_metadata_filerr�basename�splitr$�uuid�uuid4) rrrr+r%r&r"r/r.s r�export_stl_with_metadataz$STLExporter.export_stl_with_metadataAs���%)�O�O�I�z�$J�!��(�E�� � �� �6�6�x��J�M�AJ�2�7�7�#�#�I�.�4�4�S�9�!�<�s�SW�S]�S]�S_�O`��!� � ��*� �  � rr%c�b�tjj|�d�d�} ddl}t |d�5}|j ||d��ddd�t jd|���|S#1swY�#xYw#t$r+}t jdt|����Yd}~y d}~wwxYw) z'Create a metadata file for an STL file.rz.jsonN�w�)�indentzCreated metadata file: zError creating metadata file: r) rr�splitext�json�open�dumpr�infor#r"r$)rr%r+r/r;�fr)s rr0z!STLExporter._create_metadata_filebs����7�7�+�+�H�5�a�8�9��?� � � ��m�S�)�Q�� � �(�A�a� �0�*� �K�K�1�-��A� B� � � *�)�� � � �L�L�9�#�a�&��B� C��� �s.�A:�A.� !A:�.A7�3A:�: B.�!B)�)B.� destinationc��� tjj|�std|����tjj |�r?tjj |�}tjj ||�}tj||�tjd|���|S#t$r+}tjdt|����Yd}~yd}~wwxYw)z� Copy an STL file to a specified location. Args: stl_file: Path to the STL file destination: Destination path or directory Returns: Path to the copied STL file zSTL file not found: zCopied STL file to: zError copying STL file: Nr)rr�exists�FileNotFoundError�isdirr1r�shutil�copy2rr>r#r"r$)rr%r@�filenamer)s r�copy_stl_to_locationz STLExporter.copy_stl_to_locationqs��� ��7�7�>�>�(�+�'�*>�x�j�(I�J�J��w�w�}�}�[�)��7�7�+�+�H�5�� �g�g�l�l�;��A� � �L�L��;� /� �K�K�.�{�m�<� =�� ��� � �L�L�3�C��F�8�<� =��� �s�B:B=�= C1�!C,�,C1)N)NN)�__name__� __module__� __qualname__�__doc__r$rrrrr�boolr*r5r0rH�rrr r s���� 1�S� 1� %�C� %�X�d�3��8�n�5M� %�Y^�_b�dh�jr�sv�jw�_w�Yx� %�D_c�DH� �#� �8�D�QT�VY�QY�N�C[� �)1�$�s�C�x�.�)A� �MQ�RU�WZ�RZ�^� �B �c� �T�#�s�(�^� �PS� ��S��s��s�rr )r�loggingr3rE�typingrrrr�src.utils.stl_validatorr� getLoggerrIrr rNrr�<module>rSs8�� �� � �-�-�0� �� � �8� $��A�Ar

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/jhacksman/OpenSCAD-MCP-Server'

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