MCPcopy
hub / github.com/modelcontextprotocol/servers / loadGraph

Method loadGraph

src/memory/index.ts:71–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

69 constructor(private memoryFilePath: string) {}
70
71 private async loadGraph(): Promise<KnowledgeGraph> {
72 try {
73 const data = await fs.readFile(this.memoryFilePath, "utf-8");
74 const lines = data.split("\n").filter(line => line.trim() !== "");
75 return lines.reduce((graph: KnowledgeGraph, line) => {
76 const item = JSON.parse(line);
77 if (item.type === "entity") {
78 graph.entities.push({
79 name: item.name,
80 entityType: item.entityType,
81 observations: item.observations
82 });
83 }
84 if (item.type === "relation") {
85 graph.relations.push({
86 from: item.from,
87 to: item.to,
88 relationType: item.relationType
89 });
90 }
91 return graph;
92 }, { entities: [], relations: [] });
93 } catch (error) {
94 if (error instanceof Error && 'code' in error && (error as any).code === "ENOENT") {
95 return { entities: [], relations: [] };
96 }
97 throw error;
98 }
99 }
100
101 private async saveGraph(graph: KnowledgeGraph): Promise<void> {
102 const lines = [

Callers 9

createEntitiesMethod · 0.95
createRelationsMethod · 0.95
addObservationsMethod · 0.95
deleteEntitiesMethod · 0.95
deleteObservationsMethod · 0.95
deleteRelationsMethod · 0.95
readGraphMethod · 0.95
searchNodesMethod · 0.95
openNodesMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected