Skip to main content
Glama
marerem

longmem

stats

View database statistics including total entries, category breakdown, and date range to understand memory store size and determine when to rebuild the index (threshold: 256 entries).

Instructions

Return database statistics: total entries, breakdown by category, and date range.

Useful for understanding the size and composition of the memory store, and for deciding when to call rebuild_index (threshold: 256+ entries).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The MCP tool handler for 'stats'. Decorated with @mcp.tool(), it retrieves the store and calls get_stats(), returning the result as JSON.
    # ── tool: stats ───────────────────────────────────────────────────────────────
    @mcp.tool()
    async def stats() -> str:
        """
        Return database statistics: total entries, breakdown by category, and date range.
    
        Useful for understanding the size and composition of the memory store,
        and for deciding when to call rebuild_index (threshold: 256+ entries).
        """
        try:
            store, *_ = await _get_deps()
            data = await store.get_stats()
            return json.dumps(data, indent=2)
        except Exception as exc:
            return _db_error(exc)
  • The get_stats() method on SolutionStore that performs the actual statistics gathering: counts total rows, counts by category, and computes date range (with a 100k-row full scan limit).
    async def get_stats(self) -> dict:
        """
        Return summary statistics: total, by-category counts, date range.
    
        Total and per-category counts use count_rows() — efficient metadata
        reads that never load row data into RAM, regardless of DB size.
        Date range requires a full scan and is skipped for DBs > 100k entries.
        """
        total = await self._table.count_rows()
    
        # Per-category counts — one lightweight count_rows(filter) per category.
        by_category: dict[str, int] = {}
        for cat in CATEGORIES:
            safe_cat = cat.replace("'", "''")
            n = await self._table.count_rows(f"category = '{safe_cat}'")
            if n > 0:
                by_category[cat] = n
    
        # Date range — full scan only for reasonably sized DBs.
        oldest = newest = None
        note: str | None = None
        if total <= self._STATS_FULL_SCAN_LIMIT:
            rows = await self._table.query().select(["created_at"]).to_list()
            dates = [r["created_at"] for r in rows if r.get("created_at")]
            oldest = min(dates) if dates else None
            newest = max(dates) if dates else None
        else:
            note = (
                f"Date range skipped: DB has {total:,} entries. "
                "Run longmem-cursor rebuild-index to compact for faster scans."
            )
    
        result: dict = {
            "total": total,
            "by_category": dict(
                sorted(by_category.items(), key=lambda kv: kv[1], reverse=True)
            ),
            "oldest_entry": oldest,
            "newest_entry": newest,
        }
        if note:
            result["note"] = note
        return result
  • The CATEGORIES list used by get_stats() to iterate over all possible categories for per-category counts.
    CATEGORIES: list[str] = [
        # infra & ops
        "ci_cd", "containers", "infrastructure", "cloud",
        "networking", "observability", "auth_security",
        # data & ML
        "data_pipeline", "ml_training", "model_serving", "experiment_tracking",
        # LLM / AI
        "llm_rag", "llm_api", "vector_db", "agents",
        # SWE
        "database", "api", "async_concurrency", "dependencies",
        "performance", "testing", "architecture",
        "other",
    ]
  • The @mcp.tool() decorator registers the stats function as a tool in the FastMCP server.
    @mcp.tool()
    async def stats() -> str:
Behavior4/5

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

No annotations provided, so description carries full burden. Clearly indicates read-only (returns statistics), no mention of side effects or safety. Lacks details on consistency or performance, but sufficient for a stats tool.

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?

Two sentences, no wasted words. Core purpose first, then contextual usage guidance. Perfectly concise.

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

Completeness5/5

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

Given output schema exists, description covers what the tool returns (total entries, breakdown, date range) and why to use it. Connects to sibling rebuild_index with threshold. Complete for this complexity.

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?

Input schema has zero parameters and 100% coverage; description need not add parameter info. Baseline score 4 applies.

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?

Specific verb 'return' and resource 'database statistics' with explicit details: total entries, breakdown by category, date range. Clear differentiation from sibling tools like rebuild_index.

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

Usage Guidelines5/5

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

Explicitly states when to use: for understanding size/composition, and when to call rebuild_index (threshold 256+ entries). Connects to a sibling tool with a concrete condition.

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/marerem/longmem'

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