read_graph
Retrieve the complete knowledge graph from the MCP Memory Server to enable LLMs to access and reason over stored information across sessions and conversations.
Instructions
Read the entire knowledge graph
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/index.ts:399-400 (handler)MCP tool dispatch handler for 'read_graph' that calls the readGraph method and returns formatted JSON response.case "read_graph": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.readGraph(), null, 2) }] };
- src/index.ts:132-134 (handler)Handler function in KnowledgeGraphManager that executes the core logic for reading the entire knowledge graph by delegating to loadGraph.async readGraph(): Promise<KnowledgeGraph> { return this.loadGraph(); }
- src/index.ts:36-39 (schema)Type definition/schema for the KnowledgeGraph object returned by the read_graph tool.interface KnowledgeGraph { entities: Entity[]; relations: Relation[]; }
- src/index.ts:338-346 (registration)Registration of the read_graph tool in the ListTools response, including name, description, and empty input schema.{ name: "read_graph", description: "Read the entire knowledge graph", inputSchema: { type: "object", properties: {}, }, }, {
- src/index.ts:43-58 (helper)Private helper method that loads the knowledge graph from the memory JSON lines file, handling file not found gracefully.private async loadGraph(): Promise<KnowledgeGraph> { try { const data = await fs.readFile(MEMORY_FILE_PATH, "utf-8"); const lines = data.split("\n").filter(line => line.trim() !== ""); return lines.reduce((graph: KnowledgeGraph, line) => { const item = JSON.parse(line); if (item.type === "entity") graph.entities.push(item as Entity); if (item.type === "relation") graph.relations.push(item as Relation); return graph; }, { entities: [], relations: [] }); } catch (error) { if (error instanceof Error && 'code' in error && (error as any).code === "ENOENT") { return { entities: [], relations: [] }; } throw error; }