RLM-Mem MCP Server
Provides a persistent memory store backed by SQLite, allowing important findings to be saved and recalled across conversations.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@RLM-Mem MCP ServerAnalyze this codebase for security vulnerabilities in ./src"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
RLM-Mem MCP Server
An MCP (Model Context Protocol) server implementing the TRUE Recursive Language Model (RLM) technique for ultimate context management with Claude Code.
⚖️ Licensing & Pricing
Free Use (MIT License)
✅ Personal projects
✅ Academic research
✅ Non-commercial open source
✅ Non-profit organizations
✅ Annual revenue < $50K
Commercial Use (Revenue Sharing Required)
💰 10% Revenue Share for services/products using this technology
🏢 Commercial licenses required for companies/enterprises
📧 Contact:
msayf@recordandlearn.info🌐 Website: recordandlearn.info
Important: Commercial use without proper licensing voids all warranties and may result in legal action.
v2.9 Status: 🚀 Optimization Initiative Underway
✅ Code organization complete (5 new modules, 1,524 LOC)
📊 Performance roadmap planned (60-100% cumulative gain)
🎯 3 optimization phases documented
📋 16 implementation tasks ready
See .claude/claude.md for detailed optimization roadmap.
Based on:
arXiv:2512.24601 - Recursive Language Models (Zhang, Kraska, Khattab - MIT, 2025)
Related MCP server: Massive Context MCP
The Problem
Claude Code has a context window of ~200k tokens. When analyzing large codebases (500k+ tokens), Claude either:
Fails to process everything
Experiences "context rot" (degraded performance)
Runs out of space for reasoning
The TRUE RLM Solution
Key Insight: Content is stored as a VARIABLE in a Python REPL, NOT in LLM context.
Traditional Summarization (NOT what we do):
Large content → LLM summarizes → Information LOST
TRUE RLM Technique:
Large content → Stored as `prompt` variable
LLM writes Python CODE to examine portions
Sub-LLM responses stored as VARIABLES (NOT summarized)
Full data PRESERVED - accessible at any timeThe LLM acts as a programmer, writing code to search and analyze the content rather than trying to hold it all in context.
Features
TRUE RLM Processing: Content stored as variables, LLM writes code to examine it
Prompt Caching: Leverages caching for cost reduction on repeated content
Intelligent Chunking: Respects file/function/section boundaries when splitting
Memory Store: Persist important findings across conversations (SQLite-backed)
Robust Architecture: Circuit breakers, rate limiters, exponential backoff
Async Pipeline: Fully async with connection pooling and concurrent operations
Claude Haiku 4.5: Default model with 90% cost savings via prompt caching
Installation
Prerequisites
Python 3.10+
Claude Code CLI
OpenRouter API key (or Anthropic API key for direct access)
Setup
# Clone the repository
git clone https://github.com/mosif16/RLM-Mem_MCP.git
cd RLM-Mem_MCP
# Install Python dependencies
cd python
pip install -e .
# Set your API key (OpenRouter recommended for flexibility)
export OPENROUTER_API_KEY=sk-or-...
# Or use Anthropic directly
# export ANTHROPIC_API_KEY=sk-ant-...Configure Claude Code
Add the MCP server to Claude Code:
# Using the CLI
claude mcp add --transport stdio rlm -- python -m rlm_mem_mcp.server
# Or add to ~/.claude/mcp_servers.json manuallyManual configuration (~/.claude/mcp_servers.json):
{
"mcpServers": {
"rlm": {
"command": "python",
"args": ["-m", "rlm_mem_mcp.server"],
"env": {
"OPENROUTER_API_KEY": "${OPENROUTER_API_KEY}"
}
}
}
}Documentation
Complete documentation is available in the docs/ directory:
Usage Guide - Practical examples and workflows (start here!)
API Reference - Complete tool specifications
Configuration Guide - Environment variables and setup
Architecture - Technical deep-dive
Quick Usage
Tools Available
rlm_analyze
Analyze files or directories recursively.
Query: "Find all security vulnerabilities"
Paths: ["./src", "./api"]rlm_query_text
Process large text blocks directly.
Query: "Extract all error messages with timestamps"
Text: <massive log file content>rlm_status
Check server health and configuration.
rlm_memory_store / rlm_memory_recall
Persist and retrieve important findings.
Example Workflows
Security Audit:
User: "Check this repo for security vulnerabilities"
Claude uses rlm_analyze({
"query": "security vulnerabilities: SQL injection, XSS, CSRF,
hardcoded secrets, insecure deserialization, path traversal",
"paths": ["./src", "./api"]
})Architecture Review:
User: "Explain the architecture of this project"
Claude uses rlm_analyze({
"query": "describe architecture: main components, data flow,
dependencies, entry points, design patterns used",
"paths": ["."]
})Log Analysis:
User: "Here's a 50MB log file. Find all errors."
Claude uses rlm_query_text({
"query": "extract all ERROR and EXCEPTION entries with timestamps",
"text": "<log content>"
})Configuration
Environment Variables
Core Configuration
Variable | Default | Description |
| (required) | Your OpenRouter API key |
|
| Model for RLM processing |
|
| Model for final aggregation |
|
| Enable prompt caching |
|
| Cache TTL ( |
|
| Max tokens in result |
|
| Max tokens per chunk |
|
| Overlap tokens between chunks |
Commercial Licensing (Optional)
Variable | Default | Description |
| (empty) | Commercial license key for revenue sharing |
| (empty) | Organization name for commercial licensing |
|
| Enable usage telemetry for license compliance |
|
| License validation server URL |
File Filtering
Included extensions:
Code:
.py,.js,.ts,.tsx,.go,.rs,.java,.c,.cpp, etc.Config:
.json,.yaml,.toml,.iniDocs:
.md,.txt,.rst
Skipped directories:
.git,node_modules,__pycache__,venv,dist,build, etc.
How It Works
TRUE RLM Architecture
+------------------+
| Claude Code |
| |
| - Sees RLM tools |
| - Decides to use |
| - Calls tool |
+--------+---------+
|
| MCP Protocol (JSON-RPC over stdio)
v
+------------------+ +------------------+
| RLM MCP Server | | REPL Environ |
| | | |
| - Collects files |---->| prompt = content |
| - Stores as var | | results = [] |
| - LLM writes code| | llm_query(...) |
| - Executes code | | |
+--------+---------+ +------------------+
|
| API calls (with caching, rate limiting, circuit breaker)
v
+------------------+
| OpenRouter / |
| Anthropic API |
+------------------+The TRUE RLM Technique (arXiv:2512.24601)
Unlike simple summarization, TRUE RLM:
Content as Variable: Files stored in
promptvariable, NOT in LLM contextLLM Writes Code: The LLM generates Python to examine
promptSub-LLM Queries:
llm_query()calls analyze specific portionsResults as Variables: Sub-LLM responses stored in full, NOT summarized
Full Preservation: Original data always accessible for re-examination
Processing Steps
File Collection: Async walk directories, filter by extension, respect limits
Variable Storage: Content stored in REPL environment as
promptvariableCode Generation: LLM writes Python code to search/analyze content
Sandboxed Execution: Code runs in restricted environment with
llm_query()Result Aggregation: Findings combined into coherent response
Truncation: Ensure result fits in context (max 4000 tokens)
Prompt Caching Strategy
The server uses Anthropic's prompt caching to optimize costs:
System prompts are cached (90% cost reduction on hits)
5-minute TTL by default, refreshes on each use
1-hour TTL available for less frequent access
Cache statistics tracked and reported via
rlm_status
# Cache control is applied automatically to system prompts
system = [
{
"type": "text",
"text": "You are a precise information extractor...",
"cache_control": {"type": "ephemeral", "ttl": "5m"}
}
]Cost Comparison
Method | 500k token input | Context Used | Cost |
Direct (if possible) | Fails or degrades | 200k+ (full) | N/A |
Premium 1M context | Works | 500k | ~$15 |
RLM via MCP | Works | ~4k summary | ~$0.50-3 |
RLM is often cheaper and leaves context for reasoning. Using OpenRouter with Gemini Flash makes it even more cost-effective.
Robust Architecture
The server includes production-ready features:
Circuit Breaker: Stops requests after consecutive failures, auto-recovers
Rate Limiter: Respects API rate limits (requests/min, tokens/min)
Exponential Backoff: Retries with increasing delays on 429/503 errors
Connection Pooling: Reuses HTTP connections via
httpx.AsyncClientLRU Response Cache: Caches LLM responses to avoid redundant calls
Async Everything: Non-blocking I/O for file collection and API calls
Graceful Shutdown: Proper resource cleanup on server stop
Adding to CLAUDE.md
Add guidance to your project's CLAUDE.md:
## Large Codebase Protocol
When to use `rlm_analyze`:
- Analyzing 50+ files
- Searching entire codebase
- Tasks with "all", "every", or "entire" scope
- Security audits
- Architecture reviews
When NOT to use:
- Working with 1-5 specific files
- Making targeted edits
- Quick lookups in known locations
## Query Tips
Be specific in RLM queries:
BAD: "find problems"
GOOD: "find SQL injection, XSS, hardcoded secrets"
BAD: "summarize"
GOOD: "summarize architecture, main components, data flow"Development
Project Structure
RLM-Mem_MCP/
├── python/
│ ├── src/
│ │ └── rlm_mem_mcp/
│ │ ├── __init__.py # Package exports
│ │ ├── server.py # MCP server entry point
│ │ ├── rlm_processor.py # Core RLM implementation
│ │ ├── repl_environment.py # TRUE RLM REPL with llm_query()
│ │ ├── file_collector.py # Async file collection
│ │ ├── cache_manager.py # Prompt caching (Anthropic-style)
│ │ ├── memory_store.py # SQLite-backed persistent memory
│ │ ├── agent_pipeline.py # Claude Agent SDK integration
│ │ ├── config.py # Environment configuration
│ │ └── utils.py # Performance monitoring
│ ├── tests/
│ │ ├── test_integration.py # End-to-end tests
│ │ ├── test_benchmark.py # Performance benchmarks
│ │ ├── test_stress.py # Stress tests
│ │ └── conftest.py # Test fixtures
│ ├── requirements.txt
│ └── pyproject.toml
├── src/ # TypeScript implementation (optional)
│ ├── index.ts # MCP server (Node.js)
│ ├── core/
│ │ └── rlm-context-manager.ts # RLM tree-based context
│ ├── utils/
│ │ ├── tokenizer.ts # Token counting
│ │ └── text-splitter.ts # Document chunking
│ └── types/
│ └── index.ts # TypeScript interfaces
├── .mcp.json # Project MCP config
├── CLAUDE.md # Claude Code guidance
└── README.mdRunning Tests
cd python
pip install -e ".[dev]"
pytestContributing
Fork the repository
Create a feature branch
Make your changes
Run tests
Submit a pull request
References
Papers
Recursive Language Models (arXiv:2512.24601) - Zhang, Kraska, Khattab - MIT, 2025
Anthropic Documentation
Related Projects
License
Business Source License 1.1 with commercial licensing for monetization - see LICENSE for details.
Free Use: MIT license for non-commercial personal/academic use
Commercial Use: Revenue sharing required - see COMMERCIAL_LICENSE.md
Terms of Service: TERMS_OF_SERVICE.md
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/mosif16/RLM-Mem_MCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server