Skip to main content
Glama
script_tools.cpython-312.pyc10.1 kB
� ���g-��8�ddlmZmZddlmZddlmZdefd�Zy)�)�FastMCP�Context)�List)�get_unity_connection�mcpc�J�|j�ddtdtdtdtfd��}|j� ddtdtdtd td td td td tdtfd��}|j� ddtdtd tdtdtdtf d��}|j�ddtdtdtfd��}|j� ddtdtdtdtdtf d��}y)z6Register all script-related tools with the MCP server.�ctx� script_path�require_exists�returnc�:� |jd�sd|��}td|���t�jd||d��}|j dd�r|j dd�S|j d d �S#t $r}d t |���cYd }~Sd }~wwxYw) ayView the contents of a Unity script file. Args: ctx: The MCP context script_path: Path to the script file relative to the Assets folder require_exists: Whether to raise an error if the file doesn't exist (default: True) Returns: str: The contents of the script file or error message �Assets/z+ViewScript - Using normalized script path: � VIEW_SCRIPT)r r �existsT�contentzScript contents not available�messagezScript not foundzError viewing script: N)� startswith�printr� send_command�get� Exception�str)r r r �response�es ��C:\1_Sagyo\VRchat\Project\IshouJidouChouseiToul\Library\PackageCache\com.zundamonnovrchat.unity-mcp-ollama@994ecdcda9\Python\tools\script_tools.py� view_scriptz*register_script_tools.<locals>.view_scripts��� 5��)�)�)�4� '� �}�5� � �?� �}�M� N�,�-�:�:�=�*�"0�K��H� �|�|�H�d�+��|�|�I�/N�O�O��|�|�I�/A�B�B��� 5�+�C��F�8�4� 4�� 5�s$�A$A9�'A9�9 B� B�B�BN� script_name� script_type� namespace�template� script_folder� overwriterc��� t�}|re|jd�r|} nd|��} | jd�r| �|�d�} n| �d|�d�} td|���td| ���td| ���nd|�d�} td| ���|||||d �} |r|| d <|r|| d <|j d | �} | j d d�S#t $r} dt| ���cYd} ~ Sd} ~ wwxYw)a�Create a new Unity script file. Args: ctx: The MCP context script_name: Name of the script (without .cs extension) script_type: Type of script (e.g., MonoBehaviour, ScriptableObject) namespace: Optional namespace for the script template: Optional custom template to use script_folder: Optional folder path within Assets to create the script overwrite: Whether to overwrite if script already exists (default: False) content: Optional custom content for the script Returns: str: Success message or error details r�/�.cszCreateScript - Folder: z"CreateScript - Normalized folder: zCreateScript - Script path: zAssets/Scripts/z*CreateScript - Using default script path: )rrrr r"r!r� CREATE_SCRIPTrzScript created successfullyzError creating script: N)rr�endswithrrrrr)r rrrr r!r"r�unity�normalized_folderr �paramsrrs r� create_scriptz,register_script_tools.<locals>.create_script)s:��40 6�(�*�E��!�+�+�I�6�(5�%�*1�-��(A�%�%�-�-�c�2�%6�$7� �}�C�"H�K�%6�$7�q�� �S�"I�K��/� ��?�@��:�;L�:M�N�O��4�[�M�B�C�!0� �}�C�@� ��B�;�-�P�Q� +�*�&�$�&� �F��*7���'��$+��y�!��)�)�/�6�B�H��<�<� �+H�I� I��� 6�,�S��V�H�5� 5�� 6�s�B>C� C"� C�C"�C"�create_if_missing�create_folder_if_missingc�� t�}|jd�sd|��}td|���|jd�d}|j d�s |dz }|�d�}|r1||dd�}|rd|d<|j d |�}|j d d �S|j d ||d ��}|j d d �S#t$r} d t| ���cYd} ~ Sd} ~ wwxYw)aUpdate the contents of an existing Unity script. Args: ctx: The MCP context script_path: Path to the script file relative to the Assets folder content: New content for the script create_if_missing: Whether to create the script if it doesn't exist (default: False) create_folder_if_missing: Whether to create the parent directory if it doesn't exist (default: False) Returns: str: Success message or error details rzUpdateScript - Original path: r$�����r%T)r rr,r-� UPDATE_SCRIPTrzScript updated successfully)r rzError updating script: N) rrr�splitr'rrrr) r r rr,r-r(rr*rrs r� update_scriptz,register_script_tools.<locals>.update_scriptus��() 6�(�*�E��)�)�)�4� '� �}�5� � �2�;�-�@� A�&�+�+�C�0��4�K��'�'��.��u�$� �!,� �S�1� � �$/�&�)-���,�9=�F�5�6�!�-�-�o�v�F���|�|�I�/L�M�M�!�-�-�o�#.�&�@��� �|�|�I�/L�M�M��� 6�,�S��V�H�5� 5�� 6�s$�BB9�&B9�9 C� C�C�C� folder_pathc��� t�jdd|i�}|jdg�}|sydj|�S#t$r}dt |���cYd}~Sd}~wwxYw)a List all script files in a specified folder. Args: ctx: The MCP context folder_path: Path to the folder to search (default: Assets) Returns: str: List of script files or error message � LIST_SCRIPTSr3�scriptsz(No scripts found in the specified folder� zError listing scripts: N)rrr�joinrr)r r3rr6rs r� list_scriptsz+register_script_tools.<locals>.list_scripts�so�� 6�+�-�:�:�>��{�L��H��l�l�9�b�1�G��A��9�9�W�%� %��� 6�,�S��V�H�5� 5�� 6�s"�0A�A� A%� A �A%� A%� object_namec��� t�}|jdd|i�}|jdg�}|sd|�d�S|j�j d�s|�d�}|j d�d}|�F|j d �sd |��}|j |�s|j d�r|�|��}n|�d|��}|jd d|i�}|jdd �} |jd g�} | D]!} | jd�| k(s�d| �d|�d�cS||d�} |r|| d<|jd| �} | jdd�S#t$r}dt|���cYd }~Sd }~wwxYw)a�Attach a script component to a GameObject. Args: ctx: The MCP context object_name: Name of the target GameObject in the scene script_name: Name of the script to attach (with or without .cs extension) script_path: Optional full path to the script (if not in the default Scripts folder) Returns: str: Success message or error details �FIND_OBJECTS_BY_NAME�name�objectsz GameObject 'z' not found in the scene.r%r$r/Nr�GET_OBJECT_PROPERTIES�� components�typezScript 'z' is already attached to 'z'.)r:rr � ATTACH_SCRIPTrzScript attached successfullyzError attaching script: ) rrr�lowerr'r1r�replacerr)r r:rr r(�object_responser>�script_basename� object_props�script_class_namerA� componentr*rrs r� attach_scriptz,register_script_tools.<locals>.attach_script�s���$; 7�(�*�E�$�0�0�1G�� �J��O�&�)�)�)�R�8�G��%�k�]�2K�L�L��$�$�&�/�/��6�!,� �S�1� �*�/�/��4�R�8�O��&�"�-�-�i�8�$+�K�=�"9�K�#�+�+�O�<�"�+�+�C�0�)4� �o�5F�&G� �)4� �Q��6G�&H� �!�-�-�.E�� �H��L� !0� 7� 7��r� B� �&�)�)�,��;�J�'� ��=�=��(�,=�=�%�&7�%8�8R�S^�R_�_a�b�b�(� +�.��F� �(3��}�%��)�)�/�6�B�H��<�<� �+I�J� J��� 7�-�c�!�f�X�6� 6�� 7�s/�7E�CE� E�0E� E)� E$�E)�$E))T)� MonoBehaviourNNNFN)FF)�Assets)N)�toolrr�bool)rrr+r2r9rKs r�register_script_toolsrPs��� �X�X�Z�5��5�s�5�D�5�TW�5��5�@ �X�X�Z�+���!���I6� �I6��I6��I6�� I6� � I6� � I6��I6��I6� �I6��I6�V �X�X�Z� #(�).� <6� �<6��<6��<6� � <6� #'� <6� � <6��<6�| �X�X�Z�6�'�6��6�3�6��6�, �X�X�Z�  � L7� �L7��L7��L7�� L7� � L7��L7�N)�mcp.server.fastmcprr�typingr�unity_connectionrrP�rQr�<module>rVs��/��1�S7�w�S7rQ

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