# Understanding Edge Types in Codebase-Memory-MCP: A Complete Guide

> Discover edge types in Codebase-Memory-MCP, defining source-code graph relationships like import, call, and extend. Learn about dynamic edge discovery in this complete guide.

- Repository: [Martin Vogel/codebase-memory-mcp](https://github.com/DeusData/codebase-memory-mcp)
- Tags: deep-dive
- Published: 2026-07-04

---

**Edge types in Codebase-Memory-MCP are free-form string identifiers that define relationships between nodes in a source-code graph, dynamically discovered via the `SchemaInfo.edge_types` array to represent connections like `import`, `call`, or `extend`.**

Codebase-Memory-MCP, developed by DeusData, models software repositories as traversable graphs where files, functions, and classes are nodes connected by typed edges. Understanding these edge types is essential for navigating codebase topology, building accurate visualizations, and filtering relationships effectively.

## What Are Edge Types in Codebase-Memory-MCP?

In the graph model used by Codebase-Memory-MCP, **edges** represent typed relationships between nodes. For example, an edge might indicate that a function calls another function, a class extends a base class, or a file imports a module. Each edge carries a `type` property that classifies this relationship.

Unlike static enumerations, edge types are implemented as **free-form strings** stored in the `GraphEdge` interface. This design allows the system to adapt to different programming languages and analysis patterns without requiring changes to the core data model.

### The GraphEdge Interface

According to the source code in [`graph-ui/src/lib/types.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/lib/types.ts) (lines 15-19), the `GraphEdge` interface declares the type property as follows:

```typescript
interface GraphEdge {
  source: string;
  target: string;
  type: string;  // Free-form edge type identifier
  // ... additional properties
}

```

The `type` field contains values like `"import"`, `"extend"`, or `"call"` depending on the relationship being modeled.

### Dynamic Schema Discovery

The backend generates a **schema summary** that lists every distinct edge type appearing in the current dataset. This summary is represented by the `SchemaInfo` interface, specifically the `edge_types` array found at lines 42-45 in [`graph-ui/src/lib/types.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/lib/types.ts):

```typescript
interface SchemaInfo {
  edge_types: {
    type: string;   // e.g., "import", "extend", "call"
    count: number;  // Frequency of this edge type in the graph
  }[];
  // ... other schema fields
}

```

Because these types are derived from the actual code being analyzed, the set is **dynamic**—it changes as the underlying repository changes. The UI does not hard-code a static list; instead, it fetches the schema info at runtime and uses the returned `edge_types` array to drive legends, filters, and statistics.

## Common Edge Types Found in Codebase Graphs

While the specific strings depend on the language parser used to build the graph, the following edge types frequently appear in real-world runs:

- **`import`**: A file imports another module or file
- **`extend`**: A class extends a parent class
- **`implements`**: A class implements an interface
- **`call`**: A function or method invokes another function or method
- **`reference`**: A symbol references another definition (e.g., variable usage)
- **`declare`**: A declaration of a type or variable
- **`inherit`**: An interface inherits from another interface
- **`contains`**: A folder or file contains another node (project hierarchy)

The exact strings may differ depending on the language parser, but they always appear in the `edge_types` payload returned by the server.

## How to Query and Filter Edge Types

The Codebase-Memory-MCP UI retrieves edge type information at runtime to populate filters and visualization legends. The following patterns demonstrate how to work with edge types in the frontend.

### Fetching Available Edge Types

To retrieve the current set of edge types for a project, fetch the schema from the backend API. This React hook queries the `/api/schema` endpoint and returns the `edge_types` array:

```typescript
import { useEffect, useState } from "react";

interface EdgeTypeInfo {
  type: string;
  count: number;
}

export function useEdgeTypes(project: string) {
  const [edgeTypes, setEdgeTypes] = useState<EdgeTypeInfo[]>([]);
  const [error, setError] = useState<string | null>(null);

  useEffect(() => {
    async function load() {
      try {
        const params = new URLSearchParams({ project });
        const resp = await fetch(`/api/schema?${params}`);
        if (!resp.ok) throw new Error("Failed to load schema");
        const { edge_types }: { edge_types: EdgeTypeInfo[] } = await resp.json();
        setEdgeTypes(edge_types);
      } catch (e) {
        setError(e instanceof Error ? e.message : "Unexpected error");
      }
    }
    load();
  }, [project]);

  return { edgeTypes, error };
}

```

This hook utilizes the same schema endpoint that returns the `SchemaInfo` object, extracting the `edge_types` field to drive UI components.

### Rendering Edge Type Legends

Once you have fetched the edge types, you can render them as a legend showing the relationship type and its frequency in the graph:

```tsx
import { useEdgeTypes } from "./useEdgeTypes";

export function EdgeTypeLegend({ project }: { project: string }) {
  const { edgeTypes, error } = useEdgeTypes(project);

  if (error) return <div>Error: {error}</div>;
  if (!edgeTypes.length) return <div>No edge types detected.</div>;

  return (
    <ul className="edge-legend">
      {edgeTypes.map(({ type, count }) => (
        <li key={type}>
          <strong>{type}</strong>: {count} edge{count !== 1 ? "s" : ""}
        </li>
      ))}
    </ul>
  );
}

```

### Filtering Graph Data by Edge Type

To analyze specific relationship patterns, filter the graph edges by type using the `filterEdgesByType` function:

```typescript
import type { GraphData, GraphEdge } from "./lib/types";

export function filterEdgesByType(
  data: GraphData,
  targetType: string
): GraphData {
  const filteredEdges = data.edges.filter((e: GraphEdge) => e.type === targetType);
  return { ...data, edges: filteredEdges };
}

```

This utility accepts a `GraphData` object and a target type string, returning a new graph containing only edges matching that specific relationship.

## Key Implementation Files

The following files in the `graph-ui` directory define how edge types are represented, fetched, and visualized:

| File | Role |
|------|------|
| [`graph-ui/src/lib/types.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/lib/types.ts) | Declares `GraphEdge`, `GraphNode`, `SchemaInfo`, and the `edge_types` field |
| [`graph-ui/src/hooks/useGraphData.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/hooks/useGraphData.ts) | Retrieves graph layout (including `SchemaInfo`) from the server |
| [`graph-ui/src/lib/colors.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/lib/colors.ts) | Provides visual legends and stellar-type color mappings used for edge-density visualization |
| `graph-ui/src/components/*` | UI components that render the graph and legends (e.g., edge-type list, statistics) |

## Summary

- **Edge types** in Codebase-Memory-MCP are free-form strings stored in the `GraphEdge.type` property, representing relationships like `import`, `call`, or `extend`.
- The available types are **dynamically discovered** via the `SchemaInfo.edge_types` array returned by the backend schema API, rather than hard-coded in the frontend.
- Common edge types include `import`, `extend`, `implements`, `call`, `reference`, `declare`, `inherit`, and `contains`.
- The UI fetches edge type metadata at runtime to populate legends, enable filtering, and provide accurate statistics about the codebase graph structure.

## Frequently Asked Questions

### What is an edge type in Codebase-Memory-MCP?

An edge type is a string identifier that classifies the relationship between two nodes in the source-code graph. It describes how entities connect—such as a file importing another module (`import`) or a class extending a parent (`extend`)—and is stored in the `type` property of the `GraphEdge` interface defined in [`graph-ui/src/lib/types.ts`](https://github.com/DeusData/codebase-memory-mcp/blob/main/graph-ui/src/lib/types.ts).

### Are edge types hard-coded or dynamically generated?

Edge types are **dynamically generated** based on the actual code being analyzed. The backend examines the repository and populates the `SchemaInfo.edge_types` array with distinct type strings found in the graph. This means the set of available types changes as the underlying codebase changes, requiring no frontend updates when new relationship types are introduced.

### How can I retrieve the list of available edge types for a project?

Fetch the schema information from the `/api/schema` endpoint (or the layout API that returns `SchemaInfo`), passing the project identifier as a query parameter. The response includes an `edge_types` array containing objects with `type` and `count` properties, as demonstrated in the `useEdgeTypes` React hook implementation.

### What are some examples of edge types I might encounter?

Typical edge types include `import` (file dependencies), `extend` (class inheritance), `implements` (interface implementation), `call` (function invocations), `reference` (symbol usage), `declare` (type declarations), `inherit` (interface inheritance), and `contains` (hierarchical containment). The exact strings depend on the language parser used to generate the graph.