MCP server providing hierarchical memory for AI agents.
Beta: Core functionality tested and stable. Part of the Loominal multi-agent infrastructure.
Pattern is a Model Context Protocol (MCP) server that provides hierarchical memory capabilities for AI agents. It enables agents to:
- Remember information across sessions with automatic expiration
- Share learnings with other agents in the same project
- Recall context efficiently at session startup
- Isolate memories by project and agent for security
- Node.js >= 18.0.0
- NATS server with JetStream enabled
npm install @loominal/patternOr run directly:
npx @loominal/patternSet environment variables:
export NATS_URL="nats://localhost:4222" # NATS server URL
export LOOMINAL_PROJECT_ID="my-project" # Project isolation key
export LOOMINAL_AGENT_ID="agent-123" # Agent identity (optional)
export DEBUG="true" # Enable debug logging (optional)# Start the MCP server
pattern
# Or with npm
npm startAdd to your Claude Code MCP settings (~/.claude/settings.json):
{
"mcpServers": {
"pattern": {
"command": "npx",
"args": ["@loominal/pattern"],
"env": {
"NATS_URL": "nats://localhost:4222",
"LOOMINAL_PROJECT_ID": "my-project"
}
}
}
}| Category | TTL | Description |
|---|---|---|
recent |
24h | Short-term observations and learnings |
tasks |
24h | Current work items and todos |
longterm |
None | Permanent insights worth keeping |
core |
None | Identity-defining memories (protected) |
| Category | Description |
|---|---|
decisions |
Project decisions and rationale |
architecture |
Architecture choices and patterns |
learnings |
Knowledge shared across agents |
Store a new memory with specified scope and category.
{
"content": "The API uses REST with JSON responses",
"scope": "private",
"category": "longterm",
"metadata": {
"tags": ["api", "architecture"],
"priority": 1
}
}Quick shorthand to remember a task (private, 24h TTL).
{
"content": "Fix the authentication bug in login.ts"
}Quick shorthand to remember a learning (private, 24h TTL).
{
"content": "The database uses PostgreSQL with pgvector"
}Promote a temporary memory to permanent storage.
{
"memoryId": "550e8400-e29b-41d4-a716-446655440000",
"newContent": "Updated insight with more details"
}Store an identity-defining memory (use sparingly, max 100 per agent).
{
"content": "I am a coding assistant that prioritizes test coverage"
}Delete a memory by ID.
{
"memoryId": "550e8400-e29b-41d4-a716-446655440000",
"force": true // Required for core memories
}Retrieve memory context at session start.
{
"scope": "both",
"categories": ["core", "longterm", "decisions"],
"limit": 50,
"since": "2025-01-01T00:00:00Z"
}Returns:
{
"private": [...],
"shared": [...],
"summary": "Key points from your memories...",
"counts": {
"private": 25,
"shared": 10,
"expired": 5
}
}Share a private memory with all project agents.
{
"memoryId": "550e8400-e29b-41d4-a716-446655440000",
"category": "learnings",
"keepPrivate": false
}Run maintenance tasks to expire TTL memories and enforce limits.
{
"expireOnly": false
}Check server health and connection status.
Pattern supports NATS authentication via:
- URL credentials:
nats://user:pass@host:port - Environment variables:
NATS_USERandNATS_PASS
For WebSocket connections through proxies:
export NATS_URL="wss://user:pass@nats.example.com"| Limit | Value |
|---|---|
| Max memory size | 32KB |
| Max memories per agent | 10,000 |
| Max shared memories per project | 10,000 |
| Max core memories per agent | 100 |
| Recent/Tasks category limit | 1,000/500 |
# Clone the repository
git clone https://github.com/loominal/pattern.git
cd pattern
# Install dependencies
npm install
# Run tests
npm test
npm run test:coverage
# Build
npm run build
# Watch mode
npm run dev
# Lint and format
npm run lint
npm run formatflowchart TB
subgraph Clients["MCP Clients"]
CC["Claude Code"]
OA["Other Agent"]
end
subgraph Server["MCP Server"]
Pattern["Pattern<br/>(Memory)"]
end
subgraph Storage["Storage Backend"]
NATS["NATS KV<br/>(JetStream)"]
end
CC <--> Pattern
OA <--> Pattern
Pattern <--> NATS
- Project Isolation: Each project gets its own NATS KV bucket
- Agent Privacy: Private memories keyed by agentId, never visible to others
- TTL Management: Application-level expiration (NATS KV doesn't support per-key TTL)
- Summary Generation: 4KB max summary from prioritized memories
- Loominal — Multi-agent infrastructure
- Warp — MCP server for messaging
- Weft — Work coordinator
- Shuttle — Fleet management CLI
MIT - Michael LoPresti