Skip to main content
Glama

get_local_repo

Extract and convert code from a local repository into a text format optimized for AI processing, preserving structure and context for enhanced analysis.

Instructions

Process and return the code from a local repository as text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes

Implementation Reference

  • The main tool handler for 'get_local_repo', decorated with @mcp.tool(). It creates a LocalRepo2Txt instance, calls process_repo asynchronously with a 300s timeout, and returns the formatted repo content or error message.
    @mcp.tool() async def get_local_repo(repo_path: str)->str: """ Process and return the code from a local repository as text """ try: # Create an event loop loop = asyncio.get_event_loop() # Wrap synchronous operation in async operation with 300 seconds (5 minutes) timeout repo_processor = LocalRepo2Txt() repo_name, content = await asyncio.wait_for( loop.run_in_executor(None, repo_processor.process_repo, repo_path), timeout=300 ) return content except asyncio.TimeoutError: return "Processing timeout, please check repository size or file count" except Exception as e: return f"Processing failed: {str(e)}"
  • Core helper method in LocalRepo2Txt class that processes the local repository: generates structure, reads non-binary files (skipping ignored dirs and binaries), formats with instructions, and returns repo_name and content string.
    def process_repo(self, repo_path): """ 处理本地仓库并返回处理后的内容 Args: repo_path (str): 本地仓库路径 Returns: tuple: (repo_name, content_string) - 仓库名和处理后的内容字符串 """ repo_name = os.path.basename(repo_path) # print(f"Fetching repository structure for: {repo_name}") repo_structure = f"Repository Structure: {repo_name}\n" repo_structure += self._traverse_local_repo_iteratively(repo_path) repo_structure = repo_structure.replace(repo_path, '.') # print(f"\nFetching file contents for: {repo_name}") file_contents = self._get_local_file_contents_iteratively(repo_path) instructions = "Use the files and contents provided below to complete this analysis:\n\n" # 组合所有内容 content = ( instructions + repo_structure + '\n\n' + file_contents ) return repo_name, content
  • The @mcp.tool() decorator registers the get_local_repo function as an MCP tool.
    @mcp.tool()
  • Input schema: repo_path: str (local repository path). Output: str (processed repo content or error). Includes docstring description.
    async def get_local_repo(repo_path: str)->str: """ Process and return the code from a local repository as text """

Other Tools

Related 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