Skip to main content
Glama

get_gitlab_repo

Extract and process code from a GitLab repository branch as structured text for AI analysis and processing.

Instructions

Process and return the code from a GitLab repository branch as text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_urlYes
branchNomaster

Implementation Reference

  • The tool handler function for 'get_gitlab_repo', decorated with @mcp.tool() for registration, which creates a GitlabRepo2Txt instance and invokes its process_repo method to retrieve and format 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
  • The process_repo method of the GitlabRepo2Txt class, which performs the core work of fetching README, repository structure, and non-binary file contents from a GitLab repository using the GitLab API.
    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
Install Server

Other Tools

Latest Blog Posts

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/crisschan/mcp-repo2llm'

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