Repository navigation
Description
Which server?
memory (@modelcontextprotocol/server-memory)
Protocol era
Both, or not era-specific
MCP client
n/a (server-side graph mutation path in @modelcontextprotocol/server-memory@2.2.2)
The problem
All six write methods on KnowledgeGraphManager in src/memory/index.ts currently perform quadratic .slice(0, index) allocations) instead of Set/Map lookups when deduplicating or matching against the loaded graph:
createEntities(src/memory/index.ts:1193-1200): callsgraph.entities.some(...)andentities.slice(0, index).some(...)for every incoming entity.createRelations(src/memory/index.ts:1229-1238): callsgraph.relations.some(...)andrelations.slice(0, index).some(...)for every incoming relation.addObservations(src/memory/index.ts:1255-1267): callsgraph.entities.find(...)per entry andentity.observations.includes(...)per observation.deleteEntities(src/memory/index.ts:1280-1288): buildspresent = new Set(...)on line 1280, then still scansentityNames.includes(...)on every entity and relation.deleteObservations(src/memory/index.ts:1301-1312): callsgraph.entities.find(...)andd.observations.includes(...)insidefilter.deleteRelations(src/memory/index.ts:1324-1332): callsrelations.some(...)for every relation ingraph.relations.
On a 10,000-relation graph with a 2,000-relation batch, a Node.js benchmark of the current createRelations deduplication loop vs. a Set-indexed lookup measured 329.71 ms vs. 4.17 ms (~79.1x speedup)—and the gap widens further as graph/batch sizes grow. Because every write runs inside withLock(), slower write calls also hold the file lock longer under concurrent clients.
Solution you have in mind (optional)
Index existing and incoming items with Set / Map in
-
createEntities: Seedseen = new Set(graph.entities.map((e) => e.name)), then iterateentitiesonce, adding unseen names toseenandnewEntities. -
createRelations/deleteRelations: Index relations with a collision-free key (e.g., nestedMap<string, Map<string, Set<string>>>orJSON.stringify([r.from, r.to, r.relationType])—avoiding separator collisions since entity names are arbitrary byte strings) so deduplication and deletion run in$O(N + M)$ . -
addObservations/deleteObservations: BuildentityByName = new Map(graph.entities.map((e) => [e.name, e]))once per call, and use aSet<string>forentity.observations/d.observations. -
deleteEntities: Useconst toDelete = new Set(entityNames)for thegraph.entitiesandgraph.relationsfilters instead ofentityNames.includes(...).
Alternatives or workarounds you have tried
Keeping batches small in the client reduces the KnowledgeGraphManager indexes by Set/Map.
Before you submit
- I searched existing issues and this is not a duplicate.
- This is a request for this repository or one of its servers, not a new server, the MCP specification or an SDK.
Activity
cliffhall commentedon Nov 30, 2026
Triage: Priority Low (total 4)
Board: Servers V2 (#43), Status
Incoming, awaiting maintainer review (no milestone yet).Merge #5707 (#5653) into the #5693 branch to resolve the createEntiti…
Merge #5711 (#5655) into the #5693 branch to resolve the delete-metho…