How rohityadav34980/legacygraph-mcp works
What this project is (type + purpose)
LegacyGraph-MCP is a Python 3.11 MCP (Model Context Protocol) server that lets AI agents query a C++ codebase as a knowledge graph instead of raw text. It:
• Parses C++ via tree-sitter to produce an AST (accurate handling of macros/templates vs regex).
• Builds a dependency/call graph using NetworkX.
• Exposes MCP tools over JSON-RPC so an external agent/client (Claude Desktop, etc.) can query callers/callees, cycles, orphans, etc.
From the repository:
Core runtime (the “product”)
• src/server.py → Interface Layer: MCP server, JSON-RPC tool endpoints.
• src/parser.py → Ingestion Layer: tree-sitter parsing of C++ source into AST-derived facts.
• src/graph.py → Graph Layer: constructs/queries NetworkX graph; cycle detection, callers/callees, orphan detection.
• src/__init__.py → package entry glue.
Quality gates / validation tooling
• tools/verifier.py → integration-style verifier that runs the stack end-to-end and checks “100% accuracy” expectations.
• tests/test_core.py → unit tests around core behavior.
Build / dependency management
• pyproject.toml → Poetry deps (tree-sitter, networkx, MCP libs, pytest, mypy, black, etc.).
Documentation
• README.md, PROJECT_MANUAL.md → architecture + API/tool descriptions and usage.
AI Agent / MCP Client
• Claude Desktop / other MCP-compatible client.
• Communicates via JSON-RPC to the MCP server.
LegacyGraph-MCP Server (Python process)
• Contains three internal subsystems (below).
• Owns tool routing, request validation, response formatting.
Interface Layer: MCP Tool Handlers (src/server.py)
• Tools: analyze_codebase, get_callers, get_callees, detect_cycles, get_orphan_functions.
• Converts JSON-RPC requests into internal method calls.
Ingestion Layer: C++ Parser (src/parser.py)
• tree-sitter runtime + C++ grammar usage (show as dependency).
• Outputs extracted entities/relations (functions, calls, files, etc.).
Graph Layer: Knowledge Graph Engine (src/graph.py)
• NetworkX graph construction and algorithms (cycle detection, traversal).
• Query operations used by tool handlers.
C++ Codebase on Disk
• The target repository being modernized (in demo, data/legacy_project/).
AST / Parse Trees (ephemeral)
• Produced by tree-sitter; can be treated as in-memory structures.
Dependency Graph (NetworkX, in-memory)
• The central representation the MCP server queries.
Poetry Environment / pyproject.toml
• Shows how dependencies are resolved and how server is launched.
tree-sitter → Parser: AST nodes/events returned
5. Parser → Graph Layer: emits nodes/edges (function definitions, call edges, file ownership, etc.)
Secondary flows (engineering lifecycle)
• Verifier CLI → MCP stack: runs analysis + compares expected dependencies against data/legacy_project
• Pytest → core modules: unit tests; can mock parser/graph boundaries
• Poetry → installs deps / runs server: poetry run python -m src.server
• Layered architecture (3-layer):
• Interface (protocol/tools) → Ingestion (parsing) → Graph (query/algorithms)
• Graph-RAG / structure-first:
• The “retrieval” is graph traversal (callers/callees/cycles), not embeddings/vector DB.
• In-memory compute:
• Graph and AST are computed at runtime; no persistent DB is shown in this repo.
• Protocol boundary:
• MCP/JSON-RPC boundary is a key integration contract—label it clearly.
“Don’t overthink it” but be very detailed — how to avoid missing essential pieces
Given this repo, the most common omissions are:
• Forgetting that tree-sitter is a runtime parsing dependency (not just a build tool)
• Failing to show the in-memory graph as a first-class artifact
• Not separating tool exposure (MCP) from graph queries (they’re different responsibilities)
• Ignoring verifier/test harness even though README treats accuracy as a key product claim
A practical approach:
Expand each node into subcomponents based on the file tree
• “MCP Server” → tool handlers in src/server.py
• “Parse/tree-sitter” → src/parser.py + tree-sitter runtime
• “NetworkX Graph” → src/graph.py + in-memory graph + algorithms
Engineering loop
• tools/verifier.py and tests/ as separate entrypoints that exercise the server/core.