Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@



An MCP server that indexes local code into a graph database to provide context to AI assistants.
A powerful **MCP server** and **CLI tool** that indexes local code into a graph database to provide context to AI assistants and developers. Use it as a standalone CLI for code analysis or connect it to your favorite AI IDE via MCP.

### Indexing a codebase
![Indexing using an MCP client](https://github.com/Shashankss1205/CodeGraphContext/blob/main/images/Indexing.gif)
Expand All @@ -43,6 +43,7 @@ An MCP server that indexes local code into a graph database to provide context t
- **Relationship Analysis:** Query for callers, callees, class hierarchies, call chains and more.
- **Live Updates:** Watches local files for changes and automatically updates the graph.
- **Interactive Setup:** A user-friendly command-line wizard for easy setup.
- **Dual Mode:** Works as a standalone **CLI tool** for developers and as an **MCP server** for AI agents.
- **Multi-Language Support:** Full support for 11 programming languages.
- **Flexible Database Backend:** Choose between Neo4j or FalkorDB Lite.

Expand Down Expand Up @@ -81,8 +82,8 @@ CodeGraphContext supports two graph database backends:
- Perfect for quick testing and development
- Automatically installed when using Python 3.12 or higher

The `cgc setup` wizard helps you configure neo4j database backend while the falkordb database is
supported inherently.
The `cgc neo4j setup` wizard helps you configure neo4j database backend while the falkordb database is
supported inherently (enabled by default).

## Used By

Expand Down Expand Up @@ -116,8 +117,8 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
## Getting Started

1. **Install:** `pip install codegraphcontext`
2. **Setup:** `cgc setup`
This interactive command guides you through configuring your Neo4j database connection and automatically setting up your IDE.
2. **Setup:** `cgc mcp setup`
This command configures your IDE to work with CodeGraphContext. To configure a Neo4j database, use `cgc neo4j setup`.

<details>
<summary>⚙️ Troubleshooting: In case, command <code>cgc</code> not found</summary>
Expand Down Expand Up @@ -155,7 +156,7 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a

**Database Configuration:**
* **Local Setup (Docker Recommended):** Helps you set up a local Neo4j instance using Docker. Requires Docker and Docker Compose to be installed.
* **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc setup` can automate the installation of Neo4j. Requires `sudo` privileges.
* **Local Setup (Linux Binary):** For Debian-based Linux systems (like Ubuntu), `cgc neo4j setup` can automate the installation of Neo4j. Requires `sudo` privileges.
* **Hosted Setup:** Allows you to connect to an existing remote Neo4j database (e.g., Neo4j AuraDB).

**IDE/CLI Configuration:**
Expand All @@ -170,12 +171,12 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
* RooCode
* Amazon Q Developer

Upon successful configuration, `cgc setup` will generate and place the necessary configuration files:
Upon successful configuration, `cgc mcp setup` will generate and place the necessary configuration files:
* It creates an `mcp.json` file in your current directory for reference.
* It stores your Neo4j credentials securely in `~/.codegraphcontext/.env`.
* It updates the settings file of your chosen IDE/CLI (e.g., `.claude.json` or VS Code's `settings.json`).

3. **Start:** `cgc start`
3. **Start:** `cgc mcp start`

## Ignoring Files (`.cgcignore`)

Expand All @@ -197,7 +198,7 @@ You can tell CodeGraphContext to ignore specific files and directories by creati

## MCP Client Configuration

The `cgc setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
The `cgc mcp setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.

Add the following server configuration to your client's settings file (e.g., VS Code's `settings.json` or `.claude.json`):

Expand Down
199 changes: 59 additions & 140 deletions docs/docs/cli.md
Original file line number Diff line number Diff line change
@@ -1,142 +1,61 @@
# CLI Reference

The CodeGraphContext CLI provides a set of commands to manage the server, index your code, and interact with the code graph.

## `cgc setup`

Runs the interactive setup wizard to configure the server and database connection. This helps users set up a local Docker-based Neo4j instance or connect to a remote one.

**Usage:**
```bash
cgc setup
```

## `cgc start`

Starts the CodeGraphContext MCP server, which listens for JSON-RPC requests from stdin.

**Usage:**
```bash
cgc start
```

## `cgc index [PATH]`

Indexes a directory or file by adding it to the code graph. If no path is provided, it indexes the current directory.

**Arguments:**
* `PATH` (optional): Path to the directory or file to index. Defaults to the current directory.

**Usage:**
```bash
cgc index /path/to/your/project
```

### Ignoring Files (`.cgcignore`)

You can tell CodeGraphContext to ignore specific files and directories by creating a `.cgcignore` file in the root of your project. This file uses the same syntax as `.gitignore`.

When you run `cgc index`, the command will look for a `.cgcignore` file in the directory being indexed and exclude any files or directories that match the patterns in the file.

**Example `.cgcignore` file:**
```
# Ignore build artifacts
/build/
/dist/

# Ignore dependencies
/node_modules/
/vendor/

# Ignore logs
*.log
```


## `cgc delete <PATH>`

Deletes a repository from the code graph.

**Arguments:**
* `PATH` (required): Path of the repository to delete from the code graph.

**Usage:**
```bash
cgc delete /path/to/your/project
```

## `cgc visualize [QUERY]`

Generates a URL to visualize a Cypher query in the Neo4j Browser. If no query is provided, a default query will be used.

**Arguments:**
* `QUERY` (optional): The Cypher query to visualize.

**Usage:**
```bash
cgc visualize "MATCH (n) RETURN n"
```

## `cgc list_repos`

Lists all indexed repositories.

**Usage:**
```bash
cgc list_repos
```

## `cgc add_package <PACKAGE_NAME>`

Adds a Python package to the code graph.

**Arguments:**
* `PACKAGE_NAME` (required): Name of the Python package to add.

**Usage:**
```bash
cgc add_package requests
```

## `cgc cypher <QUERY>`

Executes a read-only Cypher query.

**Arguments:**
* `QUERY` (required): The read-only Cypher query to execute.

**Usage:**
```bash
cgc cypher "MATCH (n:Function) RETURN n.name"
```

## `cgc list_mcp_tools`

Lists all available tools and their descriptions.

**Usage:**
```bash
cgc list_mcp_tools
```

## `cgc help`

Show the main help message and exit.

**Usage:**
```bash
cgc help
```

## `cgc version`

Show the application version.

**Usage:**
```bash
cgc --version
```
or
```bash
cgc version
```
The CodeGraphContext CLI provides a comprehensive command-line interface to manage the server, index your code, search, analyzing and interact with the code graph.

## 1. Project Management
Use these commands to manage the repositories in your code graph.

| Command | Arguments | Description |
| :--- | :--- | :--- |
| **`cgc index`** | `[path]` <br> `--force` | Adds a repository to the graph. Default path is current directory. Use `--force` to re-index from scratch. <br> *(Alias: `cgc i`)* |
| **`cgc list`** | None | Lists all repositories currently indexed in the database. <br> *(Alias: `cgc ls`)* |
| **`cgc delete`** | `[path]` <br> `--all` | Removes a repository from the graph. Use `--all` to wipe everything. <br> *(Alias: `cgc rm`)* |
| **`cgc stats`** | `[path]` | Shows indexing statistics (node counts) for the DB or a specific repo. |
| **`cgc clean`** | None | Removes orphaned nodes and cleans up the database. |
| **`cgc add-package`** | `<name> <lang>` | Manually adds an external package node (e.g., `cgc add-package requests python`). |

## 2. Code Analysis
Understand the structure, quality, and relationships of your code.

| Command | Arguments | Description |
| :--- | :--- | :--- |
| **`cgc analyze calls`** | `<func_name>` <br> `--file` | Shows **outgoing** calls: what functions does this function call? |
| **`cgc analyze callers`** | `<func_name>` <br> `--file` | Shows **incoming** calls: who calls this function? |
| **`cgc analyze chain`** | `<start> <end>` <br> `--depth` | Finds the call path between two functions. Default depth is 5. |
| **`cgc analyze deps`** | `<module>` <br> `--no-external` | Inspects dependencies (imports and importers) for a module. |
| **`cgc analyze tree`** | `<class_name>` <br> `--file` | Visualizes the Class Inheritance hierarchy for a given class. |
| **`cgc analyze complexity`**| `[path]` <br> `--threshold` <br> `--limit` | Lists functions with high Cyclomatic Complexity. Default threshold: 10. |
| **`cgc analyze dead-code`** | `--exclude` | Finds potentially unused functions (0 callers). Use `--exclude` for decorators. |

## 3. Discovery & Search
Find code elements when you don't know the exact structure.

| Command | Arguments | Description |
| :--- | :--- | :--- |
| **`cgc find name`** | `<name>` <br> `--type` | Finds code elements (Class, Function) by their **exact** name. |
| **`cgc find pattern`** | `<pattern>` <br> `--case-sensitive` | Finds elements using fuzzy substring matching (e.g. "User" finds "UserHelper"). |
| **`cgc find type`** | `<type>` <br> `--limit` | Lists all nodes of a specific type (e.g. `function`, `class`, `module`). |

## 4. Configuration & Setup
Manage your environment and database connections.

| Command | Arguments | Description |
| :--- | :--- | :--- |
| **`cgc mcp setup`** | None | Configures your IDE/MCP Client. Creates `mcp.json`. <br> *(Alias: `cgc m`)* |
| **`cgc neo4j setup`** | None | Wizard to configure a Neo4j connection. <br> *(Alias: `cgc n`)* |
| **`cgc config show`** | None | Displays current configuration values. |
| **`cgc config set`** | `<key> <value>` | Sets a config value (e.g. `DEFAULT_DATABASE`). |
| **`cgc config reset`** | None | Resets configuration to defaults. |
| **`cgc config db`** | `<backend>` | Quick switch between `neo4j` and `falkordb`. |

## 5. Utilities & Runtime
Helper commands for developers and the MCP server.

| Command | Arguments | Description |
| :--- | :--- | :--- |
| **`cgc doctor`** | None | Runs system diagnostics (DB connection, dependencies, permissions). |
| **`cgc visualize`** | `[query]` | Generates a link to open the Neo4j Browser. <br> *(Alias: `cgc v`)* |
| **`cgc query`** | `<query>` | Executes a raw Cypher query directly against the DB. |
| **`cgc mcp start`** | None | Starts the MCP Server (used by IDEs). |
| **`cgc mcp tools`** | None | Lists all available MCP tools supported by the server. |
| **`cgc start`** | None | **Deprecated**. Use `cgc mcp start` instead. |
12 changes: 7 additions & 5 deletions docs/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ This is the official documentation for CodeGraphContext.



An MCP server that indexes local code into a graph database to provide context to AI assistants.
A powerful **CLI tool** and **MCP server** that indexes local code into a graph database to provide context to AI assistants and developers. Use it as a standalone CLI for code analysis or connect it to your favorite AI IDE via MCP.

### Indexing a codebase
### Indexing a codebase (CLI or MCP)
![Indexing using an MCP client](images/Indexing.gif)

### Using the MCP server
Expand Down Expand Up @@ -79,8 +79,9 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
2. **Configure Your Environment:**
Run the interactive setup wizard to connect to your database and configure your IDE:
```bash
cgc setup
cgc mcp setup
```
This ensures your IDE is configured. To configure a Neo4j database, use `cgc neo4j setup`.
The wizard helps you with:
- **Database Connection:**
- **Docker (Recommended):** Automatically sets up a local Neo4j instance.
Expand All @@ -90,11 +91,11 @@ If you’re using CodeGraphContext in your project, feel free to open a PR and a
- Automatically configures tools like VS Code, Cursor, Gemini CLI, and more.
- Generates the necessary `mcp.json` and `.env` files for you.

3. **Start:** `cgc start`
3. **Start:** `cgc mcp start`

## MCP Client Configuration

The `cgc setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.
The `cgc mcp setup` command attempts to automatically configure your IDE/CLI. If you choose not to use the automatic setup, or if your tool is not supported, you can configure it manually.

Add the following server configuration to your client's settings file (e.g., VS Code's `settings.json` or `.claude.json`):

Expand All @@ -104,6 +105,7 @@ Add the following server configuration to your client's settings file (e.g., VS
"CodeGraphContext": {
"command": "cgc",
"args": [
"mcp",
"start"
],
"env": {
Expand Down
10 changes: 6 additions & 4 deletions docs/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ Install the `codegraphcontext` package directly from PyPI using pip:
pip install codegraphcontext
```

### 2. Run the Setup Wizard
### 2. Run the Setup Wizard for MCP Client

Launch the interactive setup wizard to configure your Neo4j database and development environment:

```bash
cgc setup
cgc mcp setup
```

This ensures your IDE is configured. To configure a Neo4j database, use `cgc neo4j setup`.

The wizard guides you through a series of intuitive prompts to tailor your setup.

## 🧭 "Step-by-Step Guide for the Setup Wizard"

When you run `cgc setup`, the wizard offers a thoughtful journey through configuration. Follow these steps to complete your setup with ease:
When you run `cgc neo4j setup`, the wizard offers a thoughtful journey through configuration. Follow these steps to complete your setup with ease:

**1. Select Your Database Location**

Expand Down Expand Up @@ -73,7 +75,7 @@ These files ensure smooth communication between CodeGraphContext, your Neo4j ins
Once configuration is complete, launch the MCP server with:

```bash
cgc start
cgc mcp start
```

Your **CodeGraphContext** server is now active, ready to power AI-assisted graph queries.
Expand Down
Loading