Skip to main content
Glama
T-NhanNguyen

GraphRAG Llama Index MCP Server

by T-NhanNguyen
README.md
# GraphRAG LlamaIndex

Full-stack GraphRAG engine optimized for local indexing and lightweight cloud querying. Built on DuckDB, LlamaIndex, and the Model Context Protocol (MCP).

## 1. Context

This project implements a **Decoupled Architecture**:

- **Indexer (Image A)**: Heavy-duty ML environment (PyTorch, GLiNER) for local graph construction.
- **Query (Image B)**: Lightweight API environment (Node.js, DuckDB) for fast cloud deployment (~1GB footprint).

## 2. Building the Images

```bash
# Build specialized images via Docker Compose
docker compose build
```

## 3. Running Indexer & Query

Load the shell aliases for the fastest workflow:

- **macOS (Zsh)**: `source .graphrag-alias.zsh`
- **WSL/Bash**: `source .graphrag-alias.sh`
- **PowerShell**: `. .\.graphrag-alias.ps1`

### Indexing Documents

```bash
# 1. Initialize a database entry
graphrag start my_project --source /app/documents/source_files

# 2. Run the ingestion pipeline (Indexer Image)
graphrag index my_project [--reset] [--prune]
```

### Querying

```bash
# CLI Search (Query Image)
graphrag search my_project "What are the common themes?"

# Start MCP Server for Agents
docker compose up query
```

## 4. Deployment Folder

- `deployment/fly/`: Scripts for zero-latency hosting on Fly.io (optimized for free-tier fly-machines).
- `deployment/aws/`: Infrastructure scripts for ECR, S3 backups, and App Runner deployments.

## 5. Setup & Configuration

### Environment (.env)

Copy `.env.example` and set:

- `OPENAI_API_KEY`: For LLM reasoning and extraction.
- `DOCUMENTS_HOME`: Absolute path to your local data folder (mapped to `/app/documents` in Docker).

### Engine Configuration (core/graphrag_config.py)

Tweak these parameters to refine performance:

- **`SearchType`**: Switch between `entity_connections` (graph-heavy) or `thematic_overview` (summary-heavy).
- **`ExtractionMode`**: Choose `llm` (creative) or `gliner` (fast/cost-effective).

## 6. Local Integration & Testing

Integrate this project as an **MCP Server** in Desktop Agents (Claude Desktop, Cursor, etc.) to give them memory of your documents.

**Add to your MCP Config:**

```json
{
  "mcpServers": {
    "graphrag": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-v",
        "C:/Users/<USER>/.graphrag:/root/.graphrag",
        "graphrag-query"
      ]
    }
  }
}
```

## 7. Database Cheatsheet

### Core Commands

- `graphrag list`: Show all registered databases.
- `graphrag status <db>`: Check entity/relationship counts and health.
- `graphrag delete <db> [--files]`: Unregister database entry and optionally remove physical files.
- `graphrag index <db> [--reset]`: Index documents into database (use `--reset` to skip duplicate checks).

### Managed Storage Workflow

To keep your project portable, move database files into a `Managed/` folder inside your data directory.

**Manual Move:**

1. Move `your_db.duckdb` to `[DOCUMENTS_HOME]/Managed/`.
2. Re-register the path:

```bash
graphrag register my_db --db-path /app/documents/Managed/your_db.duckdb
```

---

_For S3 management see [S3_CHEATSHEET.md](deployment/aws/S3_CHEATSHEET.md)._

TDQS

A4.1/5.0

Scored across 3 tools

Disambiguation5/5

Each tool has a clearly distinct purpose with no ambiguity: explore_entity_graph is for graph traversal from a specific entity, get_corpus_stats is for corpus-level statistics, and search is for querying the knowledge base with three distinct modes (keyword_lookup, entity_connections, thematic_overview). The tools do not overlap in functionality.

Naming Consistency4/5

The tool names follow a consistent snake_case pattern (explore_entity_graph, get_corpus_stats, search), but 'search' is a generic verb compared to the more descriptive 'explore' and 'get', which is a minor deviation. Overall, the naming is predictable and readable.

Tool Count3/5

With only 3 tools, the server feels thin for a GraphRAG system, as it might lack operations like updating or managing the knowledge base. However, the tools cover core query and exploration functions, making it borderline appropriate for basic usage.

Completeness4/5

The tool surface covers key operations for querying and exploring a GraphRAG knowledge base, including graph traversal, corpus statistics, and multi-mode search. Minor gaps exist, such as no tools for adding or modifying data, but agents can work around this for read-only analysis.

Maintenance

ActivityInactive
ResponsivenessNo issues