Skip to main content

Memory Search with MCP Tools

Claude-mem provides persistent memory across sessions through 4 MCP tools that follow a token-efficient 3-layer workflow pattern.

Overview

Instead of fetching all historical data upfront (expensive), claude-mem uses a progressive disclosure approach:
  1. Search → Get a compact index with IDs (~50-100 tokens/result)
  2. Timeline → Get context around interesting results
  3. Get Observations → Fetch full details ONLY for filtered IDs
This achieves ~10x token savings compared to traditional RAG approaches.

The 3-Layer Workflow

Layer 1: Search (Index)

Start by searching to get a lightweight index of results:
Returns: Compact table with IDs, titles, dates, types Cost: ~50-100 tokens per result Purpose: Survey what exists before fetching details

Layer 2: Timeline (Context)

Get chronological context around specific observations:
Or search and get timeline in one step:
Returns: Chronological view showing what was happening before/after Cost: Variable, depends on depth Purpose: Understand narrative arc and context

Layer 3: Get Observations (Details)

Fetch full details only for relevant observations:
Returns: Complete observation details (narrative, facts, files, concepts) Cost: ~500-1000 tokens per observation Purpose: Deep dive on specific, validated items

Why This Works

Traditional Approach:
  • Fetch everything upfront: 20,000 tokens
  • Relevance: ~10% (2,000 tokens actually useful)
  • Waste: 18,000 tokens on irrelevant context
3-Layer Approach:
  • Search index: 1,000 tokens (10 results)
  • Timeline context: 500 tokens (around 2 key results)
  • Fetch details: 1,500 tokens (3 observations)
  • Total: 3,000 tokens, 100% relevant

Available Tools

__IMPORTANT - Workflow Documentation

Always visible reminder of the 3-layer workflow pattern. Helps Claude understand how to use the search tools efficiently. Usage: Automatically shown, no need to invoke

search - Search Memory Index

Search your memory and get a compact index with IDs. Parameters:
  • query - Full-text search query (supports AND, OR, NOT, phrase searches)
  • limit - Maximum results (default: 20)
  • offset - Skip first N results for pagination
  • type - Filter by observation type (bugfix, feature, decision, discovery, refactor, change)
  • obs_type - Filter by record type (observation, session, prompt)
  • project - Filter by project name
  • dateStart - Filter by start date (YYYY-MM-DD)
  • dateEnd - Filter by end date (YYYY-MM-DD)
  • orderBy - Sort order (date_desc, date_asc, relevance)
Returns: Compact index table with IDs, titles, dates, types Example:

timeline - Get Chronological Context

Get a chronological view of observations around a specific point or query. Parameters:
  • anchor - Observation ID to center timeline around (optional if query provided)
  • query - Search query to find anchor automatically (optional if anchor provided)
  • depth_before - Number of observations before anchor (default: 3)
  • depth_after - Number of observations after anchor (default: 3)
  • project - Filter by project name
Returns: Chronological list showing what happened before/during/after Example:
Or search-based:

get_observations - Fetch Full Details

Fetch complete observation details by IDs. Always batch multiple IDs in a single call for efficiency. Parameters:
  • ids - Array of observation IDs (required)
  • orderBy - Sort order (date_desc, date_asc)
  • limit - Maximum observations to return
  • project - Filter by project name
Returns: Complete observation details including narrative, facts, files, concepts Example:
Important: Always batch IDs instead of making separate calls per observation.

Common Use Cases

Debugging Issues

Scenario: Find what went wrong with database connections

Understanding Decisions

Scenario: Review architectural choices about authentication

Code Archaeology

Scenario: Find when a specific file was modified

Feature History

Scenario: Track how a feature evolved

Learning from Past Work

Scenario: Review refactoring patterns

Context Recovery

Scenario: Restore context after time away from project

Search Query Syntax

The query parameter supports SQLite FTS5 full-text search syntax:

Boolean Operators

Phrase Searches

Column-Specific Searches

Combining Operators

Token Management

Token Efficiency Best Practices

  1. Always start with search - Get index first (~50-100 tokens/result)
  2. Use small limits - Start with 3-5 results, increase if needed
  3. Filter before fetching - Use type, date, project filters
  4. Batch get_observations - Always group multiple IDs in one call
  5. Use timeline strategically - Get context only when narrative matters

Token Cost Estimates

Example Comparison: Inefficient:
Efficient:

Advanced Filtering

Date Ranges

Multiple Types

For observations of multiple types, make multiple searches or use broader query:

Project-Specific

Pagination

Result Metadata

All observations include rich metadata:
  • ID - Unique observation identifier
  • Type - bugfix, feature, decision, discovery, refactor, change
  • Date - When the work occurred
  • Title - Concise description
  • Concepts - Tagged themes (e.g., security, performance, architecture)
  • Files Read - Files examined during work
  • Files Modified - Files changed during work
  • Narrative - Story of what happened and why
  • Facts - Key factual points (decisions made, patterns used, metrics)

Troubleshooting

No Results Found

  1. Broaden your search:
  2. Check database has data:
  3. Try without filters:

IDs Not Found in get_observations

Error: “Observation IDs not found: [123, 456]” Causes:
  • IDs from different project (use project parameter)
  • IDs were deleted
  • Typo in ID numbers
Solution:

Token Limit Errors

Error: Response exceeds token limits Solution: Use the 3-layer workflow to reduce upfront costs:

Search Performance

If searches seem slow:
  1. Be more specific in queries (helps FTS5 index)
  2. Use date range filters to narrow scope
  3. Specify project filter when possible
  4. Use smaller limit values

Best Practices

  1. Index First, Details Later - Always start with search to survey options
  2. Filter Before Fetching - Use search parameters to narrow results
  3. Batch ID Fetches - Group multiple IDs in one get_observations call
  4. Use Timeline for Context - When narrative matters, timeline shows the story
  5. Specific Queries - More specific = better relevance
  6. Small Limits Initially - Start with 3-5 results, expand if needed
  7. Review Before Deep Dive - Check index before fetching full details

Technical Details

Architecture: MCP tools are a thin wrapper over the local Worker HTTP API. The MCP server translates tool calls into HTTP requests to the worker service, which handles all business logic, database queries, and Chroma vector search. MCP Server: Located at ~/.claude/plugins/marketplaces/thedotmack/plugin/scripts/mcp-server.cjs Worker Service: Express API on the configured worker port, managed by Bun Database: SQLite FTS5 full-text search on ~/.claude-mem/claude-mem.db Vector Search: Chroma embeddings for semantic search (underlying implementation)

Next Steps