Skip to main content
Glama
server.cpython-313.pyc24.1 kB
� \u�g\���SrSSKrSSKrSSKrSSKJr SSKJrJrJ r SSK J r SSK J r SSKJr SSKJr SS KJrJrJrJr \R."\R0S S 9 \R2"S 5r\ "5 \R6"S 5r\R6"S5r\(d\"S5e\"\S9R>r \RCS5 \ "S5r&S.Sjr'\&RQSS9S/S\%S\%S\)S\\%S\*S\ 4 Sjj5r+\&RQSS9S0S\%S\%S\*S\\%S\*S\ 4 S jj5r,\&RQS!S9S"\%S#\%S$\%S\4S%j5r-\&RQS&S9S1S'\%S\%S(\\%S\4S)jj5r.\&RQS*S9S\4S+j5r/S,r0\1S-:Xa\0"5 gg!\"a0r#\RIS\%"\#535 \"S\%"\#535eSr#C#ff=f)2u Whissle MCP Server ⚠️ IMPORTANT: This server provides access to Whissle API endpoints which may incur costs. Each tool that makes an API call is marked with a cost warning. Please follow these guidelines: 1. Only use tools when explicitly requested by the user 2. For tools that process audio, consider the length of the audio as it affects costs 3. Some operations like translation or summarization may have higher costs Tools without cost warnings in their description are free to use as they only read existing data. �N)�Path)�List�Optional�Dict)� load_dotenv)�FastMCP)� TextContent)� WhissleClient)� make_error�make_output_path�make_output_file�handle_input_filez4%(asctime)s - %(name)s - %(levelname)s - %(message)s)�level�format� whissle_mcp�WHISSLE_AUTH_TOKEN�WHISSLE_MCP_BASE_PATHz3WHISSLE_AUTH_TOKEN environment variable is required)� auth_tokenz'Whissle client initialized successfullyz%Failed to initialize Whissle client: �Whisslec ���[RSUSU35 SU;a�X#:aGSUS--n[RSUSUSUS-S US-S 3 5 [R"U5 g S UR 5;a[ S USU35$[ S USU35$SU;a[ SU35$SU;a[ SU35$SU;dSU;a[ SU35$[ SUSU35$)zKHelper function to handle API errors with retries and better error messageszAPI error during �: �HTTP 500��zHTTP 500 error during z. Retrying in z seconds... (Attempt �/�)Nzuploading filezServer error during z�. The file upload to the Whissle API failed. This could be due to: 1. Temporary server issues 2. File format compatibility issues 3. Network connectivity problems Please try again later or contact Whissle support. Error: zr. This might be a temporary issue with the Whissle API. Please try again later or contact Whissle support. Error: zHTTP 413z2File too large. Please try a smaller file. Error: zHTTP 415z?Unsupported file format. Please use a supported format. Error: zHTTP 401zHTTP 403z:Authentication error. Please check your API token. Error: )�logger�error�info�time�sleep�lowerr )� error_msg�operation_name� retry_count� max_retries� wait_times �F/Users/varunmehta/git/elevenlabs-mcp/whissle_mcp/whissle_mcp/server.py�handle_api_errorr)3s{�� �L�L�$�^�$4�B�y�k�B�C��Y�� � $��k�A�o�.�I� �K�K�0��0@��y�k�Yn�oz�{|�o|�n}�}~�@K�LM�@M�N�NO�P� Q� �J�J�y� !�� �9�?�?�#4�4�!�*�>�*:�;Q� R[�P[� ]���"�*�>�*:�;Q�QZ�P[�]��� �y� ��N�y�k�Z�[�[� �y� ��[�\e�[f�g�h�h� �y� �J�)�$;��V�W`�Va�b�c�c��-�n�-=�R� �{�K�L�L�u�Convert speech to text with a given model and save the output text file to a given directory. Directory is optional, if not provided, the output file will be saved to $HOME/Desktop. ⚠️ COST WARNING: This tool makes an API call to Whissle which may incur costs. Only use when explicitly requested by the user. Args: audio_file_path (str): Path to the audio file to transcribe model_name (str, optional): The name of the ASR model to use. Defaults to "en-NER" timestamps (bool, optional): Whether to include word timestamps boosted_lm_words (List[str], optional): Words to boost in recognition boosted_lm_score (int, optional): Score for boosted words (0-100) output_directory (str, optional): Directory where files should be saved. Defaults to $HOME/Desktop if not provided. Returns: TextContent with the transcription and path to the output file. )� description�audio_file_path� model_name� timestamps�boosted_lm_words�boosted_lm_score�returnc ��[RRU5(d[R SU35 SSU30$[RR U5nUS:Xa[R SU35 SSU30$[RR U5SR5nUS;a [R SU35 SSUS30$S nXWS -S -:�a,[R S US - S S35 SSUS - S SUS30$[RSU35 [RSUS - S S35 [RSU35 S/nSn UGHn Sn Sn X�::dM[RSU SU S-SU S-S35 [RUU UUUS9n U (a�[U S5(a�[RSU 35 U R[U SS5[U S S!5S".n[U S#5(aU RUS#'[U S$5(a U R(aU RUS$'Us $S%n [R S&U 35 GM S*U ;a[R S+U 35 SS,U 30$[R S-U 35 SS.U 30$![ a^n[#U5n[R S'U S(U35 Un [%US)X�5nUbX�:XaSnAGM�SU0sSnAs $U S- n SnAOSnAff=fX�::aGM�GM�![ a;n[R S/[#U535 SS.[#U530sSnA$SnAff=f)0z(Convert speech to text using Whissle API�Audio file not found: rr�Audio file is empty: r�z.wavz.mp3z.oggz.flacz.m4a�Unsupported audio format: �-. Supported formats: wav, mp3, ogg, flac, m4a���File too large: ��.2f� MB�File too large (� MB). Maximum size is � MB.zTranscribing audio file: � File size: � File format: �en-NERNrz%Attempting transcription with model: � (Attempt rr)r,r-r.r/r0� transcriptz%Transcription successful with model: �duration_seconds� language_code�en)rErFrGr.�diarize_outputz*No transcription was returned from the APIz.No transcription returned from API with model �Error with model r� transcriptionrz1All transcription attempts failed with HTTP 500: z�Server error during transcription. This might be a temporary issue with the Whissle API. Please try again later or contact Whissle support. Error: z#All transcription attempts failed: zFailed to transcribe audio: z'Unexpected error during transcription: )�os�path�existsrr�getsize�splitextr"r�client�speech_to_text�hasattrrE�getattrr.rI� Exception�strr))r,r-r.r/r0� file_size�file_ext� max_size_mb� models_to_try� last_error� try_modelr%r&�response�result� api_errorr#� error_result�es r(rRrRXs���*[B��w�w�~�~�o�.�.� �L�L�1�/�1B�C� D��5�o�5F�G�H� H��G�G�O�O�O�4� � ��>� �L�L�0��0A�B� C��4�_�4E�F�G� G��7�7�#�#�O�4�Q�7�=�=�?�� �D� D� �L�L�5�h�Z�@� A��9�(��Cp�q�r� r�� � �T�)�D�0� 0� �L�L�+�I��,C�C�+H��L� M��/� �Y�0G��/L�Lb�cn�bo�os�t�u� u� � � �/��/@�A�B�� � �k�)�y�"9�#�!>�c�B�C�� � �m�H�:�.�/�"� � �� �&�I��K��K��,�*%��K�K�"G� �{�R\�]h�ij�]j�\k�kl�mx�yz�mz�l{�{|� }�~�%�4�4�(7�#,�#-�)9�)9� 5� �H� �G�H�l�$C�$C�� � �&K�I�;�$W�X�+3�*=�*=�07��BT�VW�0X�-4�X��PT�-U�"�� #�8�\�:�:�3;�3F�3F�F�<�0�"�8�-=�>�>�8�CZ�CZ�7?�7N�7N�F�#3�4�%� �%Q� �� � �'U�V_�U`�%a�b��E'�b �� #� �L�L�L�Z�L�Y� Z�� s�t~�s�@�A� A� �L�L�>�z�l�K� L��;�J�<�H�I� I��'!� %� #�I��I��L�L�#4�Y�K�r�)��!M�N�!*�J�#3�I��P[�#i�L�#�/�&�5�!�$+�\�#:�:��1�$�K�� %��?�,�,��h �B�� � �>�s�1�v�h�G�H��7��A��x�@�A�A��B�s��AL<�AL<� AL<�8L<�AL<�<C$K� L<�#K�=)L<�'L<� L.�=L)� L<�L)�L.�L<�L)�$L<�)L.�.L<�9L<�< N�0M<�6N�<Nu�Convert speech to text with speaker diarization and save the output text file to a given directory. Directory is optional, if not provided, the output file will be saved to $HOME/Desktop. ⚠️ COST WARNING: This tool makes an API call to Whissle which may incur costs. Only use when explicitly requested by the user. Args: audio_file_path (str): Path to the audio file to transcribe model_name (str, optional): The name of the ASR model to use. Defaults to "en-NER" max_speakers (int, optional): Maximum number of speakers to identify boosted_lm_words (List[str], optional): Words to boost in recognition boosted_lm_score (int, optional): Score for boosted words (0-100) output_directory (str, optional): Directory where files should be saved. Defaults to $HOME/Desktop if not provided. Returns: TextContent with the diarized transcription and path to the output file. � max_speakersc ���[RRU5(d[R SU35 SSU30$[RR U5nUS:Xa[R SU35 SSU30$[RR U5SR5nUS;a [R SU35 SSUS30$S nXWS -S -:�a,[R S US - S S35 SSUS - S SUS30$[RSU35 [RSUS - S S35 [RSU35 S/nSn UH�n Sn Sn X�::dM[RSU SU S-SU S-S35 [RUU UUUS9n U (a�[U S5(aU R(an[RSU 35 [U SS 5[U S!S5[U S"S#5U RS$.n[U S%5(aU RUS%'Us $S&n [R S'U 35 M� S+U ;a[R S,U 35 SS-U 30$[R S.U 35 SS/U 30$![a^n[!U5n[R S(U S)U35 Un [#US*X�5nUbX�:XaSnAGM�SU0sSnAs $U S- n SnAOSnAff=fX�::aGM�GM�![a;n[R S0[!U535 SS/[!U530sSnA$SnAff=f)1z Diarize speech using Whissle APIr3rrr4rr5r6r7r8r9r:r;r<r=r>r?r@zDiarizing audio file: rArBrCNrz#Attempting diarization with model: rDrr)r,r-rbr/r0rIz#Diarization successful with model: rE�rFrGrH)rErFrGrIr.z3No diarized transcription was returned from the APIz7No diarized transcription returned from API with model rJr� diarizationrz/All diarization attempts failed with HTTP 500: z�Server error during diarization. This might be a temporary issue with the Whissle API. Please try again later or contact Whissle support. Error: z!All diarization attempts failed: zFailed to diarize speech: z%Unexpected error during diarization: )rLrMrNrrrOrPr"rrQ� diarize_sttrSrIrTr.rUrVr))r,r-rbr/r0rWrXrYrZr[r\r%r&r]r^r_r#r`ras r(�diarize_speechrg�s���*Y@��w�w�~�~�o�.�.� �L�L�1�/�1B�C� D��5�o�5F�G�H� H��G�G�O�O�O�4� � ��>� �L�L�0��0A�B� C��4�_�4E�F�G� G��7�7�#�#�O�4�Q�7�=�=�?�� �D� D� �L�L�5�h�Z�@� A��9�(��Cp�q�r� r�� � �T�)�D�0� 0� �L�L�+�I��,C�C�+H��L� M��/� �Y�0G��/L�Lb�cn�bo�os�t�u� u� � � �,�_�,=�>�?�� � �k�)�y�"9�#�!>�c�B�C�� � �m�H�:�.�/�"� � �� �&�I��K��K��,�(%��K�K�"E�i�[�PZ�[f�gh�[h�Zi�ij�kv�wx�kx�jy�yz� {�|�%�1�1�(7�#,�%1�)9�)9� 2� �H� �G�H�6F�$G�$G�H�Lc�Lc�� � �&I�)��$U�V�+2�(�L�"�*M�07��BT�VW�0X�-4�X��PT�-U�.6�.E�.E� "��#�8�\�:�:�3;�3F�3F�F�<�0�%� �%Z� �� � �'^�_h�^i�%j�k��A'�^ �� #� �L�L�J�:�,�W� X�� q�r|�q}�~�� � �L�L�<�Z�L�I� J��9�*��F�G� G��'!� %� #�I��I��L�L�#4�Y�K�r�)��!M�N�!*�J�#3�I�}�k�#g�L�#�/�&�5�!�$+�\�#:�:��1�$�K�� %��;�,�,��d �@�� � �<�S��V�H�E�F��5�c�!�f�X�>�?�?��@�s��AL&�AL&� AL&�8L&�AL&�;CJ0� L&�J0�((L&�L&�0 L�:=L�7L&�>L�L�L&� L�L&�L�L&�#L&�& M+�00M&� M+�&M+u�Translate text from one language to another. ⚠️ COST WARNING: This tool makes an API call to Whissle which may incur costs. Only use when explicitly requested by the user. Args: text (str): The text to translate source_language (str): Source language code (e.g., "en" for English) target_language (str): Target language code (e.g., "es" for Spanish) Returns: TextContent with the translated text. �text�source_language�target_languagec���U(d [RS5 [S5$[RSUSU35 [RS[ U5S35 SnSnX4::a�[RS US -S US -S 35 [ R UUUS 9nU(a=UR(a,[RS5 [SSUR3S9$[RS5 [S5$[RSUS -S35 [SUS -S35$![aIn[U5n[RSU35 [USX45nUbUsSnA$US - nSnAOSnAff=fX4::aGM(N�![aBn [RS[U 535 [S[U 535sSn A $Sn A ff=f)Nz#Empty text provided for translationzText is requiredzTranslating text from z to � Text length: � charactersrrz Attempting translation (Attempt rrr)rhrirjzTranslation successfulrhz Translation: ��typerhz(No translation was returned from the APIzTranslation error: � translationz&All translation attempts failed after � attemptszFailed to translate text after z%Unexpected error during translation: zFailed to translate text: ) rrr r�lenrQ�machine_translation�translated_textr rUrVr)) rhrirjr%r&r]r_r#r`ras r(�translate_textru<s���&.A�� �L�L�>� ?��0�1� 1� � � �,�_�,=�T�/�AR�S�T�� � �m�C��I�;�k�:�;�� �� ��(� !�� � �>�{�1�}�o�Q�{�[\�}�o�]^�_�`�!�5�5��$3�$3�6��� �� 8� 8��K�K� 8�9�&�#�-�h�.F�.F�-G�H��� �L�L�!K�L�%�&P�Q�Q� � � �=�k�!�m�_�I�V�W��;�K��M�?�)�T�U�U��� !�� �N� �� � �2�9�+�>�?� 0� �=�+�c� ��+�'�'��q� � �� !��%�(��@ �A�� � �<�S��V�H�E�F��6�s�1�v�h�?�@�@��A�sf�&F�AF�0A:D9�+D9� -F�9 F �4F�7F �8F�=F�F�F � F� G$�"7G�G$�G$u�Summarize text using an LLM model. ⚠️ COST WARNING: This tool makes an API call to Whissle which may incur costs. Only use when explicitly requested by the user. Args: content (str): The text to summarize model_name (str, optional): The LLM model to use. Defaults to "openai" instruction (str, optional): Specific instructions for summarization Returns: TextContent with the summary. �content� instructionc���U(d [RS5 [S5$[RSU35 [RS[ U5S35 SnSnX4::a�[RSUS -S US -S 35 [ R UUUS 9nU(a=UR(a,[RS 5 [SSUR3S9$[RS5 [S5$[RSUS -S35 [SUS -S35$![aIn[U5n[RSU35 [USX45nUbUsSnA$US - nSnAOSnAff=fX4::aGM(N�![aBn [RS[U 535 [S[U 535sSn A $Sn A ff=f)Nz(Empty content provided for summarizationzContent is requiredzSummarizing text using model: rlrmrrz"Attempting summarization (Attempt rrr)rvr-rwzSummarization successfulrhz Summary: rnz$No summary was returned from the APIzSummarization error: � summarizationz(All summarization attempts failed after rqzFailed to summarize text after z'Unexpected error during summarization: zFailed to summarize text: ) rrr rrrrQ�llm_text_summarizerr]r rUrVr)) rvr-rwr%r&r]r_r#r`ras r(�summarize_textr{�s���&.A�� �L�L�C� D��3�4� 4� � � �4�Z�L�A�B�� � �m�C��L�>��=�>�� �� ��(� !�� � �@��Q���q�Q\�]^�Q^�P_�_`�a�b�!�5�5�#�)� +�6��� �� 1� 1��K�K� :�;�&�#�)�(�*;�*;�)<�=��� �L�L�!G�H�%�&L�M�M� � � �?� �A� ��i�X�Y��;�K��M�?�)�T�U�U��� !�� �N� �� � �4�Y�K�@�A� 0� �?�K�e� ��+�'�'��q� � �� !��%�(��@ �A�� � �>�s�1�v�h�G�H��6�s�1�v�h�?�@�@��A�sf�&F�AF�-A:D6�(D6�-F�6 F �4F�4F �5F�:F�?F�F � F� G!�7G�G!�G!z5List all available ASR models and their capabilities.c���[RS5 SnSnX::a�[RSUS-SUS-S35 [R5nU(d [R S5 [ S5$[ U[5(aI[S U55(aS RS U55nO9S RS U55nO [R S 5 [ S 5$[RS5 [SSU3S9$[R SUS-S35 [ SUS-S35$![aIn[U5n[R SU35 [USX5nUbUsSnA$US- nSnAOSnAff=fX::aGM�N�![aBn[R S[U535 [ S[U535sSnA$SnAff=f)zcList all available ASR models. Returns: TextContent with a formatted list of available models z Fetching available ASR models...rrz#Attempting to list models (Attempt rrrz$No models were returned from the APIc3�B# �UHn[U[5v� M g7f)N)� isinstancerV��.0�models r(� <genexpr>�"list_asr_models.<locals>.<genexpr>�s���F�v�e�:�e�S�1�1�v�s�� c3�,# �UH nSU3v� M g7f)�Model: N�rs r(r�r��s���.U�f�U����/@�f�s�c3�\# �UH"nSURSURS3v� M$ g7f)r�z Description: r�N)�namer+rs r(r�r��s2���/�)/��&�e�j�j�\���AR�AR�@S�SU�V�)/�s�*,z#Unexpected response format from APIz!Successfully retrieved ASR modelsrhzAvailable ASR Models: rnzError listing models: zlisting modelsNz)All attempts to list models failed after rqz Failed to list ASR models after z%Unexpected error listing ASR models: zFailed to list ASR models: )rrrQ�list_asr_modelsrr r~�list�all�joinr rUrVr))r%r&�models� model_listr_r#r`ras r(r�r��s���3B�� � �6�7�� �� ��(�% !�� � �A�+�a�-��PQ�R]�^_�R_�Q`�`a�b�c��/�/�1����L�L�!G�H�%�&L�M�M��f�d�+�+��F�v�F�F�F�%)�Y�Y�.U�f�.U�%U� �&*�Y�Y�/�)/�/�&� � �L�L�!F�G�%�&K�L�L�� � �?�@�"��4�Z�L�A��� � � �@��Q���y�Y�Z��<�[��]�O�9�U�V�V��� !�� �N� �� � �5�i�[�A�B� 0� �;K�[�f� ��+�'�'��q� � �� !��;�(��V �B�� � �<�S��V�H�E�F��7��A��x�@�A�A��B�sf�F+�AE �>A=E �<!E �-F+� F�4F� F� F+�F�F+�F�F+�+ G7�57G2�,G7�2G7c�D�[S5 [R5 g)NzStarting Whissle MCP server)�print�mcp�runr�r*r(�mainr�s�� � '�(���G�G�Ir*�__main__)rr)rCTN�P)rCrNr�)�openaiN)2�__doc__rLr �logging�pathlibr�typingrrr�dotenvr�mcp.server.fastmcpr� mcp.typesr �whissler �whissle_mcp.utilsr r r r� basicConfig�INFO� getLoggerr�getenvr� base_path� ValueError� sync_clientrQrrUrarrVr�r)�tool�bool�intrRrgrur{r�r��__name__r�r*r(�<module>r�s��� � � ���'�'��&�!�!������'�,�,�/e�f� � � �=� )�� � � �Y�Y�+� ,� � �I�I�-� .� �� �J� K�K�G� �j� 1� =� =�F� �K�K�9�:� �i���"M�J���� ��&]B�C�]B�S�]B�QU�]B�pt�ux�py�]B�UX�]B�bf�]B�'�&]B�@���� ��&[@�C�[@�S�[@�SV�[@�nr�sv�nw�[@�SV�[@�`d�[@�'�&[@�|��� � � �3A� �3A��3A��3A�� 3A� �3A�l��� � � � �!%�3A� �3A��3A��#��3A�� 3A� �3A�l���G� ��9B��9B��9B�x�  �z���F���{�G� �L�L�8��Q���A�B� �<�S��V�H�E� F�F��G�s�+!F�G�+G � G

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/WhissleAI/whissle-mcp'

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