Skip to main content
Glama

iTerm2 Worktree MCP Server

worktree_mcp_server.cpython-313.pyc9.45 kB
� Frph�#���SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJrJ r J r J r "SS5r Sr \S:Xa\R"\ "55 gg)�N)�Any�Dict�List�Optionalc���\rSrSrSrS\S\S\\\44SjrS\S\S\\\44Sjr S\S\S\\\44S jr S \ \\ 4S\ \\ 44S jr S \ \\ 4S\ \\ 44S jrSrg)�WorktreeMCPServer� c �J�SSSSSS.SSS.SSS.SS S.S ./S QS .S ./Ulg) N�createWorktreez@Create a git worktree with iTerm automation to start development�object�stringz.The feature name to work on (e.g., 'add-auth'))�type� descriptionz1The branch name to use (e.g., 'feature/add-auth')z=The worktree folder name (e.g., 'project-name-feat-add-auth')zDescription of the task to do)� feature_name� branch_name�worktree_folderr)r� properties�required)�namer� inputSchema��tools)�selfs �2/Users/tim/repos/iterm2-mcp/worktree_mcp_server.py�__init__�WorktreeMCPServer.__init__s_��)�a�$�%-�+[�)� %-�+^�(� %-�+j�,� %-�+J�(�#�$!b�) � � �� �rr�returnc�"�[R"/SQSSSS9n[R"SSSU/SSSS9nURR 5(aSS US 34$[ R R[ R"55n[ R RXB5n[ R RU5(aSS US 34$g![Ra gf=f![Ra g f=f)z#Validate if worktree can be created)�gitz rev-parsez --git-dirT��capture_output�text�check)FzNot in a git repositoryr �branchz--listFzBranch 'z' already exists)Fz Failed to check if branch existszFolder 'z$' already exists in parent directory)TzValidation passed) � subprocess�run�CalledProcessError�stdout�strip�os�path�dirname�getcwd�join�exists)rrr�result� parent_dir� worktree_paths r�validate_worktree_creation�,WorktreeMCPServer.validate_worktree_creation,s�� 4��^�^�1�#��� �F� =��^�^���(�K�8�#��� �F� �}�}�"�"�$�$���� �5E�F�F�F�%� �W�W�_�_�R�Y�Y�[�1� ���� � �Z�A� � �7�7�>�>�-� (� (��H�_�$5�5Y�Z�Z� Z�(��-�,�,� 4�3� 4���,�,� =�<� =�s#�C�AC7�C4�3C4�7D� Dc�P�[RR[R"55n[RR X25n[ R "SSSSX/SSSS9nSSU34$![ RanSS UR34sS nA$S nAff=f) zCreate the git worktreer �worktree�addz-bTr!z!Worktree created successfully at FzFailed to create worktree: N) r+r,r-r.r/r&r'r(�stderr)rrrr2r3r1�es r�create_worktree�!WorktreeMCPServer.create_worktreeNs��� C����������5�J��G�G�L�L��E�M� �^�^�� �E�4��L�#��� �F��<�]�O�L�L� L���,�,� C��7����z�B�B� B�� C�s�A3A6�6B%� B �B%� B%rc���# �[RR5IShv�N n[R"U5IShv�N nURnU(dgUR 5IShv�N nUR n[R"S5IShv�N [RR[R"55n[RRX�5n URSU S35IShv�N URS5IShv�N [R"S5IShv�N URS5IShv�N URU5IShv�N [R"S5IShv�N URS5IShv�N g GN�GNmGNDGNN�N�N~NgNPN4N![an S S [!U 534sSn A $Sn A ff=f7f) zSAutomate iTerm to open new tab, cd to worktree, start claude, and paste descriptionN)FzNo current iTerm window found�zcd 'z' zclaude � g�?)Tz'iTerm automation completed successfullyFziTerm automation failed: )�iterm2� Connection� async_create� async_get_app�current_window�async_create_tab�current_session�asyncio�sleepr+r,r-r.r/�async_send_text� Exception�str) rrr� connection�app�window�new_tab�sessionr2r3r:s r�automate_iterm� WorktreeMCPServer.automate_iterm`s����% ?�%�0�0�=�=�?�?�J��,�,�Z�8�8�C��'�'�F��=�#�3�3�5�5�G��-�-�G��-�-��"� "� "����������5�J��G�G�L�L��E�M��)�)�D���s�*C�D� D� D��)�)�*�5� 5� 5��-�-��"� "� "��)�)�$�/� /� /��)�)�+�6� 6� 6��-�-��$� $� $��)�)�$�/� /� /�B�A@�8�6� #� E� 6� #� /� 7� %� /��� ?��5�c�!�f�X�>�>� >�� ?�s�G.�!G�F-�G�F0�G�G.�G�/F3�0)G�F6�A-G�F9�G� F;�!G�>F=�?G�F?�G�0G�1G�G�G�'G�(G�,G.�-G�0G�3G�6G�9G�;G�=G�?G�G�G�G� G+�G&� G+�!G.�&G+�+G.� argumentsc��B# �USnUSnUSnUSnURX45upgU(d SSSU3S./0$URX45up�U(d SSS U 3S./0$URXE5IS hv�N up�U(d SSS U 3S./0$SSS US US3S./0$N'7f)z#Handle the createWorktree tool callrrrr�contentr#u❌ Validation failed: �rr#u❌ Nu2✅ Worktree created but iTerm automation failed: u#✅ Successfully created worktree 'z' with branch 'z!' and started development session)r4r;rQ) rrSrrrr�valid�validation_msg�success� worktree_msg� iterm_msgs r�handle_create_worktree�(WorktreeMCPServer.handle_create_worktree�s(��� ��0� �� �.� �#�$5�6��� �.� �!%� ?� ?� � ]����� &�"9�.�9I� J���� �!%� 4� 4�[� R����� &�"&�|�n� 5���� �$(�#6�#6��#T�T����� &�"T�U^�T_� `���� � �"�A�/�AR�Ra�bm�an�oP�Q��� � �U�s�A3B�5B�6(B�messagec��*# �URS5S:XaSUR0$URS5S:Xa;USSnUSSnUS:XaURU5IS hv�N $S S U3S ./S S.$S SURS53S ./S S.$N+7f)zHandle incoming MCP messages�methodz tools/listrz tools/call�paramsrrSr Nr#zUnknown tool: rVT�rU�isErrorzUnknown method: )�getrr\)rr^� tool_namerSs r�handle_message� WorktreeMCPServer.handle_message�s���� �;�;�x� �L� 0������ ��[�[�� "�l� 2���)�&�1�I���)�+�6�I��,�,�!�8�8��C�C�C� %+�&4�Y�K�$@�� � $���!'�"2�7�;�;�x�3H�2I� J���  �� �D�s�A#B�%B�&,BrN)�__name__� __module__� __qualname__�__firstlineno__rrK�tuple�boolr4r;rQrrr\rf�__static_attributes__�rrrr s��� �< )�c� )�C� )�TY�Z^�`c�Zc�Td� )�DC�3�C��C��t�UX�y�IY�C�$'?�C�'?�c�'?�e�TX�Z]�T]�N^�'?�R2 �d�3��8�n�2 ��c�SV�h��2 �h�D��c��N��t�C��H�~�rrc��# �[5n[5nU(dg[R"U5nUR U5IShv�N n[ [R "U55 [RR5 M�NC![a g[a\nSS[U53S./SS.n[ [R "U55 [RR5 SnANpSnAff=f7f)zMain MCP server loopTNr#zServer error: rVrb) r�input�json�loadsrf�print�dumps�sysr)�flush�EOFErrorrJrK)�server�liner^�responser:�error_responses r�mainr}�s���� � �F� � ��7�D����j�j��&�G�#�2�2�7�;�;�H� �$�*�*�X�&� '� �J�J� � � � �<�� � � �� �!'�"0��Q��� 9���  ��N� �$�*�*�^�,� -� �J�J� � � � �� �sX� D�B�D�*B� B� AB� D�B� D�D� D�&AC=�8D�=D�D�__main__)rGrrr+r&rv�timer@�typingrrrrrr}rhr'rorr�<module>r�sR��� � �� � � �,�,�O�O�b�@ �z�� �K�K����r

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/timoconnellaus/claude-code-iterm-worktree-mcp'

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