Skip to main content
Glama
puravparab

Gitingest-MCP

by puravparab

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
NameRequiredDescriptionDefault
branchNo
ownerYes
repoYes

Implementation Reference

  • 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"
    		}
  • 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
  • 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)
Install Server

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/puravparab/Gitingest-MCP'

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