Skip to main content
Glama
Knowledge Graph MCP Server

Knowledge Graph MCP Server

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_edit tool 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) or pip

# Install directly from source
uv tool install --force --editable .

Install with pip

pip install .

⚡ Quick Start

  1. Start the Server: Run the server using an MCP client (see below) or directly for testing:

    kgraph
  2. Index Your Codebase: The first time you use kgraph on a project, you must index it:

    • Use the reindex_codebase tool 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:

      1. Syntax Errors: Ensures code is valid (supports JSX/TSX).

      2. Breaking Changes: Warns if you remove a function used by other files.

      3. 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 .kgraph directory 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: uv

  • Args: 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 tools
find_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:

  1. Definition (where it is)

  2. References (who calls it)

  3. 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:

  1. Syntax Errors (missing braces, invalid syntax).

  2. 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

    A3.9/5.0

    Scored across 8 tools

    Disambiguation4/5

    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.

    Naming Consistency5/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables 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
    • A
      license
      Not graded
      quality
      B
      maintenance
      Supercharges AI coding agents with a pre-indexed semantic code graph, enabling instant symbol relationships, impact analysis, and context retrieval across 20+ languages.
      168,951 npm
      77,112
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides 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
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables code intelligence through semantic, structural, graph, and text search across indexed repositories, allowing AI agents to quickly locate the exact code they need.
      16 npm
      3
      MIT