Skip to main content
Glama
yodakeisuke

Knowledge Graph Memory Server

by yodakeisuke

read_graph

Retrieve the complete knowledge graph to access stored user information and interaction history for persistent memory in chat applications.

Instructions

Read the entire knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The core handler function for the 'read_graph' tool, which loads the knowledge graph from the memory file and returns it.
    async readGraph(): Promise<KnowledgeGraph> {
      return this.loadGraph();
    }
  • index.ts:500-508 (registration)
    Registration of the 'read_graph' tool in the ListToolsRequestSchema response, including name, description, and empty input schema.
    {
      name: "read_graph",
      description: "Read the entire knowledge graph",
      inputSchema: {
        type: "object",
        properties: {},
      },
    },
    {
  • Dispatch case in the CallToolRequestSchema handler that executes the read_graph tool by calling knowledgeGraphManager.readGraph() and formatting the response.
    case "read_graph":
      return createResponse(JSON.stringify(await knowledgeGraphManager.readGraph(), null, 2));
  • Type definition for the KnowledgeGraph returned by the read_graph tool.
    interface KnowledgeGraph {
      entities: Entity[];
      relations: Relation[];
    }
  • Helper method called by readGraph to parse the JSON lines from the memory file into entities and relations.
    private async loadGraph(): Promise<KnowledgeGraph> {
      try {
        // Check if file exists first
        try {
          await fs.access(this.memoryFilePath);
        } catch (error) {
          console.error(`[Debug] File does not exist, creating empty file`);
          await fs.writeFile(this.memoryFilePath, '', 'utf-8');
          return { entities: [], relations: [] };
        }
    
        const data = await fs.readFile(this.memoryFilePath, "utf-8");
        console.error(`[Debug] Loading graph from: ${this.memoryFilePath}`);
        console.error(`[Debug] File contents: ${data}`);
        
        const lines = data.split("\n").filter(line => line.trim() !== "");
        console.error(`[Debug] Found ${lines.length} lines in the file`);
        
        const graph: KnowledgeGraph = { entities: [], relations: [] };
        
        for (const line of lines) {
          try {
            console.error(`[Debug] Processing line: ${line}`);
            const item = JSON.parse(line);
            
            if (item.type === "entity") {
              const entity: Entity = {
                name: item.name,
                entityType: item.entityType,
                observations: item.observations,
                subdomain: item.subdomain
              };
              console.error(`[Debug] Adding entity: ${JSON.stringify(entity, null, 2)}`);
              graph.entities.push(entity);
            } else if (item.type === "relation") {
              const { type, ...relation } = item;
              graph.relations.push(relation as Relation);
            }
          } catch (parseError) {
            console.error(`[Debug] Error parsing line: ${parseError}`);
            continue;
          }
        }
        
        console.error(`[Debug] Loaded ${graph.entities.length} entities and ${graph.relations.length} relations`);
        return graph;
        
      } catch (error) {
        console.error(`[Debug] Error loading graph:`, error);
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the action without behavioral details. It doesn't disclose performance implications (e.g., large data returns), rate limits, authentication needs, or what 'entire' entails (e.g., all nodes/relations). The description is minimal and lacks critical context for a read operation on a knowledge graph.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded and appropriately sized for a simple tool, making it easy for an agent to parse quickly without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and the complexity of reading an entire knowledge graph, the description is incomplete. It doesn't explain return values, data format, pagination, or scope limitations, leaving significant gaps for the agent to infer behavior in a potentially data-intensive context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0 parameters with 100% coverage, so no parameter documentation is needed. The description doesn't add parameter details, which is appropriate here. A baseline of 4 is applied as it correctly avoids redundancy, though it doesn't compensate for any gaps (none exist).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Read the entire knowledge graph' clearly states the action (read) and resource (knowledge graph), but lacks specificity about what 'entire' means compared to sibling tools like 'search_nodes' or 'open_nodes'. It distinguishes from obvious write/delete siblings but not from other read-like tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'search_nodes' or 'open_nodes'. It implies usage for reading all graph data but doesn't specify scenarios, prerequisites, or exclusions, leaving the agent to guess based on tool names alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/yodakeisuke/mcp-memory-domain-knowledge'

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