Understanding Edge Types in Codebase-Memory-MCP: A Complete Guide
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 (lines 15-19), the GraphEdge interface declares the type property as follows:
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:
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 fileextend: A class extends a parent classimplements: A class implements an interfacecall: A function or method invokes another function or methodreference: A symbol references another definition (e.g., variable usage)declare: A declaration of a type or variableinherit: An interface inherits from another interfacecontains: 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:
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:
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:
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 |
Declares GraphEdge, GraphNode, SchemaInfo, and the edge_types field |
graph-ui/src/hooks/useGraphData.ts |
Retrieves graph layout (including SchemaInfo) from the server |
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.typeproperty, representing relationships likeimport,call, orextend. - The available types are dynamically discovered via the
SchemaInfo.edge_typesarray returned by the backend schema API, rather than hard-coded in the frontend. - Common edge types include
import,extend,implements,call,reference,declare,inherit, andcontains. - 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.
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.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →