{"record":{"id":"f5e35606a6b548b3","repo":"modelcontextprotocol/servers","slug":"entity-with-name-o-entityname-not-found","errorCode":null,"errorMessage":"Entity with name ${o.entityName} not found","messagePattern":"Entity with name (.+?) not found","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/memory/index.ts","lineNumber":145,"sourceCode":"\n  async createRelations(relations: Relation[]): Promise<Relation[]> {\n    const graph = await this.loadGraph();\n    const newRelations = relations.filter(r => !graph.relations.some(existingRelation => \n      existingRelation.from === r.from && \n      existingRelation.to === r.to && \n      existingRelation.relationType === r.relationType\n    ));\n    graph.relations.push(...newRelations);\n    await this.saveGraph(graph);\n    return newRelations;\n  }\n\n  async addObservations(observations: { entityName: string; contents: string[] }[]): Promise<{ entityName: string; addedObservations: string[] }[]> {\n    const graph = await this.loadGraph();\n    const results = observations.map(o => {\n      const entity = graph.entities.find(e => e.name === o.entityName);\n      if (!entity) {\n        throw new Error(`Entity with name ${o.entityName} not found`);\n      }\n      const newObservations = o.contents.filter(content => !entity.observations.includes(content));\n      entity.observations.push(...newObservations);\n      return { entityName: o.entityName, addedObservations: newObservations };\n    });\n    await this.saveGraph(graph);\n    return results;\n  }\n\n  async deleteEntities(entityNames: string[]): Promise<void> {\n    const graph = await this.loadGraph();\n    graph.entities = graph.entities.filter(e => !entityNames.includes(e.name));\n    graph.relations = graph.relations.filter(r => !entityNames.includes(r.from) && !entityNames.includes(r.to));\n    await this.saveGraph(graph);\n  }\n\n  async deleteObservations(deletions: { entityName: string; observations: string[] }[]): Promise<void> {\n    const graph = await this.loadGraph();","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/memory/index.ts#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait manager.addObservations([{ entityName: 'Foo', contents: ['x'] }]); // entity is 'foo' -> throws\n\n// after: verify existence, use exact name\nconst graph = await manager.readGraph();\nconst name = graph.entities.find(e => e.name.toLowerCase() === 'foo')?.name;\nif (!name) { await manager.createEntities([{ name: 'foo', entityType: 't', observations: [] }]); }\nawait manager.addObservations([{ entityName: name ?? 'foo', contents: ['x'] }]);","handlingStrategy":"validation","validationCode":"const graph = await manager.readGraph();\nconst known = new Set(graph.entities.map(e => e.name));\nconst safe = observations.filter(o => known.has(o.entityName));\nif (safe.length !== observations.length) {\n  const missing = observations.filter(o => !known.has(o.entityName)).map(o => o.entityName);\n  throw new Error(`Unknown entities (create them first): ${missing.join(', ')}`);\n}\nawait manager.addObservations(safe);","typeGuard":"function entityExists(graph: { entities: { name: string }[] }, name: string): boolean {\n  return graph.entities.some(e => e.name === name);\n}","tryCatchPattern":"try {\n  await manager.addObservations(observations);\n} catch (e) {\n  if (e instanceof Error && /Entity with name .* not found/.test(e.message)) {\n    // create missing entity then retry, or report to caller\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["memory","typescript","entity-not-found","knowledge-graph"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}