# Are There Any APIs Exposed by code-review-graph? (Programmatic, CLI, and MCP Server)

> Explore code-review-graph's API options: a Python interface, a CLI tool, and an optional MCP server for remote access. Get programmatic control today.

- Repository: [Tirth Kanani/code-review-graph](https://github.com/tirth8205/code-review-graph)
- Tags: api-reference
- Published: 2026-08-17

---

**Yes. `code-review-graph` exposes a layered API stack: a Python programmatic interface in `GraphStore`, a `crg` command-line interface, and an optional MCP server for remote access.**

The `tirth8205/code-review-graph` library provides multiple interfaces for interacting with its code-knowledge graph. Whether you need to embed graph operations in Python scripts, automate workflows from the shell, or expose graph queries to external tools, the API surface is designed for flexibility.

## Programmatic Python API

The core `code_review_graph.graph.GraphStore` class in [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py) is the primary entry point for programmatic use. It wraps a SQLite-backed graph database and exposes methods for writing, querying, and traversing code relationships.

### Creating and Populating a Graph

```python
from code_review_graph.graph import GraphStore
from code_review_graph.parser import parse_file

# Initialize or open a persistent graph store

store = GraphStore("/tmp/crg.db")

# Parse source files into nodes and edges

nodes, edges = parse_file("src/example.py")

# Bulk-insert into the graph

store.store_file_nodes_edges("src/example.py", nodes, edges)

```

**Key write methods** on `GraphStore` include:

- `upsert_node(node)` – Insert or update a single node
- `upsert_edge(edge)` – Insert or update a single edge
- `store_file_nodes_edges(path, nodes, edges)` – Batch insert for a parsed file

### Querying the Graph

The API supports targeted lookups and complex traversals:

```python

# Retrieve a specific node by qualified name

node = store.get_node("module.ClassName.method_name")

# Keyword-based search across node names and types

results = store.search_nodes(query="auth", language="python")

# Find all edges where `fetch_data` is the target

callers = store.search_edges_by_target_name("fetch_data", kind="CALLS")
print([e.source_qualified for e in callers])

# Get all tests transitively reachable from a function

tests = store.get_transitive_tests("api.handlers.create_user")

```

**Key read methods** include: `get_node()`, `search_nodes()`, `search_edges_by_target_name()`, `get_transitive_tests()`, `get_all_files()`, and `has_nodes_for_language()`.

## Export API

The `code_review_graph.exports` module converts `GraphStore` instances into external formats. Located in [`code_review_graph/exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py), these functions accept a store instance and an output destination.

| Function | Output Format | Use Case |
|----------|-------------|----------|
| `export_json(store, output_path)` | JSON | Machine-readable graph dump |
| `export_graphml(store, output_path)` | GraphML | Visualization in Gephi, yEd, Cytoscape |
| `export_neo4j_cypher(store, output_path)` | Cypher script | Bulk-import into Neo4j |
| `export_obsidian_vault(store, output_dir)` | Markdown vault | Knowledge-base browsing in Obsidian |
| `export_svg(store, output_path)` | SVG image | Static visualization (requires **matplotlib**) |

```python
from pathlib import Path
from code_review_graph.exports import export_neo4j_cypher
from code_review_graph.graph import GraphStore

store = GraphStore("/tmp/crg.db")
export_neo4j_cypher(store, Path("graph.cypher"))

```

## Command-Line Interface (CLI)

The `crg` command provides shell access to all library functionality. Entry point is `code_review_graph.cli.main()`, defined in [`code_review_graph/cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/cli.py).

```bash

# Parse all files under src/ and populate the graph

crg run src/

# Execute graph queries from the shell

crg query --search "auth" --language python
crg query --impact-radius "api.handlers.create_user" --depth 2
crg query --transitive-tests "utils.validate_token"

# Export to any supported format

crg export json --output graph.json
crg export svg --output graph.svg
crg export neo4j --output graph.cypher

```

The CLI sub-commands map directly to `GraphStore` methods and export functions, ensuring behavioral parity between programmatic and command-line usage.

## MCP Server API

For remote or cross-process access, [`code_review_graph/daemon.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/daemon.py) implements an optional MCP (Model Context Protocol) server. This exposes the same `GraphStore` operations over HTTP or socket connections.

```python
from code_review_graph.daemon import run

# Start the server; handles requests using public GraphStore methods

run(host="localhost", port=8080)

```

Once running, external tools can query the graph without embedding Python or managing SQLite connections directly. The daemon uses the same method signatures as the local API, maintaining consistency across deployment modes.

## Helper Utility APIs

Several submodules expose supporting functionality that can be imported directly:

- `code_review_graph.context_savings` – Token estimation and context-savings analysis (e.g., `estimate_context_savings()`)
- `code_review_graph.parser` – `NodeInfo` and `EdgeInfo` dataclass definitions for custom parsing
- `code_review_graph.hints` and `code_review_graph.flow` – Supporting utilities for graph construction and analysis

These are imported by the main API but remain available for advanced use cases.

## API Architecture Summary

| Layer | Location | Best For |
|-------|----------|----------|
| **Core graph operations** | [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py) | Python applications needing full control |
| **Export formats** | [`code_review_graph/exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py) | Integration with external tools |
| **Shell automation** | [`code_review_graph/cli.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/cli.py) (`crg`) | CI/CD pipelines, scripting |
| **Remote access** | [`code_review_graph/daemon.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/daemon.py) | Microservices, distributed tools |

## Summary

- The **programmatic API** centers on `GraphStore` in [`code_review_graph/graph.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/graph.py), with methods for CRUD operations, impact-radius queries, and transitive test discovery.

- The **export API** in [`code_review_graph/exports.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/exports.py) provides five output formats: JSON, GraphML, Neo4j Cypher, Obsidian vault, and SVG.

- The **CLI** (`crg`) wraps all functionality for shell-based workflows, with sub-commands for `run`, `query`, `export`, and `daemon`.

- The **MCP server** in [`code_review_graph/daemon.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/daemon.py) enables remote access without code changes.

- Helper modules expose token estimation, parsing primitives, and flow analysis for extended use.

## Frequently Asked Questions

### Is code-review-graph only a CLI tool?

No. While it provides a `crg` command-line interface, the primary interface is the `GraphStore` Python class. You can embed graph operations directly in applications without invoking subprocesses.

### Can I export the graph to Neo4j?

Yes. Use `export_neo4j_cypher(store, output_path)` from `code_review_graph.exports`, or run `crg export neo4j --output graph.cypher` from the CLI. The output is a Cypher script ready for `neo4j-admin database import` or interactive execution.

### Does the API support incremental updates?

Yes. `GraphStore.upsert_node()` and `GraphStore.upsert_edge()` handle insert-or-update semantics, and `store_file_nodes_edges()` can be called repeatedly on modified files. SQLite transactions ensure atomicity.

### What protocol does the MCP server use?

The daemon in [`code_review_graph/daemon.py`](https://github.com/tirth8205/code-review-graph/blob/main/code_review_graph/daemon.py) exposes an HTTP-based MCP server by default. It serializes `GraphStore` method calls and responses as JSON, allowing any HTTP client to query the graph remotely.