Skip to main content
Glama

OpenAI MCP Server

manager.cpython-312.pyc9.25 kB
� �6�g' ���dZddlZddlZddlmZmZmZmZmZm Z ddl Z ddl m Z m Z ddlmZmZmZej$e�ZGd�d�Zy) zTool execution manager.�N)�Dict�List�Any�Optional�Callable�Union)�ThreadPoolExecutor�Future�)�Tool� ToolResult� ToolRegistryc��eZdZdZdefd�Zdeeegdfddfd�Z deee gdfddfd�Z d e ee fde fd �Zd ee ee fdee fd �Zd ededdfd�Zd ededdfd�Zd ede ddfd�Zde ee ee fffd�Zd edefd�Zy)�ToolExecutionManagerzKManages tool execution, including parallel execution and progress tracking.�registryc�J�||_i|_d|_d|_d|_y)z�Initialize the tool execution manager. Args: registry: Tool registry containing available tools N� )r�active_executions�progress_callback�result_callback� max_workers)�selfrs �N/Users/agent/claude-code-reverse/python-agent/claude_code/lib/tools/manager.py�__init__zToolExecutionManager.__init__s+�� !�� �<>���IM���LP�������callbackN�returnc��||_y)z�Set a callback function for progress updates. Args: callback: Function that takes tool_call_id and progress (0-1) as arguments N)r�rrs r�set_progress_callbackz*ToolExecutionManager.set_progress_callbacks �� "*��rc��||_y)z�Set a callback function for results. Args: callback: Function that takes tool_call_id and ToolResult as arguments N)rrs r�set_result_callbackz(ToolExecutionManager.set_result_callback's �� (��r� tool_callc ��|jdi�jdd�}|jdd�}|jj|�}|s.d|��}tj |�t ||d|��dd |� �S|j rtjd |�d ��|j||� |j|�}|j||�|S#t$r_}tjd |�d|���t ||dt|���dd t|�� �}|j||�|cYd}~Sd}~wwxYw)a Execute a single tool synchronously. Args: tool_call: Dictionary containing tool call information Returns: ToolResult with execution result Raises: ValueError: If the tool is not found �function�name��id�unknownzTool not found: �Error: r�error�� tool_call_idr&�result�execution_time�statusr+zTool z= needs permission, but permission handling is not implementedzError executing tool �: N)�getr�get_tool�loggerr+r �needs_permission�warning�_track_execution_start�execute�_track_execution_complete� Exception� exception�str)rr#� function_namer-�tool� error_msgr.�es r� execute_toolz!ToolExecutionManager.execute_tool/sS��"� � �j�"�5�9�9�&�"�E� � �}�}�T�9�5� ��}�}�%�%�m�4���*�=�/�:�I� �L�L�� #��)�"� �� �,� ��� � � � � � �N�N�U�=�/�1n�o� p� �#�#�L�-�@� ��\�\�)�,�F� � *� *�<�� @��M��� � � � �4�]�O�2�a�S�I� J��)�"� ��Q���)� ���!�f� �F� � *� *�<�� @��M�� �s�8$C� E�&AE�:E�E� tool_callsc�� �g}i}tt|jt|����5}|D]5}|j dd�� |j |j |�}� ||<�7tjj|�D])}||� |j�}|j|��+ d d d �|S#t$ro}tjd� �d|���t� fd�|D�d�} |jt!� | dt#|���dd t#|�� ��Yd }~��d }~wwxYw#1swY|SxYw) z�Execute multiple tools in parallel. Args: tool_calls: List of dictionaries containing tool call information Returns: List of ToolResult with execution results )rr(r)z%Error in parallel tool execution for r1c3��K�|];}|jdd��k(r$|jdi�jdd����=y�w)r(r'r%r&N)r2)�.0�tcr-s �r� <genexpr>z>ToolExecutionManager.execute_tools_parallel.<locals>.<genexpr>�sC�����>�B��F�F�4��,� �<���� �B�/�3�3�F�B�?�>�s�AAr*rr+r,N)r �minr�lenr2�submitrA� concurrent�futures� as_completedr.�appendr:r4r;�nextr r<) rrB�resultsrL�executorr#�futurer.r@r=r-s @r�execute_tools_parallelz+ToolExecutionManager.execute_tools_parallelisU�����%'�� �C��0@�0@�#�j�/�,R� S� �W_�'� /� �(�}�}�T�9�=� �!����):�):�I�F��".���� /� %�,�,�9�9�'�B� ��&�v�� ��#�]�]�_�F��N�N�6�*�  � �<���#!���$�$�'L�\�N�Z\�]^�\_�%`�a�$(�>�*�>�!�%�M� �N�N�:�%1�*�!(��Q���1�'(�&�!�!�f� $������ �<��s7�A"D;�!C�3D;� D8� A%D3�.D;�3D8�8D;�;Er-� tool_namec��|tj�dd�|j|<|jr|j|d�yy)z�Track the start of tool execution. Args: tool_call_id: ID of the tool call tool_name: Name of the tool g)rT� start_time�progressN)�timerr)rr-rTs rr7z+ToolExecutionManager._track_execution_start�sE��#��)�)�+��0 ����|�,� � !� !� � "� "�<�� 5� "rrWc��||jvr2||j|d<|jr|j||�yyy)z�Track the progress of tool execution. Args: tool_call_id: ID of the tool call progress: Progress value (0-1) rWN)rr)rr-rWs r�_track_execution_progressz.ToolExecutionManager._track_execution_progress�sL�� �4�1�1� 1�?G�D� "� "�<� 0�� <��%�%��&�&�|�X�>�&� 2rr.c���||jvrh|j|d�|j|d}tj�|z }|j|=|jr|j||�yyy)z�Track the completion of tool execution. Args: tool_call_id: ID of the tool call result: Tool execution result g�?rVN)rrZrXr)rr-r.rVr/s rr9z.ToolExecutionManager._track_execution_complete�s~�� �4�1�1� 1� � *� *�<�� =��/�/� �=�l�K�J�!�Y�Y�[�:�5�N��&�&�|�4��#�#��$�$�\�6�:�$� 2rc�6�|jj�S)z�Get information about active tool executions. Returns: Dictionary mapping tool_call_id to execution information )r�copy)rs r�get_active_executionsz*ToolExecutionManager.get_active_executions�s�� �%�%�*�*�,�,rc�4�tjd|���y)z�Cancel a tool execution if possible. Args: tool_call_id: ID of the tool call to cancel Returns: True if canceled successfully, False otherwise z/Cancellation not implemented for tool_call_id: F)r4r6)rr-s r�cancel_executionz%ToolExecutionManager.cancel_execution�s�� ���H���W�X�r)�__name__� __module__� __qualname__�__doc__rrrr<�floatr r r"rrrArrSr7rZr9r^�boolr`�rrrrs��U� �� �*�h��U�|�T�7I�.J�*�t�*�(�H�c�:�5F��5L�,M�(�RV�(�8�d�3��8�n�8��8�t+��d�3��8�n�1E�+�$�z�JZ�+�Z6�3�6�3�6�4�6�" ?�c� ?�U� ?�t� ?�;�c�;�:�;�RV�;�,-�t�C��c�3�h��,?�'@�-� �S� �T� rr)rd�loggingrX�typingrrrrrr�concurrent.futuresrKr r �baser r r� getLoggerrar4rrgrr�<module>rms@���� �=�=��9�0�0� �� � �8� $��O�Or

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/arthurcolle/openai-mcp'

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