get_gitlab_repo
Extract and process code from a GitLab repository branch, converting it into a text format optimized for LLM input while preserving structure and context.
Instructions
Process and return the code from a GitLab repository branch as text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | master | |
| repo_url | Yes |
Implementation Reference
- mcp-repo2llm-server.py:15-32 (handler)The main handler function for the 'get_gitlab_repo' MCP tool. It is registered via the @mcp.tool() decorator, which also defines the input schema through type annotations and default values. The function instantiates GitlabRepo2Txt processor and invokes its process_repo method to retrieve the repository contents as text.@mcp.tool() async def get_gitlab_repo(repo_url: str, branch: str = "master")->str: """ Process and return the code from a GitLab repository branch as text """ try: repo_processor = GitlabRepo2Txt() repo_name, content = repo_processor.process_repo( repo_url=repo_url, branch=branch # optional parameter ) # logger.info(f"Processed GitLab repository: {repo_name}") # logger.info(f"Processed GitLab content: {content}") return content except Exception as e: # print(f"Error processing GitLab repository: {e}") return None
- repo2llm/gitlibrepo2txt.py:116-152 (helper)Core helper method in the GitlabRepo2Txt class that processes the GitLab repository: extracts README, builds directory structure iteratively, fetches non-binary file contents iteratively, and combines them into a text representation for LLM analysis.def process_repo(self, repo_url, branch='master'): """ 处理GitLab仓库并返回处理后的内容 Args: repo_url (str): GitLab仓库URL branch (str, optional): 分支名称. 默认为 'master' Returns: tuple: (repo_name, content_string) - 仓库名和处理后的内容字符串 """ repo_name = repo_url.split('/')[-1] repo = self.gitlab.projects.get(repo_url.replace('https://gitlab.com/', '')) # print(f"Getting README for {repo_name}") readme_content = self._get_readme_content(repo, branch) # print(f"\nGetting repository structure for {repo_name}") repo_structure = f"Repository structure: {repo_name}\n" repo_structure += self._traverse_repo_iteratively(repo) # print(f"\nGetting file contents for {repo_name}") file_contents = self._get_file_contents_iteratively(repo, branch) instructions = "Use the following files and contents for analysis:\n\n" # 组合所有内容 content = ( instructions + f"README:\n{readme_content}\n\n" + repo_structure + '\n\n' + file_contents ) return repo_name, content