Universal response management wrapper for any MCP server
Break free from token limits - Automatic caching, pagination, and querying for large MCP responses.
MCP servers frequently return responses that exceed LLM context limits:
- 🌐 Full DOM content (1MB+ HTML)
- 📁 Large file system listings
- 🎨 Screenshot data
- 🔍 Extensive search results
- 🤖 UI accessibility trees
Result: Error: Response exceeds maximum length of 1048576 bytes
mcp-cache is a transparent proxy that wraps any MCP server and automatically:
- 🎯 Detects responses > 900KB
- 💾 Caches them with a unique ID
- 📊 Returns a manageable summary + query tools
- 🔍 Lets you search/paginate through cached data
Zero modifications required to your MCP servers!
# Wrap any MCP server command
npx mcp-cache <your-mcp-server-command>
# Examples
npx mcp-cache python -m chrome_automation_mcp
npx mcp-cache npx @playwright/mcp@latest
npx mcp-cache node my-custom-server.js✨ Transparent - Works with ANY MCP server 🎛️ Client-Aware - Auto-detects Claude/Cursor/etc token limits 💾 Smart Caching - 1-hour TTL with automatic cleanup (every 5min) 📄 Pagination - Automatic chunking for large responses 🔍 Query Tools - Text search, JSONPath, regex on cached data ⚙️ Zero Config - Works out of the box 🪶 Lightweight - <10ms overhead
npx mcp-cache <command>npm install -g mcp-cache
mcp-cache <command>Add to your claude_desktop_config.json:
{
"mcpServers": {
"chrome-with-cache": {
"command": "npx",
"args": [
"mcp-cache",
"python",
"-m",
"chrome_automation_mcp"
]
},
"playwright-with-cache": {
"command": "npx",
"args": [
"mcp-cache",
"npx",
"@playwright/mcp@latest"
]
}
}
}With custom settings:
{
"mcpServers": {
"chrome": {
"command": "npx",
"args": ["mcp-cache", "python", "-m", "chrome_automation_mcp"],
"env": {
"MCP_CACHE_MAX_TOKENS": "30000",
"MCP_CACHE_TTL": "7200"
}
}
}
}You: Get the full DOM of this page
Chrome MCP: [Returns 1.3MB of HTML]
Claude: ❌ Error: Response exceeds maximum length
You: Get the full DOM of this page
mcp-cache: Response too large (1.29MB, 133 chunks).
Saved as resp_abc123.
Use query_response('resp_abc123', '<query>') to search.
Use get_chunk('resp_abc123', 0) to read chunks.
You: query_response('resp_abc123', 'button.submit', limit=5)
mcp-cache: [Returns 5 matching buttons]
✅ Success!
When you wrap a server, mcp-cache adds 6 powerful tools:
Search cached responses with text, JSONPath, or regex:
// Text search (case-insensitive)
query_response('resp_abc123', 'submit button', limit=10)
// JSONPath (complex queries)
query_response('resp_abc123', '$.div[?(@.class=="navbar")]')
// Regex (pattern matching)
query_response('resp_abc123', '/href=".*\\.pdf"/')Retrieve specific chunks sequentially:
get_chunk('resp_abc123', 0) // First chunk
get_chunk('resp_abc123', 1) // Second chunkView all cached responses:
list_responses()
// Returns: [{id, tool, size, created, expires}, ...]Get metadata about a cached response:
get_response_info('resp_abc123')
// Returns: {id, tool, sizeBytes, chunks, expiresAt, ...}Extend TTL by another hour:
refresh_response('resp_abc123')
// Extends expiry timeManually delete a cached response:
delete_response('resp_abc123')# Token limits
MCP_CACHE_MAX_TOKENS=25000 # Override auto-detection
MCP_CACHE_CHUNK_SIZE=10000 # Chunk size in tokens
# Cache settings
MCP_CACHE_CACHE_DIR=~/.mcp-cache/cache # Cache location
MCP_CACHE_TTL=3600 # TTL in seconds (1 hour)
# Features
MCP_CACHE_ENABLE_INDEXING=true # Enable full-text indexing
MCP_CACHE_COMPRESSION=true # Compress cached responses
# Debug
MCP_CACHE_DEBUG=false # Enable debug loggingAutomatic token limits based on detected client:
| Client | Default Token Limit |
|---|---|
| Claude Desktop | 25,000 |
| Claude Code | 25,000 |
| Cursor | 30,000 |
| Cline | 25,000 |
| Other | 20,000 |
Override with MCP_CACHE_MAX_TOKENS environment variable.
┌─────────────────┐
│ Claude Desktop │
│ (MCP Client) │
└────────┬────────┘
│ stdio
↓
┌──────────────────────────┐
│ mcp-cache (Proxy) │
│ 1. Spawns target server │
│ 2. Forwards all messages│
│ 3. Intercepts responses │
│ 4. Caches if > 900KB │
│ 5. Adds query tools │
└────────┬─────────────────┘
│ stdio
↓
┌──────────────────┐
│ Target MCP │
│ Server │
│ (chrome, etc.) │
└──────────────────┘
Cache Storage:
- Location:
~/.mcp-cache/cache/ - Format: JSON files + metadata
- Cleanup: Every 5 minutes (automatic)
- TTL: 1 hour (default)
Enable debug logging:
MCP_CACHE_DEBUG=true npx mcp-cache python -m chrome_automation_mcpCheck cache contents:
ls -lh ~/.mcp-cache/cache/
du -sh ~/.mcp-cache/cache/{
"mcpServers": {
"chrome": {
"command": "npx",
"args": ["mcp-cache", "python", "-m", "chrome_automation_mcp"],
"env": {
"MCP_CACHE_CACHE_DIR": "/tmp/my-cache"
}
}
}
}- Use specific queries - Instead of searching the entire DOM, use CSS selectors
- Set lower limits -
query_response(..., limit=10)instead of default 100 - Use chunks for browsing - Sequential
get_chunk()calls for exploration - Refresh responses - Extend TTL if you need data longer than 1 hour
This means the response was SO large (>1MB) it couldn't even be cached. Solutions:
- Use more specific tool calls (e.g., CSS selectors instead of full DOM)
- Break operations into smaller parts
- Use simpler tools that return less data
Check automatic cleanup is running:
tail -f ~/.mcp-cache/debug.log
# Look for: "mcp-cache: Cleaned up X expired response(s)"Manual cleanup:
rm -rf ~/.mcp-cache/cache/*This is cosmetic - the cache still works. The client detection happens during runtime and defaults to claude-ai if not detected.
- ✅ Node.js: 18.0.0+
- ✅ MCP Protocol: 2024-11-05, 2025-06-18
- ✅ Clients: Claude Desktop, Claude Code, Cursor, Cline, custom clients
- ✅ Servers: ALL MCP servers (language-agnostic)
# Clone repository
git clone https://github.com/swapnilsurdi/mcp-cache.git
cd mcp-cache
# Install dependencies
npm install
# Build
npm run build
# Test locally
node dist/index.js python -m chrome_automation_mcpContributions welcome! Please read CONTRIBUTING.md first.
MIT - See LICENSE file
- chunky-mcp - Requires modifying server code
- MCP Inspector - Debugging tool, not a production wrapper
What makes mcp-cache different:
- ✨ No server modifications needed
- ✨ Production-ready (not just debugging)
- ✨ Automatic cleanup
- ✨ Advanced query capabilities
Built for the MCP community. Inspired by the need to work with real-world data that doesn't fit in token limits.
Built for seamless MCP integration