Skip to main content
Glama

pin_memory

Prevent a memory chunk from being demoted by pinning it to the hot tier, ensuring it retains full relevance regardless of last access time.

Instructions

Pin a specific chunk to the hot memory tier.

    Pinned chunks are never demoted during maintenance runs and always
    receive full relevance scores (no decay) regardless of how long ago
    they were last accessed.

    Args:
        chunk_id: Stable chunk identifier ``<path>:<chunk_index>``.

    Returns:
        Confirmation dict with ``chunk_id``, ``tier``, and ``pinned`` fields.
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chunk_idYes

Implementation Reference

  • The pin_memory tool handler function, registered as an MCP tool via @mcp.tool(). Takes a chunk_id, checks access, verifies tiered memory is enabled, calls ctx.tiered_memory.pin(chunk_id), logs the action, and returns confirmation dict with chunk_id, tier='hot', pinned=True.
    @mcp.tool()
    def pin_memory(
        chunk_id: Annotated[
            str,
            "The chunk identifier to pin, in '<absolute_path>:<chunk_index>' format. "
            "Chunk IDs are returned in search_memory results.",
        ],
    ) -> dict:
        """Pin a specific chunk to the hot memory tier.
    
        Pinned chunks are never demoted during maintenance runs and always
        receive full relevance scores (no decay) regardless of how long ago
        they were last accessed.
    
        Args:
            chunk_id: Stable chunk identifier ``<path>:<chunk_index>``.
    
        Returns:
            Confirmation dict with ``chunk_id``, ``tier``, and ``pinned`` fields.
        """
        from memorymesh.server.auth_guard import check_access
    
        if (err := check_access(ctx, "index")) is not None:
            return err
    
        if ctx.tiered_memory is None:
            return {"error": "Memory tiers are not enabled in the current configuration."}
        ctx.tiered_memory.pin(chunk_id)
        ctx.audit_logger.log_query(
            tool="pin_memory",
            query=chunk_id,
            n_results=0,
            latency_ms=0.0,
        )
        return {"chunk_id": chunk_id, "tier": "hot", "pinned": True}
  • The unpin_memory tool handler, also registered via @mcp.tool(). Unpins a chunk by calling ctx.tiered_memory.unpin(chunk_id), logs it, and returns confirmation dict with chunk_id and pinned=False.
    @mcp.tool()
    def unpin_memory(
        chunk_id: Annotated[
            str,
            "The chunk identifier to unpin, in '<absolute_path>:<chunk_index>' format.",
        ],
    ) -> dict:
        """Remove the manual pin from a chunk, allowing normal tiering.
    
        The chunk stays in the hot tier until the next maintenance run, after
        which it will be promoted or demoted based on its access history.
    
        Args:
            chunk_id: Stable chunk identifier ``<path>:<chunk_index>``.
    
        Returns:
            Confirmation dict with ``chunk_id`` and ``pinned`` fields.
        """
        from memorymesh.server.auth_guard import check_access
    
        if (err := check_access(ctx, "index")) is not None:
            return err
    
        if ctx.tiered_memory is None:
            return {"error": "Memory tiers are not enabled in the current configuration."}
        ctx.tiered_memory.unpin(chunk_id)
        ctx.audit_logger.log_query(
            tool="unpin_memory",
            query=chunk_id,
            n_results=0,
            latency_ms=0.0,
        )
        return {"chunk_id": chunk_id, "pinned": False}
  • The register() function that wires both pin_memory and unpin_memory handlers onto the FastMCP instance via decorator pattern.
    def register(mcp: FastMCP, ctx: AppContext) -> None:
        """Register ``pin_memory`` and ``unpin_memory`` tools on *mcp*.
    
        Args:
            mcp: The FastMCP instance to register onto.
            ctx: Shared application context (injected via closure).
        """
  • Module docstring describing the tool purpose, and imports including Annotated type used for the chunk_id parameter schema.
    """MCP tool: pin_memory / unpin_memory.
    
    Allows agents to manually pin chunks to the hot memory tier (keeping them
    perpetually accessible with full relevance scores) or unpin them to return
    to normal access-frequency-based tiering.
    """
    
    from __future__ import annotations
    
    from typing import TYPE_CHECKING, Annotated
    
    from mcp.server.fastmcp import FastMCP
    
    if TYPE_CHECKING:
        from memorymesh.server.app import AppContext
  • Import of pin_memory module in app.py's tool registration block.
    pin_memory,
Behavior4/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 clearly discloses key behaviors: pinned chunks are never demoted and receive no decay in relevance scores. It also specifies the return fields. However, it does not mention potential side effects or access requirements.

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 concise, front-loading the purpose in the first sentence, and organized with Args/Returns sections. Every sentence adds value without redundancy.

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?

For a simple tool with one parameter and no output schema, the description covers purpose, behavior, parameter format, and return structure. It assumes domain knowledge (e.g., 'hot memory tier'), but overall it is sufficiently complete for an agent.

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 only parameter 'chunk_id' has no description in the schema (0% coverage). The description provides a specific format: 'Stable chunk identifier <path>:<chunk_index>', adding valuable meaning beyond the schema.

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 tool's purpose: 'Pin a specific chunk to the hot memory tier.' The verb 'pin' and resource 'chunk' are specific, and the sibling 'unpin_memory' further distinguishes it as an inverse operation.

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 explains the behavioral consequences of pinning (no demotion, full relevance scores) but does not explicitly state when to use this tool versus alternatives. No guidance on prerequisites or scenarios where pinning is appropriate.

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/kilhubprojects/memory-mesh'

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