add_observations
Enhance entities in the Knowledge Graph Memory Server by appending new observations. Input entity names and associated observations to update and expand stored information efficiently.
Instructions
Add new observations to existing entities in the knowledge graph
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| observations | Yes |
Implementation Reference
- src/memory/index.ts:127-140 (handler)Core handler implementing the logic to add unique new observations to existing entities in the knowledge graph.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; }
- src/memory/index.ts:290-315 (registration)Registers the add_observations tool with the MCP server, providing title, description, input/output schemas, and a handler that delegates to KnowledgeGraphManager.addObservations.server.registerTool( "add_observations", { title: "Add Observations", description: "Add new observations to existing entities in the knowledge graph", inputSchema: { observations: z.array(z.object({ entityName: z.string().describe("The name of the entity to add the observations to"), contents: z.array(z.string()).describe("An array of observation contents to add") })) }, outputSchema: { results: z.array(z.object({ entityName: z.string(), addedObservations: z.array(z.string()) })) } }, async ({ observations }) => { const result = await knowledgeGraphManager.addObservations(observations); return { content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], structuredContent: { results: result } }; } );
- src/memory/index.ts:292-307 (schema)Tool metadata including title, description, and Zod-based input/output schemas for validation.{ title: "Add Observations", description: "Add new observations to existing entities in the knowledge graph", inputSchema: { observations: z.array(z.object({ entityName: z.string().describe("The name of the entity to add the observations to"), contents: z.array(z.string()).describe("An array of observation contents to add") })) }, outputSchema: { results: z.array(z.object({ entityName: z.string(), addedObservations: z.array(z.string()) })) } },