MCP Server for Things3

by drjforrest
Verified
� ��gc��<�ddlZddlmZmZmZddlZGd�d�Zy)�N)�List�Dict�Anyc��eZdZdZededefd��Zedeeee ffd��Z edeeee ffd��Z edeeeeffd��Z y) �AppleScriptHandlerz9Handles AppleScript execution for Things3 data retrieval.�script�returnc��� tjdd|gddd��}|jj�S#tj$r}t d|����d}~wwxYw)zA Executes an AppleScript and returns its output. � osascriptz-eT)�check�capture_output�textzFailed to execute AppleScript: N)� subprocess�run�stdout�strip�CalledProcessError� RuntimeError)r�result�es �t/Users/drjforrest/Development/my-custom-MCP-servers/mcp-server-things3/src/mcp_server_things3/applescript_handler.py� run_scriptzAppleScriptHandler.run_scriptsi�� F��^�^��d�F�+��#�� �F� �=�=�&�&�(� (���,�,� F��!@���D�E� E�� F�s�58�A� A�Ac�Z�d}tj|�}tj|�S)zC Retrieves tasks from the Inbox using AppleScript. u? tell application "Things3" -- Get inbox tasks set inboxTasks to to dos of list "Inbox" -- Initialize an empty list for JSON set tasksJSON to "[" -- Loop through each task and collect details repeat with t in inboxTasks set taskTitle to name of t -- Notes set taskNotes to "" if notes of t is not missing value then set taskNotes to notes of t end if -- Due Date set dueDate to "" if due date of t is not missing value then set dueDate to ((due date of t) as string) end if -- When (Soft Reminder) set whenDate to "" if activation date of t is not missing value then set whenDate to ((activation date of t) as string) end if -- Tags set tagText to "" try set tagList to tag names of t if tagList is not {} then set tagText to tagList as string end if end try -- Construct JSON entry set tasksJSON to tasksJSON & "{\"title\": \"" & taskTitle & "\"," & ¬ "\"notes\": \"" & taskNotes & "\"," & ¬ "\"due_date\": \"" & dueDate & "\"," & ¬ "\"tags\": \"" & tagText & "\"," & ¬ "\"when\": \"" & whenDate & "\"}," end repeat -- Remove trailing comma and close JSON array if length of tasksJSON > 1 then set tasksJSON to text 1 thru -2 of tasksJSON end if set tasksJSON to tasksJSON & "]" return tasksJSON end tell �rr�json�loads�rrs r�get_inbox_tasksz"AppleScriptHandler.get_inbox_taskss+�� 7 ��r$�.�.�v�6���z�z�&�!�!�c�Z�d}tj|�}tj|�S)zI Retrieves today's tasks from Things3 using AppleScript. u� tell application "Things3" -- Get today's tasks set todayTasks to to dos of list "Today" -- Initialize an empty list for JSON set tasksJSON to "[" -- Loop through each task and collect details repeat with t in todayTasks set taskTitle to name of t -- Notes set taskNotes to "" if notes of t is not missing value then set taskNotes to notes of t end if -- Due Date set dueDate to "" if due date of t is not missing value then set dueDate to ((due date of t) as string) end if -- Start Date set startDate to "" try if startDate of t is not missing value then set startDate to ((startDate of t) as string) end if on error set startDate to "" end try -- When (Soft Reminder) set whenDate to "" if activation date of t is not missing value then set whenDate to ((activation date of t) as string) end if -- Tags set tagText to "" try set tagList to tag names of t if tagList is not {} then set tagText to tagList as string end if end try -- Construct JSON entry set tasksJSON to tasksJSON & "{\"title\": \"" & taskTitle & "\"," & ¬ "\"notes\": \"" & taskNotes & "\"," & ¬ "\"due_date\": \"" & dueDate & "\"," & ¬ "\"start_date\": \"" & startDate & "\"," & ¬ "\"tags\": \"" & tagText & "\"," & ¬ "\"when\": \"" & whenDate & "\"}," end repeat -- Remove trailing comma and close JSON array if length of tasksJSON > 1 then set tasksJSON to text 1 thru -2 of tasksJSON end if set tasksJSON to tasksJSON & "]" return tasksJSON end tell rrs r�get_todays_tasksz#AppleScriptHandler.get_todays_tasksYs,�� B ��H$�.�.�v�6���z�z�&�!�!rc�Z�d}tj|�}tj|�S)zH Retrieves all projects from Things3 using AppleScript. a8 tell application "Things3" set projectList to projects set projectJSON to "[" repeat with p in projectList set projectTitle to name of p set projectNotes to "" if notes of p is not missing value then set projectNotes to notes of p end if set projectJSON to projectJSON & "{\"title\": \"" & projectTitle & "\", \"notes\": \"" & projectNotes & "\"}," end repeat if length of projectJSON > 1 then set projectJSON to text 1 thru -2 of projectJSON end if set projectJSON to projectJSON & "]" return projectJSON end tell rrs r� get_projectszAppleScriptHandler.get_projects�s*��  ��0$�.�.�v�6���z�z�&�!�!rN) �__name__� __module__� __qualname__�__doc__� staticmethod�strrrrrrr!r#�rrrrs���C�� F�3� F�3� F�� F��>"�T�$�s�C�x�.�1�>"��>"�@�I"�d�4��S��>�2�I"��I"�V�"�$�t�C��H�~�.�"��"rr)r�typingrrrrrr*rr�<module>r,s���"�"� �~"�~"r