Skip to main content
Glama
asset_tools.cpython-312.pyc11.4 kB
� ���g�*��8�ddlmZddlmZmZddlmZdefd�Zy)�)�Optional)�FastMCP�Context)�get_unity_connection�mcpc���|j� ddtdtdtdtdtf d��}|j� ddtdtdtd td td td td tdtfd��}|j� ddtdtdtdtdtf d��}|j�dtdtdtfd��}y)z8Register all asset management tools with the MCP server.�ctx� source_path� target_path� overwrite�returnc��� t�}|rt|t�sdS�rt�t�sdSddl}|jj |�sd|�d�Sdj �jd�dd�}�jd�d}|jd ||xsd d ��jd g�}t�fd �|D��} | r|sd��d�S|jd|�|d��} | jdd�sd| jdd��d|�d��d�S| jdd�S#t$r} dt| ��d|�d��d�cYd} ~ Sd} ~ wwxYw)a�Import an asset (e.g., 3D model, texture) into the Unity project. Args: ctx: The MCP context source_path: Path to the source file on disk target_path: Path where the asset should be imported in the Unity project (relative to Assets folder) overwrite: Whether to overwrite if an asset already exists at the target path (default: False) Returns: str: Success message or error details z9Error importing asset: source_path must be a valid stringz9Error importing asset: target_path must be a valid stringrNz$Error importing asset: Source file 'z' does not exist�/������GET_ASSET_LIST�Assets)�search_pattern�folder�assetsc3�F�K�|]}|jd��k(���y�w��pathN��get)�.0�assetr s ���C:\1_Sagyo\VRchat\Project\IshouJidouChouseiToul\Library\PackageCache\com.zundamonnovrchat.unity-mcp-ollama@994ecdcda9\Python\tools\asset_tools.py� <genexpr>z=register_asset_tools.<locals>.import_asset.<locals>.<genexpr>4s �����]�_�E�u�y�y��0�K�?�_���!zAsset already exists at '�$'. Use overwrite=True to replace it.� IMPORT_ASSET)r r r �successFzError importing asset: �error� Unknown errorz (Source: z , Target: �)�messagezAsset imported successfully) r� isinstance�str�osr�exists�join�split� send_commandr�any� Exception) r r r r �unityr)� target_dir�target_filename�existing_assets� asset_exists�response�es ` r� import_assetz*register_asset_tools.<locals>.import_assets����$) e�(�*�E��j��c�&B�R�S��j��c�&B�R�S� ��7�7�>�>�+�.�=�k�]�JZ�[�[����+�"3�"3�C�"8��"�"=�>�J�)�/�/��4�R�8�O�$�0�0�1A�"1�$�0��D���s�8�R� � � �]�_�]�]�L��I�2�;�-�?c�d�d��)�)�.�*�*�&�;��H� �<�<� �5�1�0����g��1W�0X�Xb�cn�bo�oy�{F�zG�GH�I�I��<�<� �+H�I� I��� e�,�S��V�H�J�{�m�:�Va�Ub�bc�d� d�� e�s;�D.�D.�$D.�A=D.�AD.�D.�. E�7E� E�E� prefab_path� position_x� position_y� position_z� rotation_x� rotation_y� rotation_zc ��� t�}�rt�t�sdS||||||d�} | j�D]#\} } t| tt f�r�d| �d�cSdj �jd�dd�xsd} �jd�d} | j�jd �s | �d �} ��d ��|jd d | | d ��jd g�}t�fd�|D��}|sd��d�S|jd�||||||d��}|jdd�sd|jdd��d��d�Sd|jdd��d�S#t$r}dt|��d��d�cYd}~Sd}~wwxYw)a�Instantiate a prefab into the current scene at a specified location. Args: ctx: The MCP context prefab_path: Path to the prefab asset (relative to Assets folder) position_x: X position in world space (default: 0.0) position_y: Y position in world space (default: 0.0) position_z: Z position in world space (default: 0.0) rotation_x: X rotation in degrees (default: 0.0) rotation_y: Y rotation in degrees (default: 0.0) rotation_z: Z rotation in degrees (default: 0.0) Returns: str: Success message or error details z>Error instantiating prefab: prefab_path must be a valid string)r9r:r;r<r=r>zError instantiating prefab: z must be a numberrNrr�.prefabr�Prefab��typerrrc3�F�K�|]}|jd��k(���y�wrr�rrr8s �rrzCregister_asset_tools.<locals>.instantiate_prefab.<locals>.<genexpr>�� �����\�m�U�� � �&� 1�[� @�m�rzPrefab 'z' not found in the project.�INSTANTIATE_PREFAB)r8r9r:r;r<r=r>r"Fr#r$z (Path: r%z%Prefab instantiated successfully as '� instance_name�unknown�')rr'r(�items�int�floatr+r,�lower�endswithr-rr.r/)r r8r9r:r;r<r=r>r0�position_params� param_name� param_value� prefab_dir� prefab_name� prefab_assets� prefab_existsr5r6s ` r�instantiate_prefabz0register_asset_tools.<locals>.instantiate_prefabEs����47 Q�(�*�E��j��c�&B�W�X�)�(�(�(�(�(� �O�,;�+@�+@�+B�'� �K�!�+��U�|�<�9�*��EV�W�W�,C� ���+�"3�"3�C�"8��"�"=�>�J�(�J�%�+�+�C�0��4�K��$�$�&�/�/� �:�!,� �W�5� �!,� �W�5� �!�.�.�/?� �"-�$�B���s�8�R� � �  �\�m�\�\�M� �!�+��.I�J�J��)�)�*>�*�(�(�(�(�(�(�A��H��<�<� �5�1�5�h�l�l�7�O�6\�5]�]e�fq�er�rs�t�t�:�8�<�<��Yb�;c�:d�de�f� f��� Q�1�#�a�&���+��a�P� P�� Q�s<�E!�5E!�E!�B&E!�AE!� E!�! F�*F�;F�F� object_namec��� t�}|rt|t�sdS�rt�t�sdS|jdd|i�j dg�}|sd|�d�S�j �j d�s��d��d j�jd �d d �xsd }�jd �d }|jd d||d��j dg�}t�fd�|D��} | r|sd��d�S|jd|�|d��} | j dd�sd| j dd��d|�d��d�Sd| j d����S#t$r} dt| ��d|�d��d�cYd } ~ Sd } ~ wwxYw) a�Create a new prefab asset from a GameObject in the scene. Args: ctx: The MCP context object_name: Name of the GameObject in the scene to create prefab from prefab_path: Path where the prefab should be saved (relative to Assets folder) overwrite: Whether to overwrite if a prefab already exists at the path (default: False) Returns: str: Success message or error details z9Error creating prefab: object_name must be a valid stringz9Error creating prefab: prefab_path must be a valid string�FIND_OBJECTS_BY_NAME�name�objects� GameObject '�' not found in the scene.r@rNrrrrArBrc3�F�K�|]}|jd��k(���y�wrrrEs �rrz>register_asset_tools.<locals>.create_prefab.<locals>.<genexpr>�rFrzPrefab already exists at 'r � CREATE_PREFAB)rXr8r r"FzError creating prefab: r#r$z (Object: z, Path: r%zPrefab created successfully at r) rr'r(r-rrNrOr+r,r.r/) r rXr8r r0� found_objectsrSrTrUrVr5r6s ` r� create_prefabz+register_asset_tools.<locals>.create_prefab�s����$/ c�(�*�E��j��c�&B�R�S��j��c�&B�R�S�"�.�.�/E�� �H���s�9�b�!� �!�%�k�]�2K�L�L��$�$�&�/�/� �:�!,� �W�5� ����+�"3�"3�C�"8��"�"=�>�J�(�J�%�+�+�C�0��4�K�!�.�.�/?� �"-�$�B���s�8�R� � �  �\�m�\�\�M��Y�3�K�=�@d�e�e��)�)�/�*�*�&�<��H� �<�<� �5�1�0����g��1W�0X�Xb�cn�bo�ow�yD�xE�EF�G�G�4�X�\�\�&�+�5V�4W�X� X��� c�,�S��V�H�J�{�m�8�T_�S`�`a�b� b�� c�s;�E�E�+E�!B"E�AE�E� F�&F�:F�Fc�`� t�}|jdd|i�jdg�}|sd|�d�S|jdd|i�}|jdd�}|sd|�d �S|jd d |i�}|jd d �S#t$r}dt |���cYd}~Sd}~wwxYw)a Apply changes made to a prefab instance back to the original prefab asset. Args: ctx: The MCP context object_name: Name of the prefab instance in the scene Returns: str: Success message or error details rZr[r\r]r^�GET_OBJECT_PROPERTIES�isPrefabInstanceFz' is not a prefab instance.� APPLY_PREFABrXr&z#Prefab changes applied successfullyzError applying prefab changes: N)rr-rr/r()r rXr0ra� object_props�is_prefab_instancer5r6s r� apply_prefabz*register_asset_tools.<locals>.apply_prefab�s��� >�(�*�E�"�.�.�/E�� �H���s�9�b�!� �!�%�k�]�2K�L�L�!�-�-�.E�� �H��L� ".�!1�!1�2D�e�!L� �%�%�k�]�2M�N�N��)�)�.��{�;��H��<�<� �+P�Q� Q��� >�4�S��V�H�=� =�� >�s(�5B �-B �&%B � B-� B(�"B-�(B-N)F)�rjrjrjrjrj)�toolrr(�boolrM)rr7rWrbris r�register_asset_toolsrms��� �X�X�Z�  � :e� �:e��:e��:e�� :e� � :e��:e�x �X�X�Z� ������PQ� �PQ��PQ��PQ�� PQ� � PQ� � PQ��PQ��PQ� �PQ��PQ�d �X�X�Z�  � @c� �@c��@c��@c�� @c� � @c��@c�D �X�X�Z�'>� �'>��'>� �'>��'>�N)�typingr�mcp.server.fastmcprr�unity_connectionrrm�rnr�<module>rss���/�1�~>�g�~>rn

Latest Blog Posts

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/ZundamonnoVRChatkaisetu/unity-mcp-ollama'

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