modelcontextprotocol/servers · error
Entity with name ${r.to} not found
Error message
Entity with name ${r.to} not found What it means
The same validation in createRelations(), but for the 'to' endpoint of a relation. Before appending relations to the graph, each relation's target entity name is checked against the existing entity set; if the destination node does not exist the whole batch is rejected with this error. This guarantees referential integrity of edges in the knowledge graph.
Source
Thrown at src/memory/index.ts:226
!entities.slice(0, index).some(earlier => earlier.name === e.name)
);
graph.entities.push(...newEntities);
await this.saveGraph(graph);
return newEntities;
});
}
async createRelations(relations: Relation[]): Promise<Relation[]> {
return this.withLock(async () => {
const graph = await this.loadGraph();
const entityNames = new Set(graph.entities.map(e => e.name));
relations.forEach(r => {
if (!entityNames.has(r.from)) {
throw new Error(`Entity with name ${r.from} not found`);
}
if (!entityNames.has(r.to)) {
throw new Error(`Entity with name ${r.to} not found`);
}
});
const isSameRelation = (a: Relation, b: Relation) =>
a.from === b.from &&
a.to === b.to &&
a.relationType === b.relationType;
const newRelations = relations.filter((r, index) =>
!graph.relations.some(existingRelation => isSameRelation(existingRelation, r)) &&
// Also skip duplicates appearing earlier in this same batch
!relations.slice(0, index).some(earlier => isSameRelation(earlier, r))
);
graph.relations.push(...newRelations);
await this.saveGraph(graph);
return newRelations;
});
}
View on GitHub (pinned to d73f99efbf)
Solutions
- Create the missing 'to' entity via createEntities before calling createRelations.
- Pre-validate every relation endpoint against graph.entities names in your client code.
- Verify the target entity was not deleted by a previous deleteEntities call; re-add it if needed.
- Normalize names (trim, consistent casing) when generating relations so they match stored entity names exactly.
Example fix
// before
await memory.createRelations([{ from: "Bob", to: "Acme Corp", relationType: "works_at" }]);
// after
await memory.createEntities([{ name: "Acme Corp", entityType: "organization", observations: [] }]);
await memory.createRelations([{ from: "Bob", to: "Acme Corp", relationType: "works_at" }]); Defensive patterns
Strategy: validation
Validate before calling
const graph = await memory.readGraph();
const names = new Set(graph.entities.map(e => e.name));
const bad = relations.filter(r => !names.has(r.to));
if (bad.length) throw new Error(`Unknown relation targets: ${bad.map(r => r.to).join(", ")}`);
await memory.createRelations(relations); Type guard
function targetsExist(relations: Relation[], names: Set<string>): boolean {
return relations.every(r => typeof r.to === "string" && names.has(r.to));
} Try / catch
try {
await memory.createRelations(relations);
} catch (e) {
if (e instanceof Error && /Entity with name (.+) not found/.test(e.message)) {
console.error("Relation endpoint missing; create it first:", e.message);
} else throw e;
} Prevention
- Derive relation endpoints only from entities you know exist (e.g. from a prior readGraph call).
- Reject LLM-generated relations whose targets are not in the known entity list before submitting.
- Re-create deleted entities before relinking; deletes remove nodes but old relations may reference them.
When it happens
Trigger: createRelations([ { from: 'Alice', to: 'Bob', relationType: 'reports_to' } ]) when 'Bob' was never created (or was renamed/deleted) in the graph; also triggered for any later relation in the batch even if earlier ones are valid, since validation runs over all relations before writing.
Common situations: Linking an entity to one that lives in a different graph file; stale client caches referencing deleted entities; case/whitespace mismatches on the 'to' name; constructing relations programmatically from LLM output containing hallucinated entity names.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- Entity with name ${r.from} not found
- Access denied - parent directory outside allowed directories
- Parent directory does not exist: ${parentDir}
- Invalid resourceType: ${args?.resourceType}. Must be ${RESOU
- Invalid resourceId: ${args?.resourceId}. Must be a finite po
AI-assisted analysis of modelcontextprotocol/servers@d73f99efbf (2026-09-07).
Data as JSON: /api/errors/bc04f984ec36274b.
Report an issue: GitHub.