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
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes |
Implementation Reference
- nuanced_mcp_server.py:25-64 (handler)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)}"
- nuanced_mcp_server.py:25-25 (registration)The @mcp.tool() decorator registers the initialize_graph function as an MCP tool.@mcp.tool()