Skip to main content
Glama

GitHub Chat MCP

by AsyncFuncAI
server.cpython-310.pyc3.23 kB
o ���g�� @sddlZddlZddlZddlmZmZmZmZddlm Z ddl m Z dZ ej �dd�Ze dd d gd �Ze��e d d �fdedefdd��Ze��e dd �e dd �e ddd�fdededeeeeefdefdd��Zdeeefdefdd�Zdd�Zedkr�e�dSdS) �N)�List�Dict�Any�Optional)�FastMCP)�Fieldzhttps://api.github-chat.comZGITHUB_API_KEY�zgithub-chat-mcp�requestszmcp[cli])� dependencieszNThe GitHub repository URL to index (format: https://github.com/username/repo).)� description�repo_url�returnc Cs�z1|std��|�d�std��tjt�d�ddid|id�}|jd kr+d |j��WSd |�d �WStyN}zd t|�pAt |���WYd}~Sd}~ww)zrIndex a GitHub repository to analyze its codebase. This must be done before asking questions about the repository.zRepository URL cannot be empty.�https://github.com/�FRepository URL must be in the format: https://github.com/username/repoz/verify� Content-Type�application/jsonr ��headers�json��zError indexing repository: z!Successfully indexed repository: z2. You can now ask questions about this repository.�Error: N) � ValueError� startswithr �post�GITHUB_CHAT_API_BASE� status_code�text� Exception�str�repr)r �response�e�r"�3/Users/sheing/kagimcp/src/github_chat_mcp/server.py�index_repositorys" � "��r$zNThe GitHub repository URL to query (format: https://github.com/username/repo).z)The question to ask about the repository.z;Previous conversation history for multi-turn conversations.)r �default�question�conversation_historyc Cs�zD|r|s td��|�d�std��|pg}|�d|d��tjt�d�ddi||d �d �}|jd kr:d |j��WS|��}t |�}|WSt ya}zd t |�pTt |���WYd}~Sd}~ww)zpAsk questions about a GitHub repository and receive detailed AI responses. The repository must be indexed first.z,Repository URL and question cannot be empty.rr�user)�role�contentz/chat/completions/syncrr)r �messagesrrzError querying repository: rN) rr�appendr rrrrr�format_chat_responserrr)r r&r'r+r �resultZformatted_responser!r"r"r#�query_repository.s.  �� "��r/r cCs�d}d|vr||dd7}d|vr>|dr>|d7}t|dd�D]\}}d|vr=d|dvr=||�d |dd�d �7}q!|��S) z+Format the chat response in a readable way.rZanswerz �contextsz Sources: �Z meta_data� file_pathz. � )� enumerate�strip)r � formatted�i�contextr"r"r#r-]s�r-cCs t��dS)N)�mcp�runr"r"r"r#�mainms r;�__main__)r�osr �typingrrrr�mcp.server.fastmcpr�pydanticrr�environ�getZAPI_KEYr9�toolrr$r/r-r;�__name__r"r"r"r#�<module>sT  ��� �������� �. �

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/AsyncFuncAI/github-chat-mcp'

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