modelcontextprotocol/servers · error · Error
Entity with name ${o.entityName} not found
Error message
Entity with name ${o.entityName} not found What it means
KnowledgeGraphManager.addObservations() in the memory server looks up each entity by name in the loaded graph and throws if no entity.name matches. Entity names are case-sensitive and must be created first via createEntities(). The graph is persisted as JSONL at MEMORY_FILE_PATH, and loadGraph() returns an empty graph when the file is absent, so a fresh/missing memory file has no entities.
Source
Thrown at src/memory/index.ts:145
async createRelations(relations: Relation[]): Promise<Relation[]> {
const graph = await this.loadGraph();
const newRelations = relations.filter(r => !graph.relations.some(existingRelation =>
existingRelation.from === r.from &&
existingRelation.to === r.to &&
existingRelation.relationType === r.relationType
));
graph.relations.push(...newRelations);
await this.saveGraph(graph);
return newRelations;
}
async addObservations(observations: { entityName: string; contents: string[] }[]): Promise<{ entityName: string; addedObservations: string[] }[]> {
const graph = await this.loadGraph();
const results = observations.map(o => {
const entity = graph.entities.find(e => e.name === o.entityName);
if (!entity) {
throw new Error(`Entity with name ${o.entityName} not found`);
}
const newObservations = o.contents.filter(content => !entity.observations.includes(content));
entity.observations.push(...newObservations);
return { entityName: o.entityName, addedObservations: newObservations };
});
await this.saveGraph(graph);
return results;
}
async deleteEntities(entityNames: string[]): Promise<void> {
const graph = await this.loadGraph();
graph.entities = graph.entities.filter(e => !entityNames.includes(e.name));
graph.relations = graph.relations.filter(r => !entityNames.includes(r.from) && !entityNames.includes(r.to));
await this.saveGraph(graph);
}
async deleteObservations(deletions: { entityName: string; observations: string[] }[]): Promise<void> {
const graph = await this.loadGraph();View on GitHub (pinned to 76d64c822f)
Solutions
- Ensure the entity exists by calling createEntities() before addObservations().
- Call readGraph() or searchNodes() first to confirm the exact stored name and casing.
- Trim and normalize the entityName string before calling.
Example fix
// before
await manager.addObservations([{ entityName: 'Foo', contents: ['x'] }]); // entity is 'foo' -> throws
// after: verify existence, use exact name
const graph = await manager.readGraph();
const name = graph.entities.find(e => e.name.toLowerCase() === 'foo')?.name;
if (!name) { await manager.createEntities([{ name: 'foo', entityType: 't', observations: [] }]); }
await manager.addObservations([{ entityName: name ?? 'foo', contents: ['x'] }]); Defensive patterns
Strategy: validation
Validate before calling
const graph = await manager.readGraph();
const known = new Set(graph.entities.map(e => e.name));
const safe = observations.filter(o => known.has(o.entityName));
if (safe.length !== observations.length) {
const missing = observations.filter(o => !known.has(o.entityName)).map(o => o.entityName);
throw new Error(`Unknown entities (create them first): ${missing.join(', ')}`);
}
await manager.addObservations(safe); Type guard
function entityExists(graph: { entities: { name: string }[] }, name: string): boolean {
return graph.entities.some(e => e.name === name);
} Try / catch
try {
await manager.addObservations(observations);
} catch (e) {
if (e instanceof Error && /Entity with name .* not found/.test(e.message)) {
// create missing entity then retry, or report to caller
}
throw e;
} Prevention
- Call createEntities() before addObservations() in the same workflow.
- Treat names as case-sensitive; store and reuse the exact stored name.
- Keep MEMORY_FILE_PATH stable across sessions so entities persist.
- Trim whitespace from entityName before lookup.
When it happens
Trigger: Calling add_observations with an entityName that was never created, was deleted via deleteEntities, or differs in casing/whitespace from the stored name; running against a different MEMORY_FILE_PATH than the one where the entity was created.
Common situations: Name typo or different casing; entity created in a previous session that wrote to a different memory file; entity deleted between calls; trailing whitespace in the supplied name.
Related errors
- Invalid resourceType: ${args?.resourceType}. Must be ${RESOU
- Invalid resourceId: ${args?.resourceId}. Must be a finite po
- Unknown resource: ${uri.toString()}
- Invalid resourceType: ${args?.resourceType}. Must be ${RESOU
- Invalid resourceId: ${args?.resourceId}. Must be a finite po
AI-assisted analysis of modelcontextprotocol/servers@76d64c822f (2026-08-12).
Data as JSON: /api/errors/f5e35606a6b548b3.
Report an issue: GitHub.