Graph Context

by yuqiaohan95

347 downloads Not rated yet

About

MCP server for intelligent code context — 87%+ token savings, zero resource overhead.

Explore

- AST call graph for precise cross‑file dependency resolution
- BM25 ranking with self‑evolving rules engine
- Dynamic tool loading — only 2 tools at startup (~270 tokens)
- MVCC snapshots for read‑write isolation in multi‑agent setups
- Zero external dependencies: pure CPU, no GPU, no network calls
- Built‑in Chinese‑English synonym mapping for cross‑language queries

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Graph Context
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

pip install graph-context

PROJECT_ROOT=/path/to/project MCP_MAX_TOKENS=4000 MCP_TOP_K=10 graph-context

{
  "mcpServers": {
    "graph-context": {
      "command": "graph-context",
      "env": {
        "PROJECT_ROOT": "/path/to/your/project"
      }
    }
  }
}

Load with: tools(action="load", module="admin")

| Tool | Description |
|------|-------------|
| admin_health | Engine health check (index stats, watcher, cache, MVCC version) |
| admin_config | Get current engine configuration |
| admin_update_config | Update config at runtime |
| snapshot_create | Create MVCC snapshot (COW, no deepcopy) |
| snapshot_read | Read snapshot at a specific version |
| snapshot_status | Get MVCC status |
| scope_create | Create project scope (strict isolation / shared) |
| scope_list | List all project scopes |
| scope_link | Link two projects |
| synonym_add | Add Chinese-English synonym mapping |
| synonym_discover | Discover candidate synonyms from unmatched query tokens |

```bash

Phase

Tools

Startup

`search` + `tools`

Parameter

Type

action

string

module

string

v6 architecture: Only 2 tools are injected at startup (~270 tokens). Other tools are loaded on demand via the tools manager, saving context tokens in every conversation turn.

| Phase | Tools | Token Cost |
|-------|-------|-----------|
| Startup | search + tools | ~270 tokens |
| + rules module | +6 tools | ~770 tokens total |
| + admin module | +11 tools | ~1,670 tokens total |
| All tools (legacy) | 25+ tools | ~3,000-4,000 tokens |

Load/unload tool modules on demand to save context tokens.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| action | string | "list" | list / load / unload / loaded |
| module | string | "" | Module name to load/unload |

Usage example (LLM calls):

tools(action="list")                          # See available modules
tools(action="load", module="rules") # Load rules tools
tools(action="unload", module="rules") # Unload when done
tools(action="loaded") # See what's currently loaded

Every conversation turn carries tool definitions as context. Dynamic loading drastically reduces this cost:

Legacy (all 25+ tools injected):
  Every turn: ~3,500 tokens for tool definitions
  10-turn conversation: ~35,000 tokens wasted on tool definitions alone

Dynamic loading (v6):
Startup: ~270 tokens (search + tools)
10-turn conversation (search only): ~2,700 tokens
10-turn conversation (search + rules): ~7,700 tokens
Savings: 78-92% on tool definition overhead

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "graph context": {
            "graph-context": {
                "command": "python",
                "args": [
                    "-m",
                    "tests.experiment"
                ]
            }
        }
    }
}

McpServers

{
    "graph-context": {
        "command": "python",
        "args": [
            "-m",
            "tests.experiment"
        ]
    }
}

MCP server for intelligent code context — 87%+ token savings, zero resource overhead.

An MCP context engine built on AST call graphs + BM25 ranking, delivering precise code context retrieval for AI coding assistants. No GPU, no external services, pure Python, ready to use out of the box.

中文文档

Why Graph Context

| Metric | Without MCP (full context) | With MCP (Graph Context) |
|--------|---------------------------|-------------------------|
| Per-turn token usage | Entire codebase | Only relevant chunks (precision retrieval) |
| 10-turn conversation | Linear growth, triggers forgetting | Stable at ~2,000 tokens/turn |
| Multi-agent collaboration | Each agent reloads context independently | MVCC snapshots, shared index, read-write isolation |
| Token savings | — | 87%+ (single-agent & multi-agent) |
| Resource consumption | — | Zero (pure CPU, no model calls) |

How It Works

User query → Synonym expansion (CN/EN) → BM25 ranking (AST call graph weighted)
                                              ↓
                                        IDF noise filtering → Coarse-to-fine (class → method drill-down)
                                              ↓
                                        Rule boost (self-evolving rules engine)
                                              ↓
                                        Return top-k precise chunks

Three-layer retrieval, progressively refined:

1. AST Call Graph — Function-to-function precise mapping, not token co-occurrence. Cross-file dependencies in one hop.
2. BM25 Ranking — Standard information retrieval scoring, combined with chunk type weights (function > class > imports).
3. Self-evolving Rules — New rules enter observation period first, decay based on accuracy (not time), low-performing rules auto-pruned.

Quick Start

Install

```bash
pip install graph-context

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.