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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes |
Implementation Reference
- mcp-repo2llm-server.py:56-74 (handler)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)}"
- repo2llm/localrepo2txt.py:95-126 (helper)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
- mcp-repo2llm-server.py:56-56 (registration)The @mcp.tool() decorator registers the get_local_repo function as an MCP tool.@mcp.tool()
- mcp-repo2llm-server.py:57-60 (schema)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 """