git_tree
Retrieve the tree structure of a GitHub repository by specifying the owner, repository name, and optional branch. Streamline repository analysis and navigation with extracted directory and file details.
Instructions
Get the tree structure of a GitHub repository
Args:
owner: The GitHub organization or username
repo: The repository name
branch: Optional branch name (default: None)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| branch | No | ||
| owner | Yes | ||
| repo | Yes |
Implementation Reference
- src/gitingest_mcp/server.py:48-72 (handler)The handler function for the 'git_tree' tool. It is registered via @mcp.tool() decorator, validates inputs via type hints, fetches repo data using GitIngester, and returns the tree structure or error.@mcp.tool() async def git_tree( owner: str, repo: str, branch: Optional[str] = None ) -> Union[str, Dict[str, str]]: """ Get the tree structure of a GitHub repository Args: owner: The GitHub organization or username repo: The repository name branch: Optional branch name (default: None) """ url = f"https://github.com/{owner}/{repo}" try: # Create GitIngester and fetch data asynchronously ingester = GitIngester(url, branch=branch) await ingester.fetch_repo_data() return ingester.get_tree() except Exception as e: return { "error": f"Failed to get repository tree: {str(e)}. Try https://gitingest.com/{url} instead" }
- src/gitingest_mcp/ingest.py:66-68 (helper)Helper method in GitIngester class that returns the parsed repository tree structure obtained from the external 'ingest' function.def get_tree(self) -> Any: """Returns the repository tree structure.""" return self.tree
- src/gitingest_mcp/ingest.py:17-25 (helper)Helper method that asynchronously fetches the repository data (including tree) by calling the external 'ingest' function.async def fetch_repo_data(self) -> None: """Asynchronously fetch and process repository data.""" # Run the synchronous ingest function in a thread pool loop = asyncio.get_event_loop() summary, self.tree, self.content = await loop.run_in_executor( None, lambda: ingest(self.url) ) self.summary = self._parse_summary(summary)