Skip to main content
Glama

contextual_memento_search

Search within related memories to find solutions in specific problem contexts using semantic scoping without embeddings.

Instructions

Search only within the context of a given memento (scoped search).

Two-phase process: (1) Find related memories, (2) Search only within that set. Provides semantic scoping without embeddings.

WHEN TO USE:

  • Searching within a specific problem context

  • Finding solutions in related knowledge

  • Scoped discovery

HOW TO USE:

  • Specify memory_id (context root)

  • Provide query (search term)

  • Optional: max_depth (default: 2)

RETURNS:

  • Matches found only within related memories

  • Context information

  • No leakage outside context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesMemory ID to use as context root (required)
queryYesSearch query within context (required)
max_depthNoMaximum relationship traversal depth (default: 2)

Implementation Reference

  • The handler function for the `contextual_memento_search` tool, which performs a two-phase scoped search.
    async def handle_contextual_memento_search(
        memory_db: SQLiteMemoryDatabase, arguments: Dict[str, Any]
    ) -> CallToolResult:
        """Handle contextual_search tool call.
    
        Search only within the context of a given memory by first finding
        all related memories, then searching only within that related set.
        This provides semantic scoping without embeddings.
    
        Args:
            memory_db: Database instance for memory operations
            arguments: Tool arguments from MCP call containing:
                - memory_id: ID of memory to use as context root (required)
                - query: Text search query (required)
                - max_depth: Maximum relationship traversal depth (default: 2)
    
        Returns:
            CallToolResult with scoped search results or error message
        """
        # Validate input arguments
        validate_search_input(arguments)
    
        # Validate required parameters
        if "memory_id" not in arguments:
            return CallToolResult(
                content=[
                    TextContent(
                        type="text", text="Error: 'memory_id' parameter is required"
                    )
                ],
                isError=True,
            )
    
        if "query" not in arguments:
            return CallToolResult(
                content=[
                    TextContent(type="text", text="Error: 'query' parameter is required")
                ],
                isError=True,
            )
    
        memory_id: str = arguments["memory_id"]
        query: str = arguments["query"]
        max_depth: int = arguments.get("max_depth", 2)
    
        # Phase 1: Find all memories related to the context memory
        related = await memory_db.get_related_memories(
            memory_id=memory_id,
            relationship_types=None,  # All relationship types
            max_depth=max_depth,
        )
    
        if not related:
            return CallToolResult(
                content=[
                    TextContent(
                        type="text",
                        text=f"No related memories found for context: {memory_id}",
                    )
                ]
            )
    
        # Extract IDs of related memories to scope the search
        related_ids: Set[str] = {mem.id for mem, _ in related}
    
        # Phase 2: Search only within the related memories
        # Get all memories from search, then filter by related IDs
        search_query: SearchQuery = SearchQuery(
            query=query,
            limit=100,  # Get more results to filter
            search_tolerance="normal",
  • MCP Tool definition/schema for `contextual_memento_search`.
            Tool(
                name="contextual_memento_search",
                description="""Search only within the context of a given memento (scoped search).
    
    Two-phase process: (1) Find related memories, (2) Search only within that set.
    Provides semantic scoping without embeddings.
    
    WHEN TO USE:
    - Searching within a specific problem context
    - Finding solutions in related knowledge
    - Scoped discovery
    
    HOW TO USE:
    - Specify memory_id (context root)
    - Provide query (search term)
    - Optional: max_depth (default: 2)
    
    RETURNS:
    - Matches found only within related memories
    - Context information
    - No leakage outside context""",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "memory_id": {
                            "type": "string",
  • Registration of the handler in the tool registry.
    "contextual_memento_search": handle_contextual_memento_search,
Behavior4/5

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

Discloses two-phase process ('Find related memories, Search only within that set') and guarantees 'No leakage outside context' without annotations. Explains 'semantic scoping without embeddings' as implementation detail. Minor gap: does not specify error behavior (e.g., invalid memory_id) or result ordering.

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?

Perfectly structured with clear headers (WHEN TO USE, HOW TO USE, RETURNS). Every sentence adds value—technical mechanism, usage scenarios, parameter guidance, and return guarantees. No redundancy or fluff despite comprehensive coverage.

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?

Excellent coverage given 3 parameters, 100% schema coverage, and no output schema. Describes return values conceptually ('Matches found only within related memories'). Minor deduction: lacks error handling description (e.g., orphaned memory_id) and pagination/rate limit details given relationship traversal 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?

With 100% schema coverage (baseline 3), description adds valuable semantic context: memory_id is the 'context root,' max_depth controls 'relationship traversal depth,' and parameters operate in a coordinated two-phase process. Explains interaction between parameters beyond isolated schema definitions.

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?

Specifies 'Search only within the context of a given memento' with clear verb (search) and resource (mementos). Distinguishes from sibling tool 'search_mementos' by emphasizing 'scoped search' and 'within context,' clarifying this narrows results to related memories rather than global search.

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?

Explicit 'WHEN TO USE' section lists three specific scenarios: 'Searching within a specific problem context,' 'Finding solutions in related knowledge,' and 'Scoped discovery.' Also provides 'HOW TO USE' with clear parameter mapping, effectively guiding selection over alternatives like general search.

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/x-hannibal/mcp-memento'

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