DEV Community

Cover image for What Is Codebase Memory MCP? Structural Memory for Coding Agents
Naser Rasouli
Naser Rasouli

Posted on • Originally published at naserrasouli.ir

What Is Codebase Memory MCP? Structural Memory for Coding Agents

Why Codebase Memory MCP?

As frontend projects grow, understanding the relationships between components, hooks, stores, services, and APIs becomes harder for coding agents. Tools such as Claude Code, Codex, or Cursor may need to search and open several files just to answer a simple question. Codebase Memory MCP builds a knowledge graph of the project so those relationships are stored ahead of time and agents can understand the codebase faster.

Read More:
Personal blog

What is Codebase Memory MCP?

Codebase Memory MCP is an MCP server for structural codebase analysis. It indexes source code and stores relationships between different parts of the project as a graph.

GitHub repository: DeusData/codebase-memory-mcp

In a frontend project, graph nodes can represent components, functions, hooks, modules, and routes, while edges describe relationships such as CALLS, IMPORTS, and HTTP_CALLS.

Core idea

Codebase
   ↓
Parse & Index
   ↓
Knowledge Graph
   ↓
MCP
   ↓
Coding Agent
Enter fullscreen mode Exit fullscreen mode

Instead of rediscovering the repository from scratch for every task, an agent can query its structure first and then open only the files that actually matter.

Example in a React project

Imagine part of a React storefront has this structure:

src/
├── components/
│   └── AddToCartButton.tsx
├── hooks/
│   └── useCart.ts
├── stores/
│   └── cartStore.ts
└── services/
    └── cartApi.ts
Enter fullscreen mode Exit fullscreen mode

The add-to-cart component:

import { useCart } from "@/hooks/useCart";

type Props = {
  productId: string;
};

export function AddToCartButton({ productId }: Props) {
  const { addItem } = useCart();

  return (
    <button onClick={() => addItem(productId)}>
      Add to cart
    </button>
  );
}
Enter fullscreen mode Exit fullscreen mode

The cart hook:

import { useCartStore } from "@/stores/cartStore";
import { addCartItem } from "@/services/cartApi";

export function useCart() {
  const addLocalItem = useCartStore((state) => state.addItem);

  async function addItem(productId: string) {
    addLocalItem(productId);
    await addCartItem(productId);
  }

  return { addItem };
}
Enter fullscreen mode Exit fullscreen mode

And the API service:

export async function addCartItem(productId: string) {
  return fetch("/api/cart", {
    method: "POST",
    body: JSON.stringify({ productId }),
  });
}
Enter fullscreen mode Exit fullscreen mode

For a developer, the execution flow is easy to follow. An agent seeing the repository for the first time still has to discover those relationships. Codebase Memory can store them structurally:

AddToCartButton
       ↓
useCart.addItem
       ↓
cartStore.addItem
       ↓
addCartItem
       ↓
POST /api/cart
Enter fullscreen mode Exit fullscreen mode

Questions such as “What is the add-to-cart flow?” or “What calls addItem?” can then be investigated without broadly searching the entire project first.

What role does MCP play?

Codebase Memory is not an LLM or a coding agent itself. MCP, or Model Context Protocol, is the interface through which the agent accesses Codebase Memory tools.

The overall flow looks like this:

Developer
    ↓
Coding Agent
    ↓
MCP Tool
    ↓
Codebase Memory
    ↓
Knowledge Graph
    ↓
Structured Result
Enter fullscreen mode Exit fullscreen mode

For example, if you ask:

What calls addItem?
Enter fullscreen mode Exit fullscreen mode

The agent can use a graph tool to follow inbound paths and then explain the result in natural language.

What does the knowledge graph store?

A knowledge graph turns the project into nodes and relationships between those nodes.

For example:

ProductPage
    │
    ▼
ProductDetails
    │
    ▼
AddToCartButton
    │
    ▼
useCart
    │
    ▼
addCartItem
    │
    ▼
POST /api/cart
Enter fullscreen mode Exit fullscreen mode

In a large project, this graph can preserve relationships across thousands of symbols and help an agent narrow down a problem before reading source files.

How does Codebase Memory analyze code?

The tool uses Tree-sitter to parse source code. Instead of treating files as plain text, Tree-sitter exposes their syntax as an AST, or Abstract Syntax Tree.

For example:

import { getUser } from "./userApi";

export async function loadProfile() {
  return getUser();
}
Enter fullscreen mode Exit fullscreen mode

A text search can find the string getUser, while structural analysis can identify relationships such as:

loadProfile
    │ CALLS
    ▼
getUser

getUser
    │ IMPORTED FROM
    ▼
./userApi
Enter fullscreen mode Exit fullscreen mode

That matters in TypeScript and React projects, where architecture is heavily shaped by imports, components, hooks, and function calls.

Using it in Next.js

Imagine a product page in Next.js:

import { getProduct } from "@/services/productApi";
import { ProductDetails } from "@/components/ProductDetails";

export default async function ProductPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  const { id } = await params;
  const product = await getProduct(id);

  return <ProductDetails product={product} />;
}
Enter fullscreen mode Exit fullscreen mode

And ProductDetails renders several other components:

export function ProductDetails({ product }) {
  return (
    <>
      <ProductGallery images={product.images} />
      <ProductPrice price={product.price} />
      <AddToCartButton productId={product.id} />
    </>
  );
}
Enter fullscreen mode Exit fullscreen mode

An agent can now investigate structural questions such as:

  • Where is ProductDetails used?
  • What path connects ProductPage to AddToCartButton?
  • Which parts of the project call getProduct?
  • What could be affected if AddToCartButton changes?

These are the kinds of questions where a graph adds more value than plain text search.

Important Codebase Memory MCP tools

Codebase Memory exposes multiple MCP tools for indexing, searching, and analyzing the graph.

index_repository

Analyzes the repository and builds the initial project graph.

search_graph

Finds functions, classes, modules, and other symbols stored in the graph.

trace_path

Follows call paths and is useful for questions such as “What calls this function?” or “What does this function call?”

get_architecture

Provides a higher-level view of project architecture, packages, routes, entry points, and important areas of the codebase.

detect_changes

Inspects Git changes and helps the agent identify the likely impact area of a modification.

get_code_snippet

Returns source code for a specific symbol so the agent does not always need to read an entire file.

search_code

Searches directly through indexed source code.

query_graph

Allows more advanced queries against the knowledge graph.

Impact analysis in frontend projects

One useful application of Codebase Memory is finding the blast radius of a change.

Imagine a shared button in your design system:

<Button loading={true}>Save</Button>
Enter fullscreen mode Exit fullscreen mode

You want to change its API to:

<Button status="loading">Save</Button>
Enter fullscreen mode Exit fullscreen mode

If the component is used across dozens of screens, you need to know what depends on it before refactoring.

Button
 ├── LoginForm
 ├── CheckoutForm
 ├── ProductCard
 ├── DeleteModal
 └── ProfileSettings
Enter fullscreen mode Exit fullscreen mode

A knowledge graph can help the agent find usages and dependency paths so the likely impact area is clearer before the change is made.

Codebase Memory vs. grep

grep and normal search operate on text:

grep -R "addItem" src/
Enter fullscreen mode Exit fullscreen mode

This finds files containing the string addItem, but it does not necessarily tell you which symbol is connected to which other symbol.

The difference can be summarized like this:

grep
↓
"Where does the text addItem appear?"
Enter fullscreen mode Exit fullscreen mode

Compared with:

Knowledge Graph
↓
"What calls addItem?"
"What does addItem call?"
"What path connects a component to addItem?"
Enter fullscreen mode Exit fullscreen mode

Codebase Memory therefore does not replace text search; it adds a structural layer alongside it.

Codebase Memory vs. RAG

With RAG, source code is typically split into chunks and embeddings are used to retrieve code that is semantically relevant to a question.

Source Code
    ↓
Chunks
    ↓
Embeddings
    ↓
Vector Search
    ↓
Relevant Code
Enter fullscreen mode Exit fullscreen mode

A knowledge graph solves a different problem:

Component
    ↓
Hook
    ↓
Store
    ↓
Service
    ↓
API
Enter fullscreen mode Exit fullscreen mode

In simple terms, RAG helps answer “Which code is probably relevant to my question?” while a graph helps answer “How are these parts of the code connected?”

Reducing context usage

Coding agents often load many files into the model context while exploring a repository. More files mean more tokens and more unrelated information competing for attention.

Codebase Memory can change that flow:

Whole Repository
       ↓
Knowledge Graph
       ↓
Relevant Symbols
       ↓
Relevant Files
       ↓
LLM Context
Enter fullscreen mode Exit fullscreen mode

The agent can narrow the problem with the graph first, then read only the source it actually needs.

Keeping the graph updated

A knowledge graph is only useful if it stays aligned with the codebase. Codebase Memory supports project changes so that after the initial index, graph data can be updated as files change.

Initial Index
     ↓
Knowledge Graph
     ↓
Code Changes
     ↓
Incremental Update
     ↓
Updated Graph
Enter fullscreen mode Exit fullscreen mode

This means an agent does not need to rediscover the entire repository from scratch after every small edit.

When does Codebase Memory make sense?

  • Medium and large React, Next.js, or TypeScript projects
  • Repositories with many components, hooks, stores, and services
  • Teams that use coding agents frequently
  • Codebases where dependency and call-chain tracing is difficult
  • Large design systems and component libraries
  • Projects where impact analysis matters before refactoring
  • Workflows where agents spend too much time searching and opening files

For a tiny project with only a few files, indexing and maintaining a graph may provide little value. As the codebase grows, having a structural map becomes much more useful.

Takeaway

Codebase Memory MCP adds a layer of structural memory between a coding agent and the codebase. Instead of rediscovering file relationships for every task, the agent can query a persistent knowledge graph for functions, call chains, dependencies, routes, and the likely impact of changes.

For large frontend projects, that means flows such as Component → Hook → Store → Service → API become directly queryable, helping the agent know where to look before loading a large number of files into context.

Top comments (0)