CodeGraphContext MCP server

Indexes Python codebases into a Neo4j graph database to enable sophisticated code analysis including function relationships, class hierarchies, dead code detection, and dependency tracking through real-time file monitoring and direct Cypher queries.
Back to servers
Setup instructions
Provider
Shashank Shekhar Singh
Release date
Aug 17, 2025
Language
JavaScript
Stats
201 stars

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.

Installation

Prerequisites

  • Python 3.7+
  • Neo4j database (local or hosted)
  • Docker (recommended for local Neo4j setup)

Installing CodeGraphContext

Install the package using pip:

pip install codegraphcontext

Setup

Run the interactive setup wizard:

cgc setup

This wizard will guide you through:

  1. Configuring your Neo4j database connection
  2. Setting up your IDE integration

Database Configuration Options

  • Local Setup with Docker: The recommended approach that helps you set up a Neo4j instance using Docker
  • Local Setup with Linux Binary: For Debian-based systems, automates Neo4j installation (requires sudo)
  • Hosted Setup: Connects to an existing remote Neo4j database like Neo4j AuraDB

IDE/CLI Configuration

The setup wizard can automatically configure:

  • VS Code
  • Cursor
  • Windsurf
  • Claude
  • Gemini CLI
  • ChatGPT Codex
  • Cline
  • RooCode
  • Amazon Q Developer

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

Usage

Starting the Server

Start the CodeGraphContext server:

cgc start

Ignoring Files

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

Manual MCP Client Configuration

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": []
    }
  }
}

Interacting with CodeGraphContext

Once the server is running, you can interact with it through your AI assistant using natural language:

Indexing and Watching Files

To index a project:

  • "Please index the code in the /path/to/my-project directory."
  • "Add the project at ~/dev/my-other-project to the code graph."

To watch a directory for live changes:

  • "Watch the /path/to/my-active-project directory for changes."
  • "Keep the code graph updated for the project I'm working on at ~/dev/main-app."

When you ask to watch a directory, the system:

  1. Performs a full scan to index all code (runs in background)
  2. Begins watching the directory for real-time updates

Querying and Understanding Code

Finding code:

  • "Where is the process_payment function?"
  • "Find the User class for me."
  • "Show me any code related to 'database connection'."

Analyzing relationships:

  • "What other functions call the get_user_by_id function?"
  • "If I change the calculate_tax function, what other parts of the code will be affected?"
  • "Show me the inheritance hierarchy for the BaseController class."
  • "What methods does the Order class have?"

Exploring dependencies:

  • "Which files import the requests library?"
  • "Find all implementations of the render method."

Advanced call chain analysis:

  • "Show me the full call chain from the main function to process_data."
  • "Find all functions that directly or indirectly call validate_input."
  • "What are all the functions that initialize_system eventually calls?"

Code quality assessment:

  • "Is there any dead or unused code in this project?"
  • "Calculate the cyclomatic complexity of the process_data function in src/utils.py."
  • "Find the 5 most complex functions in the codebase."

Repository management:

  • "List all currently indexed repositories."
  • "Delete the indexed repository at /path/to/old-project."

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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": []
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. 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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later