Skip to main content
Glama
ssinha3

Time MCP Server

by ssinha3
server.cpython-313.pyc9.43 kB
� ��]hF��L�SSKJrJr SSKJr SSKrSSKJr SSKJr SSK J r SSK J r SSK Jr SS KJrJrJrJr SS KJr SS KJr "S S \\5r"SS\5r"SS\5r"SS\5rSS\S-S\4SjjrS\S\4Sjr"SS5rSS\S-SS4Sjjr g)�)�datetime� timedelta)�EnumN)�Sequence)�ZoneInfo)�get_localzone_name)�Server)� stdio_server)�Tool� TextContent� ImageContent�EmbeddedResource)�McpError)� BaseModelc��\rSrSrSrSrSrg)� TimeTools��get_current_time� convert_time�N)�__name__� __module__� __qualname__�__firstlineno__�GET_CURRENT_TIME� CONVERT_TIME�__static_attributes__r��B/Users/shayan.sinha/servers/src/time/src/mcp_server_time/server.pyrrs ��)��!�Lrrc�4�\rSrSr%\\S'\\S'\\S'Srg)� TimeResult��timezoner�is_dstrN)rrrr�str�__annotations__�boolrrrrr!r!s���M��M� �Lrr!c�4�\rSrSr%\\S'\\S'\\S'Srg)�TimeConversionResult��source�target�time_differencerN)rrrrr!r&r%rrrrr)r)s�� �� ���rr)c�:�\rSrSr%\\S'\\S'\\\S'Srg)�TimeConversionInput�"� source_tz�time�target_tz_listrN)rrrrr%r&�listrrrrr/r/"s���N� �I���I�rr/�local_tz_override�returnc�l�U(a [U5$[5nUb [U5$[S5e)Nz3Could not determine local timezone - tzinfo is None)rrr)r5� local_tznames r� get_local_tzr9(s8����)�*�*�&�'�L���� �%�%� �H� I�Ir� timezone_namec�l�[U5$![an[S[U535eSnAff=f)NzInvalid timezone: )r� Exceptionrr%)r:�es r� get_zoneinfor>3s9��6�� �&�&�� �6��+�C��F�8�4�5�5��6�s� � 3�.�3c�@�\rSrSrS\S\4SjrS\S\S\S\4SjrS r g ) � TimeServer�:r:r6c��[U5n[R"U5n[UUR SS9[ UR 55S9$)z&Get current time in specified timezone�seconds��timespec�r#rr$)r>r�nowr!� isoformatr'�dst)�selfr:r#� current_times rr�TimeServer.get_current_time;sL��� �.���|�|�H�-� ��"�!�+�+�Y�+�?�� �(�(�*�+� � rr1�time_str� target_tzc �t�[U5n[U5n[R"US5R5n[R "U5n[UR URURURURUS9nURU5n UR5=(d [5n U R5=(d [5n X�- R5S- n U R5(aU SS3n O%U SR!S5R!S 5S-n [#[%UUR'S S 9[)UR+55S 9[%UU R'S S 9[)U R+55S 9U S 9$![a [ S5ef=f)�Convert time between timezonesz%H:%Mz4Invalid time format. Expected HH:MM [24-hour format])�tzinfoiz+.1f�hz+.2f�0�.rCrDrF)r+r,r-)r>r�strptimer2� ValueErrorrG�year�month�day�hour�minute� astimezone� utcoffsetr� total_seconds� is_integer�rstripr)r!rHr'rI)rJr1rMrN�source_timezone�target_timezone� parsed_timerG� source_time� target_time� source_offset� target_offset�hours_difference� time_diff_strs rr�TimeServer.convert_timeFs���'�y�1��&�y�1�� U�"�+�+�H�g�>�C�C�E�K��l�l�?�+��� �H�H� �I�I� �G�G� � � � � � �"�  � �"�,�,�_�=� �#�-�-�/�>�9�;� �#�-�-�/�>�9�;� �)�9�H�H�J�T�Q�� � &� &� (� (�/��5�Q�7�M� 0��5�=�=�c�B�I�I�#�N�QT�T�M�#��"�$�.�.� �.�B��K�O�O�-�.�� �"�$�.�.� �.�B��K�O�O�-�.�� *�  � ��1� U��S�T� T� U�s �%F!�!F7rN) rrrrr%r!rr)rrrrrr@r@:s:��  �c�  �j�  �- ��- �(+�- �8;�- � �- rr@�local_timezonec ��^^# �[S5n[5m[[U55mUR 5S[ [ 4U4Sjj5nUR5S[S[S[[[-[-4U4Sjj5nUR5n[5IShv�N upVURXVU5IShv�N SSS5IShv�N gN1NN !,IShv�N (df  g=f7f)Nzmcp-timer6c ���># �[[RRSSSSSTS3S.0S/S.S 9[[RRS SSS TS 3S.SS S.SSTS3S.S./SQS.S 9/$7f)zList available time tools.z(Get current time in a specific timezones�objectr#�stringzEIANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'z8' as local timezone if no timezone provided by the user.)�type� description)rp� properties�required)�namerq� inputSchemarPzLSource IANA timezone name (e.g., 'America/New_York', 'Europe/London'). Use 'z?' as local timezone if no source timezone provided by the user.z)Time to convert in 24-hour format (HH:MM)zNTarget IANA timezone name (e.g., 'Asia/Tokyo', 'America/San_Francisco'). Use 'z?' as local timezone if no target timezone provided by the user.�rar2rb)r rr�valuer)�local_tzs�r� list_tools�serve.<locals>.list_tools{s����� ��/�/�5�5�F�$�"�$,�-r�s{�r|�}u�,v�%�#� ",� � � � ��+�+�1�1�<�$�%-�-y�{C�zD�DC�,D�,� %-�+V�!� %-�-{�}E�|F�FE�,F�,� #�!O�!� �% �% �s�A0A3rt� argumentsc��@>^# �U=[RR:Xa6 TRS5nU(d [ S5eTR U5nOn[R R:XaB[U4SjS55(d [ S5eTRTSTSTS5nO[ S U35e[S [R"UR5S S 9S 9/$![an[ S[U535eSnAff=f7f)z#Handle tool calls for time queries.r#z#Missing required argument: timezonec3�.># �UH nUT;v� M g7f�Nr)�.0�kr{s �r� <genexpr>�+serve.<locals>.call_tool.<locals>.<genexpr>�s�����!O�A��Y��!O�s�rvzMissing required argumentsrar2rbzUnknown tool: �text�)�indent)rpr�z(Error processing mcp-server-time query: N)rrrw�getrVrr�allrr �json�dumps� model_dumpr<r%)rtr{r#�resultr=� time_servers ` �r� call_tool�serve.<locals>.call_tool�s����  R��5�Y�/�/�5�5�(�}�}�Z�8�H�#�(�)N�O�O�(�9�9�(�C�F��+�+�1�1���!O����)�)E�F�F�(�5�5�!�"3�4�!�&�)�!�"3�4��F� �$�~�d�V�%<�=�=���d�j�j��9J�9J�9L�UV�.W�X�� ��� R��G��A��x�P�Q� Q�� R�s)�D�C.C5�4D�5 D�?D�D�D)r r@r%r9ryr4r r��dictrr r r�create_initialization_optionsr �run) rk�serverryr��options� read_stream� write_streamrxr�s @@r�server�vs����� �J� �F��,�K��<��/�0�H� ����' �d�4�j�' ��' �R ����!R��!R�"�!R� �+� �,�/?�?� @�!R��!R�F�2�2�4�G��~�~�!<�+��j�j��G�<�<�<��~�~�<��~�~�~�sZ�B2D�6C(�7D�:C.�C*�C.� D�"C,�#D�*C.�,D�.D�4C7 �5 D�Dr~)!rr�enumrr��typingr�zoneinfor�tzlocalr� mcp.serverr �mcp.server.stdior � mcp.typesr r r r�mcp.shared.exceptionsr�pydanticrr%rr!r)r/r9r>r@r�rrr�<module>r�s���(�� ���&��)�G�G�*��"��T�"� ��� �9�� �)�� J�C�$�J�J�(�J�6��6��6�9 �9 �xU=��d� �U=�d�U=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/ssinha3/mcp-time-server'

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