Skip to main content
Glama

Argus

by athapong
main.cpython-312.pyc36.6 kB
� !{�g�x���dZddlmZmZddlmZddlmZddlZddl Z ddl m Z m Z m Z mZmZddlZddlZddlmZddlZddlZddlmZmZddlZdd lmZddlmcmZddl Z ddl!Z"ddl#Z#dd l$m%Z%ddl&Z&dd l'm'Z'dfd �Z(d e)fd�Z*d e)fd�Z+dfd�Z,dfd�Z-e(�Gd�de�Z.Gd�de�Z/Gd�de�Z0Gd�de�Z1Gd�de�Z2Gd�de�Z3Gd�de�Z4Gd �d!e�Z5ed"gd#�d$�%�Z6d&hhd'�d(�hd)�hd*�d(�hd+�hd,�d(�hd-�hd.�d(�d/�Z7gd0�d1d2ggd3�d4d2gd/�Z8dgd5e9d6e e.d e9fd7�Z:dhd5e9d6e e.d8e e9d e9fd9�Z;did:e9d;e9d e9fd<�Z<d=e e e9e=fd e e.fd>�Z>dgd?e9d@e e9dAe e9dBe e9d e9f dC�Z?d?e9d ee9effdD�Z@d?e9d ee9effdE�ZAd?e9d ee9effdF�ZBd?e9d ee9eCffdG�ZDdjdHee9eCfdIeCd e e9fdJ�ZEd?e9dKe9d ee9effdL�ZFd?e9d ee9effdM�ZGd?e9d ee9effdN�ZHd?e9d ee9effdO�ZIdPee9efd ee9effdQ�ZJe6j��dddR�d5e9d6e e e9e=fd8e e9d e9fdS��ZLe6j��dddR�d5e9dTe e9d6e e e9e=fd8e e9d e=e9e9ff dU��ZMe6j��ddV�d5e9d6e e e9e=fd e e9fdW��ZNe6j��dddddX�d5e9d@e e9dAe e9dBe e9d6e e e9e=fd e9f dY��ZOe6j��ddZdd[�d5e9d8e e9d\ePd6e e e9e=fd e e=f d]��ZQe6j��d2ddd^�d5e9d_e9d6e e e9e=fd8e e9d ee9eff d`��ZRe6j��ddV�d5e9d6e e e9e=fd ee9effda��ZSe6j��dbe9d e9fdc��ZUe6j��ddddd�d5e9dKe e9d6e e e9e=fd8e e9d ee9eff de��ZVy)kz2Repository analysis and security assessment tools.�)�FastMCP�server)�types)� BaseModelN)�List�Optional�Union�Dict�Any)�Path)�Repo�GitCommandError)�Enum)�Counter)�datetime�returnc�V�t�s t�t�s t�yy)z(Ensure all required tools are installed.N)�is_pmd_installed� install_pmd�is_trivy_installed� install_trivy���U/Users/athapongkaewsalapoom/Development/experimental/mcp/argus/src/panopticon/main.py�ensure_dependenciesrIs!�� � �� � � ��� rc�V� tjddgd��y#t$rYywxYw)zCheck if PMD is installed.�pmd� --versionT��capture_outputF�� subprocess�run�FileNotFoundErrorrrrrrVs/�������{�+�D�A��� ����� �� (�(c�V� tjddgd��y#t$rYywxYw)zCheck if Trivy is installed.�trivyrTrFr!rrrrr^s/��������-�d�C��� ����r%c���tj�j�}|dk(rtjgd�d��y|dk(�r�d}d|�d|�d �}t j jd �}t j|d� �tjd d � �5}tjj||j�tj!|jd�5}|j#|�ddd�ddd�t j j%|d|�d��}t j j%|d�}t j&|t j(|�j*t(j,z�t j j/|�rt j0|�t j2||�|t j4dvrHt7t j jd�d�5}|j9d|�d��ddd�yyt;d|����#1swY��PxYw#1swY��UxYw#1swYyxYw)z Install PMD.�darwin)�brew�installrT��check�linuxz 7.0.0-rc4z:https://github.com/pmd/pmd/releases/download/pmd_releases/z /pmd-bin-z.zipz ~/.local/bin��exist_okF��suffix�delete�rNzpmd-bin-z/bin/pmdr�PATHz ~/.bashrc�az export PATH="z:$PATH" �Unsupported operating system: )�platform�system�lowerr"r#�os�path� expanduser�makedirs�tempfile�NamedTemporaryFile�urllib�request� urlretrieve�name�zipfile�ZipFile� extractall�join�chmod�stat�st_mode�S_IEXEC�exists�remove�symlink�environ�open�write� Exception) r9� pmd_version�pmd_url� install_dir�tmp_file�zip_ref� pmd_script�pmd_link�bashrcs rrrfs��� �_�_� � $� $� &�F� ������1��>� �7� �!� �N�{�m�[d�ep�dq�qu�v���g�g�(�(��8� � � � �K�$�/�� (� (��u� E�� �N�N� &� &�w�� � � >��������4���"�"�;�/�5�F� �W�W�\�\�+��+��h�/O�P� ��7�7�<�<� �U�3�� ����R�W�W�Z�0�8�8�4�<�<�G�H� �7�7�>�>�(� #� �I�I�h� � � � �:�x�(� �b�j�j��0� 0��b�g�g�(�(��5�s�;�v�� � ��{�m�9�E�F�<�;� 1��8���A�B�B�!5�4��F� E��<�;�s1� A I�+I �=I�I%� I �I�I"�%I.c��tj�j�}|dk(rtjgd�d��y |dk(r�tjgd�d��tjgd�dd��tjgd �dd��tjgd �d��tjgd �d��y t d |����)zInstall Trivy.r))r*r+zaquasecurity/trivy/trivyTr,r.)�sudo�apt-getr+�wgetzapt-transport-https�gnupgz lsb-release) r_z-qO�-z8https://aquasecurity.github.io/trivy-repo/deb/public.key�|�gpgz --dearmorrbr]�teez/usr/share/keyrings/trivy.gpg�>z /dev/null)r-�shell) �echoz-deb [signed-by=/usr/share/keyrings/trivy.gpg]z-https://aquasecurity.github.io/trivy-repo/debz$(lsb_release -sc)�mainrbr]rdz"/etc/apt/sources.list.d/trivy.list)r]r^�update)r]r^r+r'z-yr7N)r8r9r:r"r#rS)r9s rrr�s��� �_�_� � $� $� &�F� ������F�d�S� �7� ���� �� � ��� � �T�  #� ��� � �T�  #� ���4�D�A����D�D�Q��8���A�B�Brc��eZdZUeed<y)�GitLabCredentials�api_keyN)�__name__� __module__� __qualname__�str�__annotations__rrrrkrk�s�� �Lrrkc�@�eZdZUeed<dZeeed<dZeeed<y)�AnalyzeRepositoryInput�repo_urlN�gitlab_credentials�branch� rmrnrorprqrurrkrvrrrrsrs�s&���M�6:���!2�3�:� �F�H�S�M� rrsc�P�eZdZUeed<eeed<dZeeed<dZ eeed<y)�InspectFilesInputrt� file_pathsNrurv) rmrnrorprqrrurrkrvrrrryry�s0���M��S� ��6:���!2�3�:� �F�H�S�M� rryc�,�eZdZUeed<dZeeed<y)�EnumerateBranchesInputrtNru)rmrnrorprqrurrkrrrr|r|�s���M�6:���!2�3�:rr|c�h�eZdZUeed<dZeeed<dZeeed<dZeeed<dZ ee ed<y)� DiffInputrtN�source�target� file_pathru) rmrnrorprqrrr�r�rurkrrrr~r~�sB���M� �F�H�S�M� � �F�H�S�M� �#�I�x��}�#�6:���!2�3�:rr~c�T�eZdZUeed<dZeeed<dZeeed<dZ eeed<y)�SecurityScanInputrtNrur'� scan_typerv) rmrnrorprqrurrkr�rvrrrr�r��s4���M�6:���!2�3�:�&�I�x��}�&� �F�H�S�M� rr�c�J�eZdZUeed<eed<dZeeed<dZeeed<y)�CodeQualityInputrt�languageNrurvrwrrrr�r��s+���M��M�6:���!2�3�:� �F�H�S�M� rr�c�J�eZdZUdZeed<dZeeed<dZee eed<y)�TeamsWebhookConfigz&Microsoft Teams webhook configuration.�urlN�channel� mention_users) rmrnro�__doc__rprqr�rr�rrrrr�r��s+��0� �H�!�G�X�c�]�!�)-�M�8�D��I�&�-rr�zRepository Tools)� GitPython�gitdb�requests�pylint�bandit�WARNING)� dependencies� log_levelz.go>�func �import (�package )� extensions�markers>�.kt�.java�.scala>� import java� public classr�>�.py�.pyi�.pyx>�def �from �class �import >�.js�.ts�.jsx�.tsx>�let �const �functionr�)�go�java�python� javascript)�gocycloz golangci-lintr'rr')r�r�r'�eslintrtruc���|s|Sd|vrb|jd�r |jdd|j�d��S|jd�r |jdd|j�d��S|S)zIConvert repository URL to include authentication if credentials provided.z gitlab.comzhttps://zhttps://oauth2:�@zgit@zgit@gitlab.com:z @gitlab.com/)� startswith�replacerl)rtrus r�get_authenticated_urlr�s��� ����x�� � � �z� *��#�#�J�/�BT�B\�B\�A]�]^�0_�`� `� � � �� (��#�#�$5��I[�Ic�Ic�Hd�dp�7q�r� r� �Orrvc���|�d|r |jnd�d|xsd��}tj|j��j �dd}t j jtj�d|���}t||�}t j j|�r� t|�}|jsZ|j�j|k(r=|j�j!�|r|j"j%|�|St'j(|d��t j*|d� � |rtj,|||� �|Stj,||�|S#t'j(|d��Y�gxYw#t.$r3}t'j(|d��t/d t1|�����d}~wwxYw) zHClone or retrieve an existing repository from cache and return its path.�:��defaultN� � repo_cache_T)� ignore_errorsr/)rvzRepository cloning failed: )rl�hashlib�sha256�encode� hexdigestr;r<rHr?� gettempdirr�rMr �bare�remoter��fetch�git�checkout�shutil�rmtreer>� clone_fromrSrp) rtrurv� cache_key� repo_hash�temp_dir�authenticated_url�repo�es r� clone_repor�s����*�A�<N�0�8�8�TV�W�WX�Y_�Yl�cl�Xm�n�I����y�/�/�1�2�<�<�>�s��C�I��w�w�|�|�H�/�/�1�[�� �3L�M�H�-�h�8J�K�� �w�w�~�~�h�� 8���>�D��9�9�����!2�!2�6G�!G�� � � �#�#�%���H�H�%�%�f�-��� �M�M�(�$� 7� �K�K��4�(�@� � �O�O�-�x�� G��� �O�O�-�x� 8���� 8� �M�M�(�$� 7�� �@�� � �h�d�3��5�c�!�f�X�>�?�?��@�s1�2A0F�#F�F$�.F$�F!�$ G �-.G�G r<�prefixc��d}tj|�}|j�t|�D]�\}}|j d�r�|t |�dz k(}|rdnd}|rdnd}tj j||�} |||z|zdzz }tj j| �s��|t| ||z�z }��|S) z/Generate a tree-like directory structure stringr��.git�u └── u ├── z u│ � ) r;�listdir�sort� enumerater��lenr<rH�isdir�get_directory_tree) r<r��output�entries�i�entry�is_last�current_prefix� next_prefix� entry_paths rr�r�1s��� �F��j�j���G� �L�L�N��g�&���5� � � �F� #� ��s�7�|�a�'�'��)0��l�� '�f�X� ��W�W�\�\�$��.� ��&�>�)�E�1�D�8�8�� �7�7�=�=�� $� �(��V�k�5I�J� J�F�'� �Mr�credsc�x�|syt|t�r t|��St|t�r tdi|��Sy)z8Convert various credential formats to GitLabCredentials.N)rlr)� isinstancerprk�dict)r�s r�create_gitlab_credentialsr�Gs8�� ���%��� ��/�/��%��� �)�5�)�)� r� repo_pathrr�r�c��� t|�}|r|j|�}n|jj}|r|j|�}n |jr|jdnd}|sy|r|jj ||d|�}n|jj ||�}|r|SdS#t $r}dt|���cYd}~Sd}~wt$r}dt|���cYd}~Sd}~wwxYw)z&Get diff between two commits/branches.rNz)No previous commit found to compare with.z--zNo changes found.zGit diff failed: zError generating diff: ) r �commit�head�parentsr��diffrrprS) r�rr�r�r�� source_commit� target_commitr�r�s r�get_diff_changesr�Qs���2��I��� � �K�K��/�M� �I�I�,�,�M� � �K�K��/�M�8E�8M�8M�M�1�1�!�4�SW�M� �B� ��8�8�=�=�� �t�Y�O�D��8�8�=�=�� �>�D��t�4�!4�4�� �,�"�3�q�6�(�+�+�� �2�(��Q���1�1��2�s=�A(B.�+AB.�,B.�. C.�7 C �C.� C.� C)�#C.�)C.c�,� tjdddd|gddd��}tj|j�S#tj $r}dd|j ��icYd }~Sd }~wtj$rdd icYSt$rdd icYSwxYw) z.Run Trivy vulnerability scanner on repository.r'�fsz--format�jsonT)r �textr-�errorzTrivy scan failed: NzFailed to parse Trivy outputz0Trivy not installed. Please install Trivy first.) r"r#r��loads�stdout�CalledProcessError�stderr�JSONDecodeErrorr$�r��resultr�s r�run_trivy_scanrps��� M���� �d�J�� � :����  �� �z�z�&�-�-�(�(�� � (� (�;��.�q�x�x�j�9�:�:�� � � �9��7�8�8� �M��K�L�L�M�s'�<?�B�A(�"B�(B� B�Bc�@� tjgd�|dd��}gddd�}|jr�|jj�j d�}d}|D]l}|s�|j �}t |�dk\s�%t |d�}|d}|d } |d j||| d ��||z }|d kDs�`|d xxdz cc<�nt |�dkDr|t |�z |d<|S#t$rddicYSt$r} ddt| ���icYd} ~ Sd} ~ wwxYw)z.Run cyclomatic complexity analysis on Go code.)r�z-avgz-over=10�.T)�cwdr r�r)�cyclomatic_complexity�average_complexity�high_complexity_functionsr������������r)� complexityr��file� rr�rr�zbgocyclo not installed. Please install with: go install github.com/fzipp/gocyclo/cmd/gocyclo@latestzFailed to run gocyclo: N) r"r#r��strip�splitr��int�appendr$rSrp) r�r�metrics�lines�total_complexity�line�partsr � function_namer�r�s r�run_gocyclo_analysisr�sK��(=���� 0����  ��&(�"#�)*� �� �=�=��M�M�'�'�)�/�/��5�E� � ���� �J�J�L�E��5�z�Q��%(��q��]� �(-�b� � �$)�"�I� �� 7�8�?�?�*4�(5�$-�A�� )�J�6�(�%��?�#�$?�@�A�E�@�� �5�z�A�~�0@�3�u�:�0M��,�-���� ���}�~�~� �=��2�3�q�6�(�;�<�<��=�s6�AC,�"C,�:C,�</C,�, D�;D�D�D�Dc ��� tjdd��5}|j}ddd�tjddd|dd d d d g d d ��} t |d�5}|j �}ddd�ditj|�S#1swY�jxYw#1swY�.xYw#tj|�wxYw#t$rddicYSt$r}ddt|���icYd}~Sd}~wwxYw)z@Run PMD static code analysis on Java code and return raw output.z.xmlFr1Nrr-z-dz-Rzrulesets/java/quickstart.xml�-f�xml�-rT�r r�r4� raw_outputr�zAPMD not installed. Please install PMD from https://pmd.github.io/zFailed to run PMD: ) r?r@rDr"r#rQ�readr;�unlinkr$rSrp)r�rW� output_pathr�f� xml_contentr�s r�run_pmd_analysisr$�s���9� � (� (��u� E��"�-�-�K�F�������i��4��e��k�  � ��  �� #��k�3�'�1��f�f�h� �(� �+�.� �I�I�k� "�-F� E��$(�'�� �I�I�k� "�� �^��\�]�]� �9��.�s�1�v�h�7�8�8��9�si�C� B�*C� B'�B�. B'�9C�B�C�B$� B'�'B>�>C� C2�C2�C-�'C2�-C2c ���t�}i}d}tj|�D]�\}}}d|vr� |D]�}tjj ||�}tjj |�\}} tjj |�dkDr�htj�D]d\} } | | dvs� t|dd��5} | jd��t�fd �| d D��} | dkDr|| xxd z cc<|d z }d d d ��f����|dkDr |j�D] \} }||z || <�|S#1swY�6xYw#Y��xYw) z~ Detect programming languages used in the repository. Returns a dictionary of language -> confidence score (0-1). rr�i@Br�r4�utf-8��encodingic3�*�K�|] }|�vrd��� y�w)r�Nr)�.0�marker�contents �r� <genexpr>z.detect_repository_languages.<locals>.<genexpr>�s"�����/B�?R�V�/5��/@�01�?R�s�r�r�N) rr;�walkr<rH�splitext�getsize�LANGUAGE_PATTERNS�itemsrQr�sum)r�� file_count�language_confidence� total_files�root�_�filesr r��ext�lang�patternsr"� marker_count�countr,s @r�detect_repository_languagesr?�sb��� ��J����K��'�'�)�,���a�� �T�>� ��D���� � �T�4�0�I��W�W�%�%�i�0�F�A�s��w�w���y�)�I�5��#4�"9�"9�";���h��(�<�0�0� !�!�)�S�7�C�q�&'�f�f�T�l�G�+.�/B�x� �?R�/B�,B�L�+�a�/� *�4� 0�A� 5� 0� +�q� 0� � D��#<�� -�6�Q��%�+�+�-�K�D�%�(-� �(;� �� %�.� ��D�C��!� �s%�>E � AE � E �E �E � E � languages�min_confidencec��t�}|j�D]0\}}||k\s� |jtj |g���2t |�S)z;Get appropriate analysis tools based on detected languages.)�setr2ri�ANALYSIS_TOOLS�get�list)r@rA�selected_toolsr;� confidences r�get_analysis_toolsrI�sO���U�N�%�O�O�-���j� �� '� � !� !�.�"4�"4�T�2�">� ?�.� �� �rr�c���i}|dk(rt|�|d<|S|dk(rt|�|d<|S|dk(rt|�|d<t|�|d<|S|dk(rt |�|d <|S) z%Run language-specific analysis tools.r�r�r�rr�r�r�r�r�)rr$�run_pylint_analysis�run_bandit_analysis�run_eslint_analysis)r�r��resultss r�run_language_specific_analysisrOs����G��4��1�)�<�� �� �N� �V� �)�)�4���� �N� �X� �/� �:����/� �:���� �N� �\� !�/� �:���� �Nrc��� tjdd|gdd��}|jrtj|j�SddiS#t $r}ddt |���icYd}~Sd}~wwxYw) z#Run Pylint analysis on Python code.r�z--output-format=jsonTrr�zNo output from pylintzPylint analysis failed: N�r"r#r�r�r�rSrpr�s rrKrKss��>���� �-�y� 9��� �� -3�M�M�t�z�z�&�-�-�(�a��I`�?a�a�� �>��3�C��F�8�<�=�=��>�s$�AA �A � A/�A*�$A/�*A/c��� tjdddd|gdd��}|jrtj|j�SddiS#t $r}dd t |���icYd }~Sd }~wwxYw) z,Run Bandit security analysis on Python code.r�rrr�Trr�zNo output from banditzBandit analysis failed: NrQr�s rrLrL!sv��>���� �t�T�6�9� 5��� �� -3�M�M�t�z�z�&�-�-�(�a��I`�?a�a�� �>��3�C��F�8�<�=�=��>�s$�AA� A� A1�A,�&A1�,A1c��� tjddd|gdd��}|jrtj|j�SddiS#t $r}ddt |���icYd }~Sd }~wwxYw) z2Run ESLint analysis on JavaScript/TypeScript code.r�rr�Trr�zNo output from eslintzESLint analysis failed: NrQr�s rrMrM-st��>���� �t�V�Y� /��� �� -3�M�M�t�z�z�&�-�-�(�a��I`�?a�a�� �>��3�C��F�8�<�=�=��>�s$�AA � A � A0�A+�%A0�+A0� scan_resultsc���|jdg�}t|�td�|D��td�|D��td�|D��td�|D��d�S)z,Format Trivy scan results for Teams message.�vulnerabilitiesc3�JK�|]}|jd�dk(s�d���y�w)�severity�CRITICALr�N�rE�r*�vs rr-z'format_trivy_results.<locals>.<genexpr>?s!����V�?�a�a�e�e�J�6G�:�6U��?���#�#c3�JK�|]}|jd�dk(s�d���y�w)rX�HIGHr�NrZr[s rr-z'format_trivy_results.<locals>.<genexpr>@s!����N��!�!�%�%� �2C�v�2M�A��r]c3�JK�|]}|jd�dk(s�d���y�w)rX�MEDIUMr�NrZr[s rr-z'format_trivy_results.<locals>.<genexpr>As!����R��A�A�E�E�*�4E��4Q�a��r]c3�JK�|]}|jd�dk(s�d���y�w)rX�LOWr�NrZr[s rr-z'format_trivy_results.<locals>.<genexpr>Bs!����L�o�����z�1B�e�1K�1�o�r])zTotal Vulnerabilities�Critical�High�Medium�Low)rEr�r3)rTrVs r�format_trivy_resultsrh9sa��"�&�&�'8�"�=�O�"%�_�!5��V�?�V�V��N��N�N��R��R�R��L�o�L�L�  �r)rurvc�� t|�}t|||�}t|�}|S#t$r}dt |���cYd}~Sd}~wwxYw)a Generate a tree representation of a repository's file structure. Args: repo_url: Repository URL to analyze gitlab_credentials: Optional GitLab token string or credentials dict branch: Optional branch name to clone zRepository analysis failed: N)r�r�r�rSrp)rtrurvr�r��treer�s r�analyze_repository_structurerkEsP��7�)�*<�=���x���7� �!�)�,��� �� �7�-�c�!�f�X�6�6��7���$'� A� A�A�Arzc��td|�d|�d|��� t|�}t|||�}i}|D]r}tjj ||�}tjj |�sd||<�H t|dd��5} | j�||<ddd��t|S#1swY� xYw#t$r} d t| ���||<Yd} ~ ��d} ~ wwxYw#t$r} d d t| ���icYd} ~ Sd} ~ wwxYw) z:Extract and return contents of specified repository files.z.inspect_repository_files called with repo_url=z , file_paths=z, gitlab_credentials=zError: File not foundr4r&r'NzError reading file: r�zRepository inspection failed: ) �printr�r�r;r<rH�isfilerQrrSrp) rtrzrurvr�r�rNr�� full_pathr"r�s r�inspect_repository_filesrqWs�� � :�8�*�M�R\�Q]�]r�tF�sG� H�I�D�)�*<�=���x���7� ���#�I���� � �Y� �:�I��7�7�>�>�)�,�'<�� �"�� E��)�S�7�;�q�)*����G�I�&�<��$��� <�;��� E�';�C��F�8�%D�� �"�� E�� �D��9�#�a�&��B�C�C��D�s`�A$C�;B5� B)�B5�%C�)B2 �.B5�5 C�>C�C�C�C� C?�%C:�4C?�:C?)ruc��� t|�}t||�}t|�}|jD�cgc]}|j��}}|Scc}w#t $r}dt |���gcYd}~Sd}~wwxYw)z,Retrieve all branch names from a repository.zBranch enumeration failed: N)r�r�r �branchesrDrSrp)rtrur�r�r�rvrsr�s r�enumerate_branchesrtusu�� 8�)�*<�=���x��/� ��I���/3�m�m�<�m�F�F�K�K�m��<����=�� �8�-�c�!�f�X�6�7�7��8�s.�0A�A �A� A� A0�A+�%A0�+A0)rr�r�ruc�� t|�}t||�}t||||�S#t$r}dt |���cYd}~Sd}~wwxYw)aV Compare changes between git commits or branches. Args: repo_url: Repository URL source: Source branch/commit (default: current HEAD) target: Target branch/commit (default: previous commit) file_path: Specific file to compare (optional) gitlab_credentials: Optional GitLab credentials zComparison failed: N)r�r�r�rSrp)rtrr�r�rur�r�r�s r�compare_git_changesrv�sP��$.�)�*<�=���x��/� �� �6�6�9�E�E�� �.�$�S��V�H�-�-��.�rlr )rv� max_countrurwc�� t|�}t|||�}t|�}|r|jj |�g}|j |��D]�}|j |j|jj�d|jj�d�|jj�|jj�d����|S#t$r} ddt!| ���igcYd} ~ Sd} ~ wwxYw)a  Get commit history for a repository branch. Args: repo_url: Repository URL branch: Branch name (default: current branch) max_count: Maximum number of commits to return gitlab_credentials: Optional GitLab credentials )rwz <re)�hash�author�date�messager�zFailed to get commit history: N)r�r�r r�r�� iter_commitsr�hexsharzrD�email�committed_datetime� isoformatr|rrSrp) rtrvrwrur�r�r��commitsr�r�s r�get_commit_historyr��s��� F�)�*<�=���x���7� ��I��� � �H�H� � �f� %����'�'�)�'�<�F� �N�N�� � �#�]�]�/�/�0��6�=�=�3F�3F�2G�q�I��1�1�;�;�=�!�>�>�/�/�1� � �=���� �F��:�3�q�6�(�C�D�E�E��F�s�CC� C?�$C:�4C?�:C?)r�rurvr�c��� t|�}t|||�}|dk7rddiSt|�}|t|�d�S#t$r}ddt |���icYd}~Sd}~wwxYw)z6Perform security scanning on a repository using Trivy.r'r�z Only Trivy scanning is supported)� trivy_scan�summaryzSecurity scan failed: N)r�r�rrhrSrp)rtr�rurvr�r�rTr�s r�security_scan_repositoryr��s|��<�)�*<�=���x���7� � �� ��?�@� @�%�i�0� �&�+�L�9� � �� �<��1�#�a�&��:�;�;��<�s� <�<� A�A�A�Ac�� t|�}t||�}t|�}|jD]}|j ��|j D�cgc]}|j ��c}|j�jD�cgc]*}|j jd�r�|j ��,c}|jj d�}d|d�Scc}wcc}w#t$r} ddt| ���d�cYd} ~ Sd} ~ wwxYw) a Fetch all branches from a repository and ensure they are up to date. Args: repo_url: Repository URL to fetch from gitlab_credentials: Optional GitLab credentials Returns: Dictionary containing branch information or error z/HEAD)�localr��current�success)�statusrsr�zFailed to fetch branches: �r�r�N) r�r�r �remotesr��headsrDr��refs�endswith� active_branchrSrp) rtrur�r�r�r�rv�refrsr�s r�fetch_all_branchesr��s��� �)�*<�=���x��/� ��I����l�l�F� �L�L�N�#� 15� � �;� �f�f�k�k� �;�+/�;�;�=�+=�+=�`�+=�C�S�X�X�EV�EV�W^�E_�s�x�x�+=�`��)�)�.�.� �� � � � �� <��`�� � ��1�#�a�&��:� � �� �sB�AC�C�&C� C�%C�3C� C� D�%C;�5D�;D� pmd_outputc� �d|��S)Na�As a seasoned software engineer, meticulously review the code quality analysis results generated by PMD. Craft a comprehensive, professional, and technically detailed summary that encompasses the following aspects: 1. Provide an overall assessment of the codebase's health, highlighting the general adherence to coding standards and best practices. 2. Identify and emphasize the most critical issues that demand immediate attention, detailing their potential impact on system stability, performance, and security. 3. Analyze and describe any recurring patterns or trends in the issues found, offering insights into common pitfalls or areas of weakness in the code. 4. Offer specific, actionable recommendations for improvement, suggesting concrete steps to remediate identified issues and enhance code quality. 5. Prioritize the issues in a logical order for addressing them, balancing urgency, impact, and effort required for resolution. PMD output: r)r�s r�analyze_pmd_violationsr�s��� � � �r)r�rurvc�~� t|�}t|||�}|st|�}|sddd�S|j�di}t |�}|sddd�Sd|id�}|j �D]\} } | dk\s� t || �|d | <�t|�|d <|S#t$r} dd t| ���d�cYd } ~ Sd } ~ wwxYw) a\ Analyze code quality with automatic language detection and tool selection. Args: repo_url: Repository URL language: Optional language override gitlab_credentials: Optional GitLab credentials branch: Optional branch name to clone Returns: Dictionary containing analysis results r�z+No supported programming languages detectedr�g�?z7No suitable analysis tools found for detected languagesr�)r�r@�analysis皙�����?r�� security_scanzCode quality analysis failed: N) r�r�r?r:rIr2rOrrSrp) rtr�rurvr�r��detected_languages�toolsrNr;rHr�s r�analyze_code_qualityr�s��&+ �)�*<�=���x���7� ��!<�Y�!G� �%�%�J��� #+�.�.�"2�C�!8� �#�#5�6���!�R�� � �+�� �� !3� 8� 8� :� �D�*��S� �,J�9�VZ�,[�� �#�D�)�!;� $2�)�#<��� ���� � ��5�c�!�f�X�>� � �� �s.�+B�#B�!B�4#B� B<�!B7�1B<�7B<)rN)N)NN)r�)r�)Wr��mcp.server.fastmcprr�mcp.server.fastmcp.resourcesr�pydanticrr;r"�typingrrr r r r?r��pathlibr r�r�r�r rr��enumr�xml.etree.ElementTree�etree� ElementTree�ETr8�urllib.requestrArJ� collectionsr�rerr�boolrrrrrkrsryr|r~r�r�r��mcpr1rDrpr�r�r�r�r�r�rrr$�floatr?rIrOrKrLrMrh�toolrkrqrtrvrr�r�r��promptr�r�rrr�<module>r�s���8�.�.�� ��3�3�� ��� �%� ��"�"��� �� ��d ��$���D��!C�FC�D��� ��!�Y�!� !� �!� ;�Y�;�;� �;�!� �!� !�y�!� .��.� ���� ���g�4� � 1�>� � .�9�� 5�<����( 0� �G� �+��W�%� �� �C� �X�FW�=X� �dg� �!@��!@�(�;L�2M�!@�^f�gj�^k�!@�wz�!@�F�S��#��s��,�X�e�C��I�.>�%?��H�M^�D_��2��2�X�c�]�2�H�S�M�2�^f�gj�^k�2�wz�2�>M�c�M�d�3��8�n�M�"*=�C�*=�D��c��N�*=�X9��9��S�#�X��9�B(�3�(�4��U� �3C�(�T �$�s�E�z�"2� �E� �TX�Y\�T]� ��c��S��T�#�s�(�^��& >�3� >�4��S��>� >� >�3� >�4��S��>� >� >�3� >�4��S��>� >� �t�C��H�~� �$�s�C�x�.� �����dh�CG�7�c�7�x�PU�VY�[_�V_�P`�Ga�7�rz�{~�r�7�LO�7� �7�"����w{�VZ�D�#�D�4��9�D�Zb�ch�il�nr�ir�cs�Zt�D�FN�OR�FS�D�_c�dg�il�dl�_m�D� �D�:����Z^� 8�C� 8�X�e�C�QU�I�FV�=W� 8�cg�hk�cl� 8� � 8�����!� �#�59� .��.� �S�M�.� �S�M�.���}� .� !��s�D�y�!1�2� .�  � .� �.�2����!��59� #F��#F� �S�M�#F��#F�!��s�D�y�!1�2� #F�  �$�Z� #F� �#F�J�����59� � <��<��<�!��s�D�y�!1�2�<� �S�M� <�  �#�s�(�^� <� �<�.����Z^�$ �C�$ �X�e�C�QU�I�FV�=W�$ �cg�hk�mp�hp�cq�$ � �$ �L���� �s� �s� �� �����#�59� � = ��= ��s�m�= �!��s�D�y�!1�2�= � �S�M� = �  �#�s�(�^� = � �= 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/athapong/argus'

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