Memory MCP
A Model Context Protocol server for managing LLM conversation memories with intelligent context window caching.
Key Features
Use Cases
README
Memory MCP
A Model Context Protocol (MCP) server for logging and retrieving memories from LLM conversations with intelligent context window caching capabilities.
Features
- Save Memories: Store memories from LLM conversations with timestamps and LLM identification
- Retrieve Memories: Get all stored memories with detailed metadata
- Add Memories: Append new memories without overwriting existing ones
- Clear Memories: Remove all stored memories
- Context Window Caching: Archive, retrieve, and summarize conversation context
- Relevance Scoring: Automatically score archived content relevance to current context
- Tag-based Search: Categorize and search context by tags
- Conversation Orchestration: External system to manage context window caching
- MongoDB Storage: Persistent storage using MongoDB database
Installation
Option 1: Install from npm (Recommended)
npm install -g @jamesanz/memory-mcp
The package will automatically configure Claude Desktop on installation.
Option 2: Install from source
- Install dependencies:
npm install
- Build the project:
npm run build
Configuration
Set the MongoDB connection string via environment variable:
export MONGODB_URI="mongodb://localhost:27017"
Default: mongodb://localhost:27017
Usage
Running the MCP Server
Start the MCP server:
npm start
Running the Conversation Orchestrator Demo
Try the interactive CLI demo:
npm run cli
The CLI demo allows you to:
- Add messages to simulate conversation
- See automatic archiving when context gets full
- Trigger manual archiving and retrieval
- Create summaries of archived content
- Monitor conversation status and get recommendations
Basic Memory Tools
-
save-memories: Save all memories to the database, overwriting existing ones
memories: Array of memory strings to savellm: Name of the LLM (e.g., 'chatgpt', 'claude')userId: Optional user identifier
-
get-memories: Retrieve all memories from the database
- No parameters required
-
add-memories: Add new memories to the database without overwriting existing ones
memories: Array of memory strings to addllm: Name of the LLM (e.g., 'chatgpt', 'claude')userId: Optional user identifier
-
clear-memories: Clear all memories from the database
- No parameters required
Context Window Caching Tools
-
archive-context: Archive context messages for a conversation with tags and metadata
conversationId: Unique identifier for the conversationcontextMessages: Array of context messages to archivetags: Tags for categorizing the archived contentllm: Name of the LLM (e.g., 'chatgpt', 'claude')userId: Optional user identifier
-
retrieve-context: Retrieve relevant archived context for a conversation
conversationId: Unique identifier for the conversationtags: Optional tags to filter byminRelevanceScore: Minimum relevance score (0-1, default: 0.1)limit: Maximum number of items to return (default: 10)
-
score-relevance: Score the relevance of archived context against current conversation context
conversationId: Unique identifier for the conversationcurrentContext: Current conversation context to compare againstllm: Name of the LLM (e.g., 'chatgpt', 'claude')
-
create-summary: Create a summary of context items and link them to the summary
conversationId: Unique identifier for the conversationcontextItems: Context items to summarizesummaryText: Human-provided summary textllm: Name of the LLM (e.g., 'chatgpt', 'claude')userId: Optional user identifier
-
get-conversation-summaries: Get all summaries for a specific conversation
conversationId: Unique identifier for the conversation
-
search-context-by-tags: Search archived context and summaries by tags
tags: Tags to search for
Example Usage in LLM
Basic Memory Operations
-
Save all memories (overwrites existing):
User: "Save all my memories from this conversation to the MCP server" LLM: [Uses save-memories tool with current conversation memories] -
Retrieve all memories:
User: "Get all my memories from the MCP server" LLM: [Uses get-memories tool to retrieve stored memories]
Context Window Caching Workflow
-
Archive context when window gets full:
User: "The conversation is getting long, archive the early parts" LLM: [Uses archive-context tool to store old messages with tags] -
Score relevance of archived content:
User: "How relevant is the archived content to our current discussion?" LLM: [Uses score-relevance tool to evaluate archived content] -
Retrieve relevant archived context:
User: "Bring back the relevant archived information" LLM: [Uses retrieve-context tool to get relevant archived content] -
Create summaries for long conversations:
User: "Summarize the early parts of our conversation" LLM: [Uses create-summary tool to condense archived content]
Conversation Orchestration System
The ConversationOrchestrator class provides automatic context window management:
Key Features
- Automatic Archiving: Archives content when context usage reaches 80%
- Intelligent Retrieval: Retrieves relevant content when usage drops below 30%
- Relevance Scoring: Uses keyword overlap to score archived content relevance
- Smart Tagging: Automatically generates tags based on content keywords
- Conversation State Management: Tracks active conversations and their context
- Recommendations: Provides suggestions for optimal context management
Usage Example
import { ConversationOrchestrator } from "./orchestrator.js";
const orchestrator = new ConversationOrchestrator(8000); // 8k word limit
// Add a message (triggers automatic archiving/retrieval)
const result = await orchestrator.addMessage(
"conversation-123",
"This is a new message in the conversation",
"claude",
);
// Check if archiving is needed
if (result.archiveDecision?.shouldArchive) {
await orchestrator.executeArchive(result.archiveDecision, result.state);
}
// Check if retrieval is needed
if (result.retrievalDecision?.shouldRetrieve) {
await orchestrator.executeRetrieval(result.retrievalDecision, result.state);
}
Database Schema
Basic Memory Structure
type BasicMemory = {
_id: ObjectId;
memories: string[]; // Array of memory strings
timestamp: Date; // When memories were saved
llm: string; // LLM identifier (e.g., 'chatgpt', 'claude')
userId?: string; // Optional user identifier
};
Extended Memory Structure (Context Caching)
type ExtendedMemory = {
_id: ObjectId;
memories: string[]; // Array of memory strings
timestamp: Date; // When memories were saved
llm: string; // LLM identifier
userId?: string; // Optional user identifier
conversationId?: string; // Unique conversation identifier
contextType?: "active" | "archived" | "summary";
relevanceScore?: number; // 0-1 relevance score
tags?: string[]; // Categorization tags
parentContextId?: ObjectId; // Reference to original content for summaries
messageIndex?: number; // Order within conversation
wordCount?: number; // Size tracking
summaryText?: string; // Condensed version
};
Context Window Caching Workflow
The orchestration system automatically:
- Monitors conversation length and context usage
- Archives content when context usage reaches 80%
- Scores relevance of archived content against current context
- Retrieves relevant content when usage drops below 30%
- Creates summaries to condense very long conversations
Key Features
- Conversation Grouping: All archived content is linked to specific conversation IDs
- Relevance Scoring: Simple keyword overlap scoring (can be enhanced with semantic similarity)
- Tag-based Organization: Categorize content for easy retrieval
- Summary Linking: Preserve links between summaries and original content
- Backward Compatibility: All existing memory functions work unchanged
- Automatic Management: No manual intervention required for basic operations
Development
To run in development mode:
npm run build
node build/index.js
To run the CLI demo:
npm run cli
License
ISC
Star History
Repository Owner
User
Repository Details
Programming Languages
Tags
Topics
Join Our Newsletter
Stay updated with the latest AI tools, news, and offers by subscribing to our weekly newsletter.
Related MCPs
Discover similar Model Context Protocol servers
Agentic Long-Term Memory with Notion Integration
Production-ready agentic long-term memory and Notion integration with Model Context Protocol support.
Agentic Long-Term Memory with Notion Integration enables AI agents to incorporate advanced long-term memory capabilities using both vector and graph databases. It offers comprehensive Notion workspace integration along with a production-ready Model Context Protocol (MCP) server supporting HTTP and stdio transports. The tool facilitates context management, tool discovery, and advanced function chaining for complex agentic workflows.
- ⭐ 4
- MCP
- ankitmalik84/Agentic_Longterm_Memory
MCP CLI
A powerful CLI for seamless interaction with Model Context Protocol servers and advanced LLMs.
MCP CLI is a modular command-line interface designed for interacting with Model Context Protocol (MCP) servers and managing conversations with large language models. It integrates with the CHUK Tool Processor and CHUK-LLM to provide real-time chat, interactive command shells, and automation capabilities. The system supports a wide array of AI providers and models, advanced tool usage, context management, and performance metrics. Rich output formatting, concurrent tool execution, and flexible configuration make it suitable for both end-users and developers.
- ⭐ 1,755
- MCP
- chrishayuk/mcp-cli
VictoriaMetrics MCP Server
Model Context Protocol server enabling advanced monitoring and observability for VictoriaMetrics.
VictoriaMetrics MCP Server implements the Model Context Protocol (MCP) to provide seamless integration with VictoriaMetrics, allowing advanced monitoring, data exploration, and observability. It offers access to almost all read-only APIs, as well as embedded documentation for offline usage. The server facilitates comprehensive metric querying, cardinality analysis, alert and rule testing, and automation capabilities for engineers and tools.
- ⭐ 87
- MCP
- VictoriaMetrics-Community/mcp-victoriametrics
Raindrop.io MCP Server
Enable LLMs to manage and search Raindrop.io bookmarks via the Model Context Protocol.
Raindrop.io MCP Server is an integration that allows large language models to interact with Raindrop.io bookmarks using the Model Context Protocol. It provides tools to create and search bookmarks, including filtering by tags, and is designed for interoperability with environments like Claude for Desktop. Installation can be done via Smithery or manually, and configuration is managed through environment variables. The project is open source and optimized for secure, tokenized access to Raindrop.io.
- ⭐ 63
- MCP
- hiromitsusasaki/raindrop-io-mcp-server
MCP System Monitor
Real-time system metrics for LLMs via Model Context Protocol
MCP System Monitor exposes real-time system metrics, such as CPU, memory, disk, network, host, and process information, through an interface compatible with the Model Context Protocol (MCP). The tool enables language models to retrieve detailed system data in a standardized way. It supports querying various hardware and OS statistics via structured tools and parameters. Designed with LLM integration in mind, it facilitates context-aware system monitoring for AI-driven applications.
- ⭐ 73
- MCP
- seekrays/mcp-monitor
OpenStreetMap MCP Server
Enhancing LLMs with geospatial and location-based capabilities via the Model Context Protocol.
OpenStreetMap MCP Server enables large language models to interact with rich geospatial data and location-based services through a standardized protocol. It provides APIs and tools for address geocoding, reverse geocoding, points of interest search, route directions, and neighborhood analysis. The server exposes location-related resources and tools, making it compatible with MCP hosts for seamless LLM integration.
- ⭐ 134
- MCP
- jagan-shanmugam/open-streetmap-mcp
Didn't find tool you were looking for?