Knowledge Graph MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Knowledge Graph MCP Server find all references to the User model in our authentication system"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
kgraph 🧠
Knowledge Graph for Codebases
kgraph is a powerful Model Context Protocol (MCP) server that indexes your codebase into a knowledge graph, enabling semantic search, precise code navigation, and impact analysis for LLM agents.
Unlike simple text search or grep, kgraph understands the structure of your code—classes, functions, imports, and calls—allowing agents to answer complex questions like "Who calls this function?" or "What happens if I change this class?".
✨ Features
Semantic Search: Find code by meaning ("auth middleware") not just keywords. Uses LanceDB for vector search.
Precise Navigation: Jump to definitions and find references with 100% accuracy using Tree-sitter parsing.
Structure Analysis: Understand file outlines (classes, methods, hooks) instantly.
Impact Analysis:
validate_edittool checks for syntax errors and breaking changes before you apply edits.React/TypeScript Support: First-class support for modern web frameworks (Components, Hooks, JSX).
Multi-Language: Supports Python, JavaScript, TypeScript, Java, and more.
Related MCP server: CodeGraph
🚀 Installation
Prerequisites
Python 3.10 or higher
uv(recommended) orpip
Install with uv (Recommended)
# Install directly from source
uv tool install --force --editable .Install with pip
pip install .⚡ Quick Start
Start the Server: Run the server using an MCP client (see below) or directly for testing:
kgraphIndex Your Codebase: The first time you use
kgraphon a project, you must index it:Use the
reindex_codebasetool with the path to your project.Example:
reindex_codebase(root_path="/path/to/my/project")
🛠️ MCP Tools
kgraph exposes the following tools to MCP clients:
🔍 Search & Navigation
search_code(query, limit=5, file_type="")Performs a hybrid search (Semantic + Keyword) to find relevant code snippets.
Great for: "Find the user authentication logic" or "Where is the payment processed?"
find_definitions(name)Locates where a class, function, or component is defined.
Returns file path, line number, and docstring.
find_references(name)Finds all usages of a symbol (calls, imports, inheritance).
Essential for refactoring and understanding dependencies.
📄 Code Understanding
get_structure(file_path)Returns a structured outline of a file: imports, classes, functions, and methods.
Supports React components, hooks, and event handlers.
get_usage_context(symbol)Retrieves a 360° view of a symbol: Definition + References + Outgoing Calls.
Optimized for LLMs to get full context in one shot.
get_file_summary(file_path)Returns a token-efficient summary of a file (signatures and docstrings only).
🛡️ Validation
validate_edit(file_path, new_content)Validates a proposed code edit before applying it.
Checks for:
Syntax Errors: Ensures code is valid (supports JSX/TSX).
Breaking Changes: Warns if you remove a function used by other files.
Signature Changes: Warns if you change a function signature used elsewhere.
⚙️ Management
reindex_codebase(root_path)Scans and indexes the codebase. Run this initially and after major changes.
Creates a
.kgraphdirectory in your project root.
🔌 MCP Client Configuration
Claude Desktop
Add this to your claude_desktop_config.json:
{
"mcpServers": {
"kgraph": {
"command": "uv",
"args": [
"tool",
"run",
"kgraph"
]
}
}
}Cursor / Other Clients
If your client supports stdio MCP servers, use:
Command:
uvArgs:
tool run kgraph
🏗️ Architecture
kgraph uses a hybrid storage approach:
SQLite: Stores the structural graph (Nodes: Files, Functions, Classes; Edges: IMPORTS, CALLS, DEFINES).
LanceDB: Stores vector embeddings of code snippets for semantic search.
Tree-sitter: Used for robust, error-tolerant parsing of source code.
📝 License
MIT
Available Tools
8 toolsfind_definitionsA
Finds where a class or function is defined. Returns file path, line number, and docstring.
Inputs: name (required). Returns: result
find_referencesB
Finds where a symbol is used in the codebase. Returns a list of files and lines where the symbol is called.
Inputs: name (required). Returns: result
get_file_summaryA
Returns a token-efficient summary of a file: imports, classes, functions, and docstrings. Optimized for small context windows.
Inputs: file_path (required). Returns: result
get_structureB
Returns the structure (classes, functions) of a specific file. Note: Requires the file's project to be indexed first.
Inputs: file_path (required). Returns: result
get_usage_contextA
Retrieves a comprehensive context for a symbol:
Definition (where it is)
References (who calls it)
Calls (who it calls)
This is optimized for small LLMs to get full context in one shot.
Inputs: symbol (required). Returns: result
reindex_codebaseA
Scans and indexes the specified directory to build the knowledge graph. This is a heavy operation and should be called when the codebase changes significantly. Database will be created in {root_path}/.kgraph/
Inputs: root_path (required). Returns: result
search_codeA
Performs a semantic search for code snippets relevant to the query. Note: Requires a project to be indexed first with reindex_codebase.
Parameters:
query: Search query
limit: Maximum results (default 5)
file_type: Optional file extension filter (e.g., "py", "java", "ts")
verbose: If True, include technical details like vectors and distances (default False)
Inputs: query (required), limit, verbose, file_type. Returns: result
validate_editA
Validates a proposed code edit BEFORE applying it. Checks for:
Syntax Errors (missing braces, invalid syntax).
Breaking Changes (removing functions/classes that are used by other files).
Use this tool to check your code before writing it to a file.
Inputs: file_path (required), new_content (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Tools are mostly distinct, but get_structure, find_definitions, get_file_summary, and get_usage_context have overlapping information (e.g., both report classes/functions). Descriptions help differentiate, but an agent could be confused about which to use for a specific need.
All tools follow a consistent verb_noun pattern in snake_case (e.g., reindex_codebase, search_code, find_definitions). No mixing of styles or confusing verbs.
8 tools cover indexing, search, structural exploration, context retrieval, and validation—well-scoped for a code knowledge graph server. Each tool serves a distinct purpose without being too few or too many.
The surface covers core operations: indexing, search, definitions, references, file summary, and edit validation. Minor gaps exist (e.g., no explicit graph query tool), but the set is largely complete for code understanding tasks.
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Search indexed code, trace dependencies, assess change impact, and recall repository memory.
Enterprise code intelligence for M&A, security audits, and tech debt. Hosted server with 200k free.
Code intelligence platform for AI agents. 20 tools for architecture, security & impact analysis.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables semantic code search across multiple repositories using natural language queries. Provides intelligent code discovery, symbol lookups, and cross-repo dependency analysis for AI coding agents.MIT
- AlicenseNot gradedqualityBmaintenanceSupercharges AI coding agents with a pre-indexed semantic code graph, enabling instant symbol relationships, impact analysis, and context retrieval across 20+ languages.168,951 npm77,112MIT
- AlicenseNot gradedqualityDmaintenanceProvides semantic code search and code insights via a knowledge graph, enabling AI to understand, navigate, and modify complex projects with deep dependency and architecture analysis.MIT
- AlicenseNot gradedqualityDmaintenanceEnables code intelligence through semantic, structural, graph, and text search across indexed repositories, allowing AI agents to quickly locate the exact code they need.16 npm3MIT