Skip to main content
Glama

read_graph

Retrieve the complete knowledge graph structure including memories, their relationships, decay scores, and statistical overview to analyze stored information and connections.

Instructions

Read the entire knowledge graph of memories and relations.

Returns the complete graph structure including all memories (with decay scores),
all relations between memories, and statistics about the graph.

Args:
    status: Filter memories by status - "active", "promoted", "archived", or "all".
    include_scores: Include decay scores and age in results.
    limit: Maximum number of memories to return.

Returns:
    Complete knowledge graph with memories, relations, and statistics.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_scoresNo
limitNo
statusNoactive

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The complete implementation of the 'read_graph' MCP tool, including the @mcp.tool() decorator for registration, function definition with input parameters (serving as schema), and the full handler logic for reading the knowledge graph with status filtering, optional scoring, pagination, and statistics.
    @mcp.tool()
    def read_graph(
        status: str = "active",
        include_scores: bool = True,
        limit: int | None = None,
        page: int | None = None,
        page_size: int | None = None,
    ) -> dict[str, Any]:
        """
        Read the entire knowledge graph of memories and relations.
    
        Returns the complete graph structure including all memories (with decay scores),
        all relations between memories, and statistics about the graph.
    
        **Pagination:** Results are paginated to help you navigate large knowledge graphs.
        Use `page` and `page_size` to retrieve specific portions of the graph.
        If searching for specific memories or patterns, increment `page` to see more results.
    
        Args:
            status: Filter memories by status - "active", "promoted", "archived", or "all".
            include_scores: Include decay scores and age in results.
            limit: Maximum number of memories to return (1-10,000).
            page: Page number to retrieve (1-indexed, default: 1).
            page_size: Number of memories per page (default: 10, max: 100).
    
        Returns:
            Dictionary with paginated graph including:
            - memories: List of memories for current page
            - relations: All relations (not paginated, for graph structure)
            - stats: Graph statistics
            - pagination: Metadata (page, page_size, total_count, total_pages, has_more)
    
        Examples:
            # Get first page of active memories
            read_graph(status="active", page=1, page_size=10)
    
            # Get next page
            read_graph(status="active", page=2, page_size=10)
    
            # Larger page for overview
            read_graph(status="active", page=1, page_size=50)
    
        Raises:
            ValueError: If status is invalid or limit is out of range.
        """
        # Input validation
        valid_statuses = {"active", "promoted", "archived", "all"}
        if status not in valid_statuses:
            raise ValueError(f"status must be one of {valid_statuses}, got: {status}")
    
        if limit is not None:
            limit = validate_positive_int(limit, "limit", min_value=1, max_value=10000)
    
        # Only validate pagination if explicitly requested
        pagination_requested = page is not None or page_size is not None
    
        status_filter = None if status == "all" else MemoryStatus(status)
        graph = db.get_knowledge_graph(status=status_filter)
    
        if limit and limit > 0:
            graph.memories = graph.memories[:limit]
            graph.stats["limited_to"] = limit
    
        now = int(time.time())
        memories_data = []
        for memory in graph.memories:
            mem_data = {
                "id": memory.id,
                "content": memory.content,
                "entities": memory.entities,
                "tags": memory.meta.tags,
                "created_at": memory.created_at,
                "last_used": memory.last_used,
                "use_count": memory.use_count,
                "strength": memory.strength,
                "status": memory.status.value,
            }
            if include_scores:
                score = calculate_score(
                    use_count=memory.use_count,
                    last_used=memory.last_used,
                    strength=memory.strength,
                    now=now,
                )
                mem_data["score"] = round(score, 4)
                mem_data["age_days"] = round((now - memory.created_at) / 86400, 1)
            memories_data.append(mem_data)
    
        relations_data = [
            {
                "id": rel.id,
                "from": rel.from_memory_id,
                "to": rel.to_memory_id,
                "type": rel.relation_type,
                "strength": round(rel.strength, 4),
                "created_at": rel.created_at,
            }
            for rel in graph.relations
        ]
    
        # Apply pagination only if requested
        if pagination_requested:
            # Validate and get non-None values
            valid_page, valid_page_size = validate_pagination_params(page, page_size)
            paginated_memories = paginate_list(
                memories_data, page=valid_page, page_size=valid_page_size
            )
            return {
                "success": True,
                "memories": paginated_memories.items,
                "relations": relations_data,
                "stats": {
                    "total_memories": graph.stats["total_memories"],
                    "total_relations": graph.stats["total_relations"],
                    "avg_score": round(graph.stats["avg_score"], 4),
                    "avg_use_count": round(graph.stats["avg_use_count"], 2),
                    "status_filter": graph.stats["status_filter"],
                },
                "pagination": paginated_memories.to_dict(),
            }
        else:
            # No pagination - return all memories
            return {
                "success": True,
                "memories": memories_data,
                "relations": relations_data,
                "stats": {
                    "total_memories": graph.stats["total_memories"],
                    "total_relations": graph.stats["total_relations"],
                    "avg_score": round(graph.stats["avg_score"], 4),
                    "avg_use_count": round(graph.stats["avg_use_count"], 2),
                    "status_filter": graph.stats["status_filter"],
                },
            }
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses that the tool reads data (implying non-destructive) and returns a complete graph, but lacks details on permissions, rate limits, or error handling. It adds some context about what's included (decay scores, statistics) but is incomplete for behavioral transparency.

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 well-structured and front-loaded with the core purpose, followed by parameter and return details. Every sentence adds value without redundancy, making it efficient and easy to parse for an agent.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no annotations, but with an output schema), the description is fairly complete. It covers purpose, parameters, and return values, and the output schema reduces the need to explain returns in detail. However, it lacks usage guidelines and some behavioral context, slightly impacting completeness.

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 schema description coverage is 0%, so the description must compensate. It explains all three parameters: status filters memories by specific values, include_scores adds decay scores and age, and limit sets a maximum return count. This adds meaningful semantics beyond the bare schema, though it could elaborate on default behaviors or constraints.

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

Purpose5/5

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

The description clearly states the verb 'Read' and the resource 'entire knowledge graph of memories and relations', specifying it returns the complete graph structure including memories with decay scores, relations, and statistics. This distinguishes it from siblings like search_memory or cluster_memories by emphasizing comprehensive retrieval rather than filtering or processing.

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. It does not mention scenarios where this is preferred over search_memory or open_memories, nor does it specify prerequisites or exclusions, leaving the agent to infer usage from the purpose 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/prefrontal-systems/mnemex'

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