sap_client.cpython-311.pyc•3.49 kB
�
�
�h � � � d dl Z d dlmZ d dlmZ d dlmZ d dlmZ G d� d� � Z ded e
d
efd�Zd� Z
ed
k r e j e
� � � � dS dS )� N)�AsyncExitStack)�stdio_client)�
ClientSession)�TextContentc � � e Zd Zd� ZdS )�SimpleServerc � � || _ d S )N)�command)�selfr
s �
sap_client.py�__init__zSimpleServer.__init__ s
� ������ N)�__name__�
__module__�__qualname__r
� r r r r s# � � � � � �� � � � r r �session�
function_name�
parametersc � �2 K � | � d||d��� � � d {V ��}t d|� d�� � |j D ]+}t |t � � rt |j � � �,d S # t $ r }t d|� d|� �� � Y d }~d S d }~ww xY w)N�call_sap_function)r r )�name� argumentsz
Result from �:zError calling z: )� call_tool�print�content�
isinstancer �text� Exception)r r r �resultr �es r �call_and_printr# s � � � �5��(�(�$�!.�(�� � )�
�
�
�
�
�
�
�
�� �/�}�/�/�/�0�0�0��~� $� $�G��'�;�/�/�
$��g�l�#�#�#�� $� $�� � 5� 5� 5�
�3�}�3�3��3�3�4�4�4�4�4�4�4�4�4�����5���s �A&A, �,
B�6B�Bc � � K � t ddg� � } t � � 4 �d {V ��}|� t | � � � � � d {V ��\ }}t ||� � 4 �d {V ��}|� � � � d {V �� t
|dddddd�� � � d {V �� t
|d d
di� � � d {V �� d d d � � �d {V �� n# 1 �d {V ��swxY w Y d d d � � �d {V �� d S # 1 �d {V ��swxY w Y d S )N�pythonz
sap_server.py�BAPI_GL_GETGLACCPERIODBALANCES�C999�
0010010101�2023�10)�COMPANYCODE�GLACCT�
FISCALYEAR�CURRENCYTYPE�BAPI_USER_GET_DETAIL�USERNAME�SAPUSER)r r �enter_async_contextr r �
initializer# )�server�
exit_stack�read�writer s r �mainr8 s � � � �
�8�_�5�
6�
6�F���� � � � � � � �:�&�:�:�<��;O�;O�P�P�P�P�P�P�P�P���e� ��u�-�-� � � � � � � ���$�$�&�&�&�&�&�&�&�&�&� ��*J�%�&�$� $� M� M� � �
�
�
�
�
�
�
� !��*@��I�C� � �
�
�
�
�
�
�
� � � � � � � � � � � � � � � � � � � � � � � ���� � � � �� � � � � � � � � � � � � � � � � � � � � � � ���� � � � � � s7 �AC0�*AC�:C0�
C �C0�C �C0�0
C:�=C:�__main__)�asyncio�
contextlibr �mcp.client.stdior �mcp.client.sessionr � mcp.typesr r �str�dictr# r8 r �runr r r �<module>rB s� �� ���� %� %� %� %� %� %� )� )� )� )� )� )� ,� ,� ,� ,� ,� ,� !� !� !� !� !� !�� � � � � � � �5�-� 5�� 5�QU� 5� 5� 5� 5�"� � �&