server.cpython-312.pyc•2.57 kB
�
    Q��gT  �                   �v  � d dl mZ d dlZd dlZd dlmZ  e�         ej                  dd�      Z ej                  dd�      Z ej                  dd	�      Z	 ej                  d
d�      Z
 ej                  dd
�      Zd� Z ed�      Z
e
j                  �       defd��       Ze
j                  �       dedefd��       Zy)�    )�FastMCPN)�load_dotenv�DB_HOST�db�DB_PORT�5432�DB_NAME�
mydatabase�DB_USER�postgres�DB_PASSWORD�passwordc                  �V   � t        j                  dt        t        t        t
        ��      S )z!Return a new database connection.�	localhost)�host�port�database�userr   )�psycopg2�connectr   r	   r   r
   � �    �-/Users/rick/Projects/mcp-python/app/server.py�get_db_connectionr      s$   � ����
�
��
��� r   z
Demo Donna�returnc                  �  � 	 t        �       } | j                  �       5 }|j                  d�       |j                  �       }ddd�       | j	                  �        t        �      S # 1 sw Y   �$xY w# t        $ r}d|� �cY d}~S d}~ww xY w)�~
    Executes a SQL query and returns the result as a string.
    
    Example:
      query_db("SELECT * FROM my_table;")
    z*SELECT * FROM information_schema.schemata;N�Error: �r   �cursor�execute�fetchall�close�str�	Exception)�conn�cur�result�es       r   �
get_db_schemar*      sq   � �� �"��
�[�[�]�c��K�K�D�E��\�\�^�F� � 	
�
�
���6�{��	 �]��
 � ����}�����3   �A- �"A!�"A- �!A*�&A- �-	B�6B �:B� B�queryc                 �  � 	 t        �       }|j                  �       5 }|j                  | �       |j                  �       }ddd�       |j	                  �        t        �      S # 1 sw Y   �$xY w# t        $ r}d|� �cY d}~S d}~ww xY w)r   Nr   r   )r,   r&