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:- Search → Get a compact index with IDs (~50-100 tokens/result)
- Timeline → Get context around interesting results
- Get Observations → Fetch full details ONLY for filtered IDs
The 3-Layer Workflow
Layer 1: Search (Index)
Start by searching to get a lightweight index of results:Layer 2: Timeline (Context)
Get chronological context around specific observations:Layer 3: Get Observations (Details)
Fetch full details only for relevant observations: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
- 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 - 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- What to look for, in plain words: matched by meaning first, then by keywords (see How the query is matched)limit- Maximum results (default: 20)offset- Skip first N results for paginationtype- Record category:observations,sessionsorprompts(default: all). Any other value is treated as an observation type, likeobs_typeobs_type- Filter observations by type (bugfix, feature, decision, discovery, refactor, change); comma-separated for severalproject- Filter by project namedateStart- Filter by start date (YYYY-MM-DD)dateEnd- Filter by end date (YYYY-MM-DD)orderBy- Sort order (date_desc, date_asc, relevance)
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
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 returnproject- Filter by project name
Common Use Cases
Debugging Issues
Scenario: Find what went wrong with database connectionsUnderstanding Decisions
Scenario: Review architectural choices about authenticationCode Archaeology
Scenario: Find when a specific file was modifiedFeature History
Scenario: Track how a feature evolvedLearning from Past Work
Scenario: Review refactoring patternsContext Recovery
Scenario: Restore context after time away from projectHow the query is matched
When the vector index (Chroma) is running,search first matches your query by meaning, so describe what you are looking for in plain words: query="why the worker failed to start after the upgrade". Keyword matching fills any record category the semantic pass left empty, and answers on its own when the vector index is off or unavailable.
Keyword matching of observations and session summaries reads the query as plain words. It has no operators:
- Every word must appear somewhere in the record, in any order and in any field.
query="security deprecated"finds records that mention both. AND,OR,NOT, quotes, parentheses andfield:prefixes are ordinary words.query="security NOT deprecated"requires “not” and “deprecated” too, andquery='"database migration"'is not a phrase search: the two words can appear anywhere. To narrow results, use theobs_type,project,dateStartanddateEndparameters.- Case does not matter. Punctuation inside a word splits it into parts that must appear together, in order, so
query="worker-service.ts"finds that file name, but not a record that only mentions “worker”, “service” and “ts” apart. - Words can match inside longer words when nothing matches whole words. If no record contains every whole word, each word must still appear, but may be part of a longer one, so
query="migrat"finds “migration”. Text in scripts written without spaces between words (Chinese, Japanese, Korean, Thai and others) is always matched this way.
query="database migration" misses a prompt that says “migration of the database”. Keep prompt searches short.
The hosted server runtime searches observations with PostgreSQL full-text search, which has its own rules: words match by their English stem, OR combines alternatives, quotes require a phrase, a leading - excludes a word, and there is no matching inside longer words.
Token Management
Token Efficiency Best Practices
- Always start with search - Get index first (~50-100 tokens/result)
- Use small limits - Start with 3-5 results, increase if needed
- Filter before fetching - Use type, date, project filters
- Batch get_observations - Always group multiple IDs in one call
- Use timeline strategically - Get context only when narrative matters
Token Cost Estimates
Example Comparison:
Inefficient:
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
-
Broaden your search:
-
Check database has data:
-
Try without filters:
IDs Not Found in get_observations
Error: “Observation IDs not found: [123, 456]” Causes:- IDs from different project (use
projectparameter) - IDs were deleted
- Typo in ID numbers
Token Limit Errors
Error: Response exceeds token limits Solution: Use the 3-layer workflow to reduce upfront costs:Search Performance
If searches seem slow:- Be more specific in queries (helps FTS5 index)
- Use date range filters to narrow scope
- Specify project filter when possible
- Use smaller limit values
Best Practices
- Index First, Details Later - Always start with search to survey options
- Filter Before Fetching - Use search parameters to narrow results
- Batch ID Fetches - Group multiple IDs in one get_observations call
- Use Timeline for Context - When narrative matters, timeline shows the story
- Specific Queries - More specific = better relevance
- Small Limits Initially - Start with 3-5 results, expand if needed
- 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
- Progressive Disclosure - Philosophy behind 3-layer workflow
- Architecture Overview - System components
- Database Schema - Understanding the data structure
- Claude Desktop Setup - Installation and configuration

