codegraph-mcp

codegraph-mcp

MCP server that enables intent search over Python call graphs inside Cursor, returning cite spans and call chains to reduce token usage.

Category
访问服务器

README

codegraph-mcp

<p align="center"> <img src="assets/mascot.png" alt="codegraph-mcp" width="120" /> </p>

Intent search over your Python repo's call graph, inside Cursor. One MCP tool returns cite spans and caller→anchor→callee chains so the agent searches once, reads surgically, and burns fewer tokens than grep-then-read loops.

Demo

<p align="center"> <a href="https://github.com/SahilSheikh12299/codegraph-mcp/blob/main/assets/demo.mp4"> <img src="assets/demo-poster.jpg" alt="Watch demo — click to play" width="720" /> </a> </p>

Requirements

All of the following are required:

Component Purpose
Python 3.10+ Runtime
Ollama Generates intent docstrings during indexing
qwen2.5:1.5b Ollama model for docstrings
BAAI/bge-large-en-v1.5 Embedding model (HuggingFace, downloaded on setup/first run)
mixedbread-ai/mxbai-rerank-base-v2 Cross-encoder reranker (HuggingFace)

Hardware: ~8 GB RAM recommended; ~3–5 GB disk for models after first run.

Scope: Python repositories only (for now).

Quick start

# 1. Ollama + required model
brew install ollama          # or https://ollama.com
ollama pull qwen2.5:1.5b

# 2. Install codegraph-mcp (once)
python -m venv .venv
source .venv/bin/activate
pip install "git+https://github.com/SahilSheikh12299/codegraph-mcp.git"

# 3. Global setup (once)
codegraph-mcp setup

Then restart Cursor (or reload MCP in Settings → MCP).

Open any Python repo and ask Cursor where behavior lives — e.g. "Where is authentication handled?" The first search indexes that repo; later searches use the cache at ~/.cursor_graph_rag/graphs/.

No per-project configuration needed.

Pinned install

pip install "git+https://github.com/SahilSheikh12299/codegraph-mcp.git@v0.1.0"

Usage

The MCP server exposes one tool:

search_codebase_intent

search_codebase_intent(
    search_queries=["how redirects are resolved after HTTP response"],
    active_project_root="/absolute/path/to/repo",
    grep_terms=["resolve_redirects"],  # optional symbol anchors
)

Returns markdown with up to 2 matches per grep term and per search query: anchor cite, a tiny call flow, and caller/callee cites. The agent reads those line ranges with native Read — no full-file dumps.

active_project_root is the absolute workspace root (Cursor provides this in context).

What setup does

codegraph-mcp setup runs once globally:

  1. Verifies Ollama is running and qwen2.5:1.5b is installed
  2. Prefetches HuggingFace embedding + reranker models (warns if offline)
  3. Merges codegraph-mcp into ~/.cursor/mcp.json
  4. Installs agent skill at ~/.cursor/skills/codegraph-mcp/SKILL.md

Performance expectations

Phase What happens Typical feel
First setup Ollama check + HF model download (~3–5 GB) One-time; minutes if models aren't cached
First search on a repo Incremental index: Ollama docstrings → call graph → embeddings Minutes on medium/large repos; seconds on tiny ones
Later searches (warm cache) Mtime check only; embed/rerank changed files Usually seconds
Every search call Reloads embedding + reranker models, runs sync under a file lock, then retrieves Adds model load time between idle searches (see below)

Why searches aren't instant: Each search_codebase_intent call syncs the graph for that workspace, then searches. That keeps results fresh but means the tool is "sync then search," not a pure in-memory lookup.

Model memory: Embedding and reranker models unload after each tool call to keep RAM down. The next search pays load cost again (~few seconds on CPU, faster with GPU). Concurrent overlapping calls share one loaded instance.

Rough repo sizing (first index, CPU, Ollama docstrings on):

Repo size Python files Ballpark first index
Tiny < 20 ~30s–2 min
Small 20–100 ~2–10 min
Medium 100–500 ~10–30+ min
Large 500+ 30+ min; consider CURSOR_GRAPHRAG_AUTO_DOCSTRINGS=0 for a faster cold start

Disable auto-docstrings during indexing if you only want speed over semantic richness:

export CURSOR_GRAPHRAG_AUTO_DOCSTRINGS=0

Known limitations (v0.1)

  • Python only.py source files; no JS, Go, notebooks as first-class targets.
  • Static call graphCALLS edges come from AST name resolution + import tracking. Dynamic dispatch (getattr, eval, heavy metaprogramming) may be missing or incomplete.
  • Cursor + MCP — Tested around Cursor's MCP workflow and agent skill; other MCP hosts may work but aren't the primary target.
  • Agent discipline — The skill guides "one search, surgical reads," but the host model can still grep or over-read if it ignores the skill.
  • Top-2 per term — Returns at most two matches per grep term and per intent query by design (token budget). Obscure symbols may need a refined query or grep_terms.
  • Local stack required — Ollama + HuggingFace models; not a hosted/API-only product.
  • Single global MCP process — One Python env serves all workspaces; model weights install once in that venv.

Documentation

Development

git clone https://github.com/SahilSheikh12299/codegraph-mcp.git
cd codegraph-mcp
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选