CodeGraphContext is an MCP server that builds a knowledge graph from your local codebase, enabling AI assistants to understand your code's structure and relationships. It indexes your code into a Neo4j graph database and provides powerful querying capabilities to analyze code relationships, dependencies, and more.
Install the package using pip:
pip install codegraphcontext
Run the interactive setup wizard:
cgc setup
This wizard will guide you through:
The setup wizard can automatically configure:
If the cgc command is not found after installation, you may need to run a PATH fix script:
Linux/Mac:
curl -O https://raw.githubusercontent.com/Shashankss1205/CodeGraphContext/main/scripts/post_install_fix.sh
chmod +x post_install_fix.sh
./post_install_fix.sh
source ~/.bashrc # or ~/.zshrc for zsh users
Windows (PowerShell):
curl -O https://raw.githubusercontent.com/Shashankss1205/CodeGraphContext/main/scripts/post_install_fix.sh
bash post_install_fix.sh
. $PROFILE
Start the CodeGraphContext server:
cgc start
Create a .cgcignore file in your project root to exclude files from indexing. The syntax is similar to .gitignore:
# Ignore build artifacts
/build/
/dist/
# Ignore dependencies
/node_modules/
/vendor/
# Ignore logs
*.log
If automatic configuration doesn't work for your tool, add this to your client's settings file:
{
"mcpServers": {
"CodeGraphContext": {
"command": "cgc",
"args": [
"start"
],
"env": {
"NEO4J_URI": "YOUR_NEO4J_URI",
"NEO4J_USERNAME": "YOUR_NEO4J_USERNAME",
"NEO4J_PASSWORD": "YOUR_NEO4J_PASSWORD"
},
"tools": {
"alwaysAllow": [
"add_code_to_graph",
"add_package_to_graph",
"check_job_status",
"list_jobs",
"find_code",
"analyze_code_relationships",
"watch_directory",
"find_dead_code",
"execute_cypher_query",
"calculate_cyclomatic_complexity",
"find_most_complex_functions",
"list_indexed_repositories",
"delete_repository",
"visualize_graph_query",
"list_watched_paths",
"unwatch_directory"
],
"disabled": false
},
"disabled": false,
"alwaysAllow": []
}
}
}
Once the server is running, you can interact with it through your AI assistant using natural language:
To index a project:
/path/to/my-project directory."~/dev/my-other-project to the code graph."To watch a directory for live changes:
/path/to/my-active-project directory for changes."~/dev/main-app."When you ask to watch a directory, the system:
Finding code:
process_payment function?"User class for me."Analyzing relationships:
get_user_by_id function?"calculate_tax function, what other parts of the code will be affected?"BaseController class."Order class have?"Exploring dependencies:
requests library?"render method."Advanced call chain analysis:
main function to process_data."validate_input."initialize_system eventually calls?"Code quality assessment:
process_data function in src/utils.py."Repository management:
/path/to/old-project."To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "CodeGraphContext" '{"command":"cgc","args":["start"],"env":{"NEO4J_URI":"************","NEO4J_USER":"************","NEO4J_PASSWORD":"**************"},"tools":{"alwaysAllow":["list_imports","add_code_to_graph","add_package_to_graph","check_job_status","list_jobs","find_code","analyze_code_relationships","watch_directory","find_dead_code","execute_cypher_query"],"disabled":false},"disabled":false,"alwaysAllow":[]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:
{
"mcpServers": {
"CodeGraphContext": {
"command": "cgc",
"args": [
"start"
],
"env": {
"NEO4J_URI": "************",
"NEO4J_USER": "************",
"NEO4J_PASSWORD": "**************"
},
"tools": {
"alwaysAllow": [
"list_imports",
"add_code_to_graph",
"add_package_to_graph",
"check_job_status",
"list_jobs",
"find_code",
"analyze_code_relationships",
"watch_directory",
"find_dead_code",
"execute_cypher_query"
],
"disabled": false
},
"disabled": false,
"alwaysAllow": []
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json2. Add this to your configuration file:
{
"mcpServers": {
"CodeGraphContext": {
"command": "cgc",
"args": [
"start"
],
"env": {
"NEO4J_URI": "************",
"NEO4J_USER": "************",
"NEO4J_PASSWORD": "**************"
},
"tools": {
"alwaysAllow": [
"list_imports",
"add_code_to_graph",
"add_package_to_graph",
"check_job_status",
"list_jobs",
"find_code",
"analyze_code_relationships",
"watch_directory",
"find_dead_code",
"execute_cypher_query"
],
"disabled": false
},
"disabled": false,
"alwaysAllow": []
}
}
}
3. Restart Claude Desktop for the changes to take effect