Skip to main content
Glama

initialize_graph

Initialize a code graph for repository analysis to map function relationships and dependencies, enabling AI assistants to explore code structure effectively.

Instructions

Initialize a code graph for the given repository path.

Args: repo_path: Path to the repository to analyze

Returns: Success message with information about the initialized graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repo_pathYes

Implementation Reference

  • The handler function for the 'initialize_graph' tool, including the @mcp.tool() decorator which also serves as registration. This function initializes a CodeGraph for the given repository path, stores it globally, sets it as active, and counts Python files.
    @mcp.tool()
    def initialize_graph(repo_path: str) -> str:
        """Initialize a code graph for the given repository path.
    
        Args:
            repo_path: Path to the repository to analyze
    
        Returns:
            Success message with information about the initialized graph
        """
        global _code_graphs, _active_repo
    
        # Check if path exists
        if not os.path.exists(repo_path):
            return f"Error: Path '{repo_path}' does not exist"
        
        # Use absolute path as key
        abs_path = os.path.abspath(repo_path)
    
        try:
            result = CodeGraph.init(repo_path)
    
            if result.errors:
                error_messages = [str(error) for error in result.errors]
                return f"Errors initializing code graph:\n" + "\n".join(error_messages)
    
            _code_graphs[abs_path] = result.code_graph
            _active_repo = abs_path
    
            # Count Python files
            py_files = glob.glob(f"{repo_path}/**/*.py", recursive=True)
    
            return (
                f"Successfully initialized code graph for {repo_path}.\n"
                f"Repository contains {len(py_files)} Python files.\n"
                f"This is now the active repository."
            )
        except Exception as e:
            return f"Error initializing code graph: {str(e)}"
  • The @mcp.tool() decorator registers the initialize_graph function as an MCP tool.
    @mcp.tool()
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/mattmorgis/nuanced-mcp'

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