Skip to main content
Glama

read_graph

Retrieve the entire knowledge graph, including entities, observations, and relations, using Memento's fully-offline MCP server for persistent storage and efficient data retrieval.

Instructions

Retrieve the entire knowledge graph: all entities with their observations and relations.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • src/server.js:158-173 (registration)
    MCP tool registration for 'read_graph' with empty input schema and a handler that JSON.stringifies the result of KnowledgeGraphManager.readGraph()
    // Tool: read_graph this.tool( 'read_graph', 'Retrieve the entire knowledge graph: all entities with their observations and relations.', {}, async () => ({ content: [{ type: 'text', text: JSON.stringify( await this.#knowledgeGraphManager.readGraph(), null, 2 ) }] }) );
  • PostgreSQL-specific handler for readGraph(): fetches all entities, attaches observations, fetches all relations with entity names, and returns structured graph data.
    async readGraph() { /** * @type {[{entitytype:string, name:string, id}]} */ const entities = await this.#query('SELECT * FROM entities', []); const observations = await this.#query('SELECT entity_id, content FROM observations', []); /** * @type {[{from_name: string, to_name: string, relationtype: string}]} */ const relations = await this.#query( `SELECT r.from_id, r.to_id, r.relationtype, ef.name AS from_name, et.name AS to_name FROM relations r JOIN entities ef ON ef.id = r.from_id JOIN entities et ON et.id = r.to_id`, [] ); return { entities: entities.map(e => ({ name: e.name, entityType: e.entitytype, observations: observations .filter(o => o.entity_id === e.id) .map(o => o.content) })), relations: relations.map(rel => ({ from: rel.from_name, to: rel.to_name, relationType: rel.relationtype })) }; }
  • SQLite-specific handler for readGraph(): fetches all entities, attaches observations, fetches all relations with entity names, and returns structured graph data.
    async readGraph() { const entities = await this.db.all('SELECT * FROM entities'); const observations = await this.db.all('SELECT entity_id, content FROM observations'); /** * * @type {[{from_name, to_name, relationType}]} */ const relations = await this.db.all(` SELECT r.from_id, r.to_id, r.relationType, ef.name AS from_name, et.name AS to_name FROM relations r JOIN entities ef ON ef.id = r.from_id JOIN entities et ON et.id = r.to_id `); return { entities: entities.map(entity => ({ name: entity.name, entityType: entity.entityType, observations: observations .filter(obs => obs.entity_id === entity.id) .map(obs => obs.content) })), relations: relations.map(rel => ({ from: rel.from_name, to: rel.to_name, relationType: rel.relationType })) }; }
  • KnowledgeGraphManager helper method that delegates readGraph() call to the underlying GraphRepository implementation.
    readGraph() { return this.#repository.readGraph(); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/iAchilles/memento'

If you have feedback or need assistance with the MCP directory API, please join our Discord server