Skip to main content
Glama

ConnectWise API Gateway MCP Server

api_db_utils.cpython-313.pyc14.6 kB
� �P�g�/���SrSSKrSSKrSSKJrJrJrJrJrJ r "SS5r \ S:Xa�\ "S5r \ RS5r\SS H9r\"\S R#5S \S 35 \"S \S35 \"5 M; \(a6\ R%\SS5r\"S5 \"\ R)\55 \ R+5 gg)z� API Database Utility Functions This module provides utility functions to query the SQLite database containing the ConnectWise API endpoint information. �N)�Dict�List�Any�Optional�Union�Tuplec �@�\rSrSrSrS\4SjrSSjrSSjrS \S\ \ \\ 44S jr S \ S\ \\ 44S jrS \S\S\\ \\ 44SjrS\ \4SjrS\S\ \ \\ 44SjrS \ S\S\\ \\ 44SjrSS \S\ S\ \ \\ 44SjjrS\ \\ 4S\4SjrSrg)� APIDatabase� z?Class to handle queries to the ConnectWise API SQLite database.�db_pathc�>�XlSUlUR5 g)z#Initialize the database connection.N)r �conn�connect)�selfr s �>C:\MCP-Servers\CWM-API-Gateway-MCP\api_gateway\api_db_utils.py�__init__�APIDatabase.__init__s��� ��� � � � ���returnNc��[R"UR5Ul[RURlg)z.Establish a connection to the SQLite database.N)�sqlite3rr r�Row� row_factory�rs rr�APIDatabase.connects&���O�O�D�L�L�1�� � '� � �� � �rc�\�UR(aURR5 gg)zClose the database connection.N)r�closers rr�APIDatabase.closes�� �9�9� �I�I�O�O� � r�queryc��UR(dUR5 URR5nSUS3nURSX3X345 /nUR 5HnUR [ U55 M U$)z� Search for API endpoints matching the query. Args: query: Search string (can match path, description, tags) Returns: List of matching endpoints �%z� SELECT * FROM endpoints WHERE path LIKE ? OR description LIKE ? OR tags LIKE ? OR summary LIKE ? ORDER BY category, path )rr�cursor�execute�fetchall�append�dict)rrr"�search_pattern�results�rows r�search_endpoints�APIDatabase.search_endpoints!s~���y�y� �L�L�N����!�!�#���U�G�1������ ��n� M� O����?�?�$�C� �N�N�4��9� %�%��r� endpoint_idc��UR(dUR5 URR5nURSU45 [ UR 5=(d 05nU(d0$URSU45 UR 5Vs/sHn[ U5PM snUS'URSU45 UR 5nU(a�[ U5US'USRS5(a#[R"USS5USS'USRS5(a#[R"USS5USS'URSU45 /nUR 5H�n[ U5nURS5(a[R"US5US'URS5(a[R"US5US'URU5 M� XcS 'U$s snf![Ra GN f=f![Ra N�f=f![Ra N�f=f![Ra N�f=f) z� Get complete details for a specific endpoint. Args: endpoint_id: ID of the endpoint Returns: Dictionary with endpoint details including parameters and response info z$SELECT * FROM endpoints WHERE id = ?z.SELECT * FROM parameters WHERE endpoint_id = ?� parametersz2SELECT * FROM request_bodies WHERE endpoint_id = ?� request_body�schema�examplez3SELECT * FROM response_bodies WHERE endpoint_id = ?� responses) rrr"r#r&�fetchoner$�get�json�loads�JSONDecodeErrorr%)rr,r"�endpointr)r/r2�responses r�get_endpoint_details� APIDatabase.get_endpoint_details@sV���y�y� �L�L�N����!�!�#�� ���=� �~�N�����)�/�R�0����I� ���G�+��X�7=���7H�!I�7H��$�s�)�7H�!I���� ���K�k�^�\����(� � �'+�L�'9�H�^� $���'�+�+�H�5�5��9=���H�^�D\�]e�Df�9g�H�^�,�X�6� ��'�+�+�I�6�6��:>�*�*�X�n�E]�^g�Eh�:i�H�^�,�Y�7� ���L�{�n�]�� ��?�?�$�C��C�y�H��|�|�H�%�%��)-���H�X�4F�)G�H�X�&� �|�|�I�&�&��*.�*�*�X�i�5H�*I�H�Y�'� � � �X� &�%�"!*������W"J���+�+������+�+������+�+������+�+����sN�H� "H#�"H>�4I�'I2�#H;�:H;�>I�I�I/�.I/�2J �J �path�methodc��UR(dUR5 URR5nURSXR 545 UR 5nU(dgUR US5$)z� Find an endpoint by its path and HTTP method. Args: path: API path (e.g., /service/tickets) method: HTTP method (get, post, put, patch, delete) Returns: Endpoint details or None if not found zQ SELECT id FROM endpoints WHERE path = ? AND method = ? N�id)rrr"r#�lowerr3r:)rr<r=r"�results r�find_endpoint_by_path_method�(APIDatabase.find_endpoint_by_path_method�sn���y�y� �L�L�N����!�!�#����� ��L�L�N� #� %� ���"�����(�(����6�6rc���UR(dUR5 URR5nURS5 UR 5Vs/sHo"SPM sn$s snf)zH Get a list of all API categories. Returns: List of category names z9SELECT DISTINCT category FROM endpoints ORDER BY category�category)rrr"r#r$)rr"r)s r�get_categories�APIDatabase.get_categories�sV���y�y� �L�L�N����!�!�#�����R�S�+1�?�?�+<�=�+<�C�J��+<�=�=��=s�A0rEc���UR(dUR5 URR5nURSU45 UR 5Vs/sHn[ U5PM sn$s snf)z� Get all endpoints for a specific category. Args: category: Category name Returns: List of endpoints in that category z[ SELECT * FROM endpoints WHERE category = ? ORDER BY path )rrr"r#r$r&)rrEr"r)s r�get_endpoints_by_category�%APIDatabase.get_endpoints_by_category�se���y�y� �L�L�N����!�!�#����� ��[�  � &,�_�_�%6�7�%6�c��S� �%6�7�7��7s�!A9� param_namec���UR(dUR5 URR5nURSX45 UR 5nU(a [ U5$S$)z� Get details for a specific parameter of an endpoint. Args: endpoint_id: ID of the endpoint param_name: Name of the parameter Returns: Parameter details or None if not found zV SELECT * FROM parameters WHERE endpoint_id = ? AND name = ? N)rrr"r#r3r&)rr,rKr"rAs r�get_parameter_details�!APIDatabase.get_parameter_details�s^���y�y� �L�L�N����!�!�#����� �� &� (� ���"��%�t�F�|�/�4�/r�limitc �&^ �UR(dUR5 UR5R5m 1SknT Vs/sH oDU;dM UPM snm /nT (dU$T H�n[ U5S:aMSUS3nURR 5nUR SXwXwU45 UR5H&n [U 5n X�;dMURU 5 M( M� U 4Sjn URU SS9 USU$s snf) z� Search for endpoints using natural language queries. Attempts to match keywords to endpoints based on common terms. Args: query: Natural language query limit: Maximum number of results Returns: List of matching endpoints >�a�an�at�by�in�on�or�to�and�but�for�the�from�like�with�about�r!z� SELECT id, path, method, description, category FROM endpoints WHERE path LIKE ? OR description LIKE ? OR tags LIKE ? OR summary LIKE ? LIMIT ? c�>�SnTH}nX RSS5R5;aUS- nX RSS5R5;aUS- nX RSS5R5;dMxUS- nM U$) Nrr<�ra� description��tags�)r4r@)r8�score�keyword�keywordss �r�score_endpoint�>APIDatabase.search_by_natural_language.<locals>.score_endpoints�����E�#���l�l�6�2�6�<�<�>�>��Q�J�E��l�l�=�"�=�C�C�E�E��Q�J�E��l�l�6�2�6�<�<�>�>��Q�J�E� $��LrT)�key�reverseN) rrr@�split�lenr"r#r$r&r%�sort) rrrO� common_words�wordr(rir'r"r)r8rkrjs @r�search_by_natural_language�&APIDatabase.search_by_natural_language�s ����y�y� �L�L�N��;�;�=�&�&�(��D� �%-�J�X�T�\�1I�D�X�J������N� �G��7�|�a��� �� ��^�N��Y�Y�%�%�'�F� �N�N��!�.�RW�X� Z����(����9���*��N�N�8�,�)�# �. � � � ��� �6��v�����WKs � D�Dr8c ���/nURSS5R5nURSS5nURSS5nURUSU35 U(aURSU35 SU;a�US(a�URS5 USH�nURS S5nURS S5nURS 5S :XaS OSn URSS5n URSS5n URSUSUSU SU SU 3 5 M� SU;a�US(a�URS5 USRS05n [U [5(a.U (a'URS[ R "U SS935 USRS05n [U [5(a.U (a'URS[ R "U SS935 SU;abUS(aXURS5 USH>nURSS5nURSS5nURSUSU35 M@ S RU5$)!z� Format an endpoint for display in a user-friendly way. Args: endpoint: Endpoint dictionary Returns: Formatted string representation r=rcr<rd� z Description: r.z Parameters:�name�location�requiredrg�Requiredr�typez - z (z, z): r/z Request Body:r0z Schema: re)�indentr1z Example: r2z Responses:� status_codez: � )r4�upperr%� isinstancer&r5�dumps�join)rr8� formattedr=r<rd�paramrxryrz� param_type� param_descr0r1r9�status�descs r�format_endpoint_for_display�'APIDatabase.format_endpoint_for_display sR��� ����h��+�1�1�3���|�|�F�B�'���l�l�=�"�5� ����F�8�1�T�F�+�,� � � � �}�[�M�:� ;� �8� #���(>� � � �_� -�!�,�/���y�y���,�� �9�9�Z��4��).���:�)>�!�)C�:���"�Y�Y�v�r�2� �"�Y�Y�}�b�9� �� � �4��v�R��z��H�:�R� �|�SV�Wa�Vb�!c�d�0� �X� %�(�>�*B� � � �.� /��n�-�1�1�(�B�?�F��&�$�'�'�F�� � �:�d�j�j���.J�-K�!L�M��~�.�2�2�9�b�A�G��'�4�(�(�W�� � �;�t�z�z�'�!�/L�.M�!N�O� �(� "�x� �'<� � � �^� ,�$�[�1��!���m�R�8���|�|�M�2�6��� � �4��x�r�$��!8�9�2� �y�y��#�#r)rr )rN)� )�__name__� __module__� __qualname__�__firstlineno__�__doc__�strrrrrrrr*�intr:rrBrFrIrMrtr��__static_attributes__�rrr r s&��I���� ,� � �c��d�4��S��>�.B��>C��C��S�#�X��C�J7��7�c�7�h�t�TW�Y\�T\�~�F^�7�6>��S� �>� 8�#�8�$�t�C��H�~�:N�8�.0��0�#�0�(�SW�X[�]`�X`�Sa�Jb�0�0?��?�C�?��d�SV�X[�S[�n�I]�?�B4$�D��c��N�4$�s�4$rr �__main__zconnectwise_api.db�tickets�r=rwr<z rdr?z&Detailed information for first result:)r�rr5�typingrrrrrrr r��dbr*r(rA�printr�r:�detailsr�rr�rr�<module>r�s����� �:�:�G$�G$�T  �z�� �)� *�B��!�!�)�,�G��"�1�+�� ���!�'�'�)�*�!�F�6�N�+;�<�=� ��6�-�(�)�*�+� ��� ��)�)�'�!�*�T�*:�;�� �6�7� �b�,�,�W�5�6��H�H�J�!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/jasondsmith72/CWM-API-Gateway-MCP'

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