Skip to main content
Glama
modelcontextprotocol

Knowledge Graph Memory Server

read_graph

Access and retrieve the entire knowledge graph stored in the Knowledge Graph Memory Server to maintain persistent user information across interactions.

Instructions

Read the entire knowledge graph

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Registration of the 'read_graph' MCP tool, including title, description, input/output schemas, and the handler function.
    server.registerTool(
      "read_graph",
      {
        title: "Read Graph",
        description: "Read the entire knowledge graph",
        inputSchema: {},
        outputSchema: {
          entities: z.array(EntitySchema),
          relations: z.array(RelationSchema)
        }
      },
      async () => {
        const graph = await knowledgeGraphManager.readGraph();
        return {
          content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }],
          structuredContent: { ...graph }
        };
      }
    );
  • Core handler method in KnowledgeGraphManager that loads and returns the entire KnowledgeGraph by delegating to private loadGraph().
    async readGraph(): Promise<KnowledgeGraph> {
      return this.loadGraph();
    }
  • Private helper method that reads the memory file (JSONL format), parses each line into entities or relations, and constructs the KnowledgeGraph. Handles missing file gracefully.
    private async loadGraph(): Promise<KnowledgeGraph> {
      try {
        const data = await fs.readFile(this.memoryFilePath, "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;
      }
  • TypeScript interface defining the structure of the knowledge graph returned by read_graph tool.
    export interface KnowledgeGraph {
      entities: Entity[];
      relations: Relation[];
    }
  • Zod schemas for Entity and Relation used in the output schema of read_graph and other tools.
    const EntitySchema = z.object({
      name: z.string().describe("The name of the entity"),
      entityType: z.string().describe("The type of the entity"),
      observations: z.array(z.string()).describe("An array of observation contents associated with the entity")
    });
    
    const RelationSchema = z.object({
      from: z.string().describe("The name of the entity where the relation starts"),
      to: z.string().describe("The name of the entity where the relation ends"),
      relationType: z.string().describe("The type of the relation")
    });
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states a read operation but doesn't disclose behavioral traits like permissions needed, rate limits, response format, pagination, or whether it's safe/destructive. 'Entire' hints at scope but lacks operational details.

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 no wasted words. It's front-loaded with the core action and resource, making it highly concise and well-structured.

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 a read operation with implied complexity (graph data), the description is incomplete. It lacks details on return values, error handling, or behavioral context needed for effective tool use.

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?

With 0 parameters and 100% schema coverage, the baseline is 4. The description adds value by specifying 'entire knowledge graph', which clarifies scope beyond the empty schema, but doesn't detail output semantics or constraints.

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

Purpose4/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). It distinguishes from siblings like 'search_nodes' (filtered) and 'open_nodes' (specific), though not explicitly. However, it lacks specificity about what 'entire' means versus alternatives.

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

Usage Guidelines3/5

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

The description implies usage for retrieving all graph data, contrasting with 'search_nodes' for filtered queries. However, it doesn't explicitly state when to use this versus 'open_nodes' or other read-like siblings, nor provide exclusions or prerequisites.

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

Related 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/modelcontextprotocol/knowledge-graph-memory-server'

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