Skip to main content
Glama

get_local_repo

Process local repository code into text format for AI analysis and processing, preserving context and structure.

Instructions

Process and return the code from a local repository as text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes

Implementation Reference

  • The main handler function for the 'get_local_repo' MCP tool. It is decorated with @mcp.tool() which serves as both the implementation and registration. Wraps the synchronous LocalRepo2Txt.process_repo in an async executor with timeout handling.
    @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)}"
  • The core helper method called by the tool handler. It processes the local repository by traversing directory structure, collecting file paths, reading text contents (skipping binaries and ignored dirs), and formatting into a string with structure and contents.
    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()
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