Skip to main content
Glama

Claude MCP Server

by risherb
mcp_integration.cpython-312.pyc6.01 kB
� �Y�g���6�ddlZddlZddlZddlZddlmZmZmZmZm Z ddl m Z m Z ddl Z ddlZddlZdZej"j%dd�Ze dZe Gd�d ��Ze Gd �d ��ZGd �d �ZGd�d�Zdeeefdeeeffd�Zy)�N)�Dict�List�Any�Optional�Literal)� dataclass�asdictzhttps://api.duckduckgo.com�CLAUDE_API_KEY��claudec�X�eZdZUeed<dZeed<dZeed<dZeed<de ee ffd�Z y ) � DDGRequest�q�json�format��no_html� skip_disambig�returnc��t|�S�N)r )�selfs �>C:\Users\risha\OneDrive\Desktop\MCP_Project\mcp_integration.py�to_dictzDDGRequest.to_dicts ���d�|��N) �__name__� __module__� __qualname__�str�__annotations__rr�intrrrr�rrrrs9�� �F��F�C���G�S���M�3����c�3�h��rrc�,�eZdZUeed<eed<eed<y)� WebResult�title�url� descriptionN)rrrrr r"rrr$r$s�� �J� �H��rr$c�8�eZdZefdefd�Zddededeefd�Z y) � MCPClient�endpointc��||_yr)r*)rr*s r�__init__zMCPClient.__init__!s �� �� r�query�countrc ���t|��} tj|j|j ���}|j �|j �}g}|jd�rM|jt|jdd�|jdd�|jdd����|S#t$r}t|�gcYd}~Sd}~wwxYw)N)r)�params�Abstract�Headingr � AbstractURL)r%r&r') r�requests�getr*r�raise_for_statusr�appendr$� Exception�print)rr-r.�request�response�data�results�es r�searchzMCPClient.search$s����u�%�� ��|�|�� � ����(��H� � %� %� '��=�=�?�D��G��x�x� �#����y��(�(�9�b�1��(�(�=�"�5� $����R� 8� �� �N��� � �!�H��I�� �s�B0B?�? C� C�C�CN)� ) rrr�DUCKDUCKGO_ENDPOINTrr,r!rr$r?r"rrr)r) s/��':�!��!��C����T�)�_�rr)c�F�eZdZddefd�Zdedeefd�Zdedeefd�Zy) �ClaudeMCPBridge� llm_providerc��t�|_||_|dk(r5tj�}t j t|��|_yy)Nr )�api_key� http_client) r)� mcp_clientrD�httpx�Client� anthropic� Anthropicr � claude_client)rrDrGs rr,zClaudeMCPBridge.__init__?sD��#�+���(��� �8� #��,�,�.�K�!*�!4�!4�&�'�"�D� � $r� user_messagerc�H�|jdk(r|j|�SdgS)Nr �error)rD�_extract_with_claude)rrNs r� extract_website_queries_with_llmz0ClaudeMCPBridge.extract_website_queries_with_llmKs)�� � � �� (��,�,�\�:� :��9� rc ��� |jjjddddd|d�g��}|jdj}t j d |t j�}|r%tj|jd ��}n tj|�}|jd g�}|S#Yy xYw#t$r}t|�gcYd}~Sd}~wwxYw) Nzclaude-3-sonnet-20240229i�g�������?a&You are a helpful assistant that identifies web search queries in user message. Extract any specific website or topic queries the user wants information about. Return results as a JSON object with a 'queries' field containing an array of strings. If no queries are found, return an empty array.�user)�role�content)�model� max_tokens� temperature�system�messagesrz```(?:json)?\s*({.*?})\s*```rrP�queries)rMr[�createrV�text�rer?�DOTALLr�loads�groupr5r8r9)rrNr;rV� json_match�resultr\r>s rrQz$ClaudeMCPBridge._extract_with_claudeQs��� ��)�)�2�2�9�9�0���@�#� �=�� :��H��&�&�q�)�.�.�G����#B�G�R�Y�Y�W�J��� � �:�#3�#3�A�#6�7��#�!�Z�Z��0�F��j�j��B�/�G��N��#�"��� � �!�H��I�� �s<�BC�B?�+C�?C�C�C� C&� C!�C&�!C&N)r ) rrr� LLMProviderr,rrrRrQr"rrrCrC=s<�� �[� ��S��T�#�Y�� ����c��rrC� tool_paramsrc��|jdd�}|sddiSt�}|jj|�}d|D�cgc] }t |���c}iScc}w)Nr-r rPzno queryr=)r5rCrHr?r )rfr-�bridger=rds r�handle_claude_tool_callriose�� �O�O�G�R� (�E� ���$�$� � �F����&�&�u�-�G� ��9��v�F�6�N��9� ���9s�A)�osr_rr4�typingrrrrr� dataclassesrr �openairKrIrA�environr5r rerr$r)rCrrir"rr�<module>ros��� � � ��5�5�)� �� �2������� 0�"�5���h�� � ��� �� ��� �� ��:0�0�d ��c�3�h�� �D��c��N� r

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/risherb/Claude_MCP_Server'

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