Skip to main content
Glama

explore_repo

Analyze codebase structure and extract function/class signatures to understand project organization and locate relevant code components.

Instructions

πŸ—ΊοΈ STEP 1: Map the codebase structure - start simple, then zoom in!

PROGRESSIVE DISCOVERY WORKFLOW:

  1. First call: explore_repo("/path/to/project") - See directory structure only

  2. Zoom in: explore_repo("/path/to/project", focus_dirs=["src"], include_symbols=True)

  3. Go deeper: explore_repo("/path/to/project", max_depth=3, include_symbols=True)

INPUTS:

  • root_path: The ABSOLUTE path to the project (e.g., "/Users/john/myproject") NOT relative paths like "./myproject" or "~/myproject"

  • max_depth: How deep to traverse directories (None = unlimited, accepts int or string)

  • include_symbols: Show function/class signatures with docs (False = dirs only, accepts bool or string)

  • focus_dirs: List of top-level directories to focus on (e.g., ["src", "lib"])

  • max_symbols_per_file: Max symbols to show per file when include_symbols=True (accepts int or string)

EXAMPLE 1 - Initial exploration (directory only): explore_repo("/Users/john/project")

Returns:

/Users/john/project/

β”œβ”€β”€ src/

β”œβ”€β”€ tests/

β”œβ”€β”€ docs/

└── README.md

EXAMPLE 2 - Zoom into src/ with symbols: explore_repo("/Users/john/project", focus_dirs=["src"], include_symbols=True)

Returns:

/Users/john/project/

└── src/

β”œβ”€β”€ auth.py

β”‚ β”œβ”€β”€ class AuthService: # Handles user authentication

β”‚ β”œβ”€β”€ def authenticate(username, password): # Validates credentials

β”‚ └── def logout(session_id): # Ends user session

└── models.py

β”œβ”€β”€ class User(BaseModel): # User account model

└── ... and 3 more

EXAMPLE 3 - Limited depth exploration: explore_repo("/Users/john/project", max_depth=1, include_symbols=True)

Shows only top-level dirs and files with their symbols

πŸ’‘ PRO TIP: Start with include_symbols=False to see structure, then set it to True for areas you want to examine in detail. This prevents information overload!

⚑ PERFORMANCE: Symbol extraction is cached per git commit - subsequent calls are instant!

WHAT TO DO NEXT:

  • If you found interesting directories, zoom in with focus_dirs

  • If you see relevant files, use find_symbol() to locate specific functions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
root_pathYes
max_depthNo
include_symbolsNo
focus_dirsNo
max_symbols_per_fileNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'explore_repo'. Registers the tool with FastMCP, handles parameter conversion for LLM compatibility, retrieves or creates XRayIndexer instance, and calls its explore_repo method to generate the repository tree.
    @mcp.tool
    def explore_repo(
        root_path: str, 
        max_depth: Optional[Union[int, str]] = None,
        include_symbols: Union[bool, str] = False,
        focus_dirs: Optional[List[str]] = None,
        max_symbols_per_file: Union[int, str] = 5
    ) -> str:
        """
        πŸ—ΊοΈ STEP 1: Map the codebase structure - start simple, then zoom in!
        
        PROGRESSIVE DISCOVERY WORKFLOW:
        1. First call: explore_repo("/path/to/project") - See directory structure only
        2. Zoom in: explore_repo("/path/to/project", focus_dirs=["src"], include_symbols=True)
        3. Go deeper: explore_repo("/path/to/project", max_depth=3, include_symbols=True)
        
        INPUTS:
        - root_path: The ABSOLUTE path to the project (e.g., "/Users/john/myproject")
                     NOT relative paths like "./myproject" or "~/myproject"
        - max_depth: How deep to traverse directories (None = unlimited, accepts int or string)
        - include_symbols: Show function/class signatures with docs (False = dirs only, accepts bool or string)
        - focus_dirs: List of top-level directories to focus on (e.g., ["src", "lib"])
        - max_symbols_per_file: Max symbols to show per file when include_symbols=True (accepts int or string)
        
        EXAMPLE 1 - Initial exploration (directory only):
        explore_repo("/Users/john/project")
        # Returns:
        # /Users/john/project/
        # β”œβ”€β”€ src/
        # β”œβ”€β”€ tests/
        # β”œβ”€β”€ docs/
        # └── README.md
        
        EXAMPLE 2 - Zoom into src/ with symbols:
        explore_repo("/Users/john/project", focus_dirs=["src"], include_symbols=True)
        # Returns:
        # /Users/john/project/
        # └── src/
        #     β”œβ”€β”€ auth.py
        #     β”‚   β”œβ”€β”€ class AuthService: # Handles user authentication
        #     β”‚   β”œβ”€β”€ def authenticate(username, password): # Validates credentials
        #     β”‚   └── def logout(session_id): # Ends user session
        #     └── models.py
        #         β”œβ”€β”€ class User(BaseModel): # User account model
        #         └── ... and 3 more
        
        EXAMPLE 3 - Limited depth exploration:
        explore_repo("/Users/john/project", max_depth=1, include_symbols=True)
        # Shows only top-level dirs and files with their symbols
        
        πŸ’‘ PRO TIP: Start with include_symbols=False to see structure, then set it to True
        for areas you want to examine in detail. This prevents information overload!
        
        ⚑ PERFORMANCE: Symbol extraction is cached per git commit - subsequent calls are instant!
        
        WHAT TO DO NEXT:
        - If you found interesting directories, zoom in with focus_dirs
        - If you see relevant files, use find_symbol() to locate specific functions
        """
        try:
            # Convert string inputs to proper types (for LLMs that pass strings)
            if max_depth is not None and isinstance(max_depth, str):
                max_depth = int(max_depth)
            if isinstance(max_symbols_per_file, str):
                max_symbols_per_file = int(max_symbols_per_file)
            if isinstance(include_symbols, str):
                include_symbols = include_symbols.lower() in ('true', '1', 'yes')
                
            indexer = get_indexer(root_path)
            tree = indexer.explore_repo(
                max_depth=max_depth,
                include_symbols=include_symbols,
                focus_dirs=focus_dirs,
                max_symbols_per_file=max_symbols_per_file
            )
            return tree
        except Exception as e:
            return f"Error exploring repository: {str(e)}"
  • The @mcp.tool decorator registers the explore_repo function as an MCP tool with FastMCP.
    @mcp.tool
  • Function signature and docstring define the input schema (parameters with types/defaults) and output (str tree representation) for the MCP tool, used by FastMCP for validation.
    def explore_repo(
        root_path: str, 
        max_depth: Optional[Union[int, str]] = None,
        include_symbols: Union[bool, str] = False,
        focus_dirs: Optional[List[str]] = None,
        max_symbols_per_file: Union[int, str] = 5
    ) -> str:
        """
  • Core helper method in XRayIndexer class that implements the repository exploration logic: parses gitignore, builds recursive tree with optional symbols using _build_tree_recursive_enhanced, handles caching.
    def explore_repo(
        self, 
        max_depth: Optional[int] = None,
        include_symbols: bool = False,
        focus_dirs: Optional[List[str]] = None,
        max_symbols_per_file: int = 5
    ) -> str:
        """
        Build a visual file tree with optional symbol skeletons.
        
        Args:
            max_depth: Limit directory traversal depth
            include_symbols: Include symbol skeletons in output
            focus_dirs: Only include these top-level directories
            max_symbols_per_file: Max symbols to show per file
            
        Returns:
            Formatted tree string
        """
        # Get gitignore patterns if available
        gitignore_patterns = self._parse_gitignore()
        
        # Build the tree
        tree_lines = []
        self._build_tree_recursive_enhanced(
            self.root_path, 
            tree_lines, 
            "", 
            gitignore_patterns,
            current_depth=0,
            max_depth=max_depth,
            include_symbols=include_symbols,
            focus_dirs=focus_dirs,
            max_symbols_per_file=max_symbols_per_file,
            is_last=True
        )
        
        # Save cache after building tree
        if include_symbols:
            self._save_cache()
        
        return "\n".join(tree_lines)
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure and excels. It explains the tool's progressive workflow, caching behavior ('Symbol extraction is cached per git commit - subsequent calls are instant!'), performance implications, and output format through detailed examples. It also clarifies path requirements ('ABSOLUTE path... NOT relative paths') and default behaviors.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (workflow, inputs, examples, tips, next steps) and uses emojis for visual organization. While slightly verbose, every sentence adds value: the workflow guides usage, examples illustrate outputs, tips optimize performance, and next steps connect to sibling tools. It could be more concise but remains highly effective.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is exceptionally complete for a tool with 5 parameters, 0% schema coverage, no annotations, but an output schema. It covers purpose, usage workflow, parameter details, behavioral traits (caching, performance), examples with output formats, and integration with sibling tools. The presence of an output schema means return values don't need explanation, and the description fills all other gaps comprehensively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Given 0% schema description coverage, the description fully compensates by providing comprehensive parameter semantics. Each of the 5 parameters is clearly explained with purpose, constraints, and examples: root_path (absolute vs. relative), max_depth (unlimited vs. limited), include_symbols (dirs only vs. with symbols), focus_dirs (top-level directories to filter), and max_symbols_per_file (limit when symbols shown). The examples demonstrate practical usage of all parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Map the codebase structure - start simple, then zoom in!' It specifies the verb ('explore', 'map') and resource ('repo', 'codebase structure'), and distinguishes it from sibling tools by focusing on structural discovery rather than symbol searching (find_symbol), interface reading (read_interface), or breakage analysis (what_breaks).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when and how to use this tool versus alternatives. It outlines a 'PROGRESSIVE DISCOVERY WORKFLOW' with three steps, advises starting with 'include_symbols=False' to avoid overload, and directs users to 'use find_symbol() to locate specific functions' after exploration. It clearly differentiates from sibling tools by positioning explore_repo as the entry point for structural mapping.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/srijanshukla18/xray'

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