The macOS Shell MCP server includes a 4-phase caching system for command outputs.
The cache system determines which commands can be cached and for how long based on usage patterns.
- Classification: Commands are classified into caching strategies based on their nature
- Learning: Detects duplicate outputs and adjusts caching behavior
- Persistence: Learned rules persist across server restarts
- Output Analysis: Analyzes command output for dynamic content patterns
- Manual Control: 5 MCP tools provide control over cache behavior
View cache statistics including hit rates, memory usage, and performance metrics.
{
"tool": "cache_stats"
}Returns:
- Total cache entries
- Memory usage
- Hit/miss statistics
- Average time saved
- Top cached commands
Shows why a command has its current cache strategy.
{
"tool": "cache_explain",
"parameters": {
"command": "git status"
}
}Returns:
- Current cache strategy (NEVER, SHORT, MEDIUM, LONG, PERMANENT)
- Reason for the strategy
- Rule source (hardcoded, learned, or user-defined)
Remove commands from the cache.
{
"tool": "cache_clear_command",
"parameters": {
"command": "ls -la",
"cwd": "/optional/directory"
}
}Clear cache entries using regex patterns.
{
"tool": "cache_clear_pattern",
"parameters": {
"pattern": "docker.*"
}
}Mark a command to never be cached.
{
"tool": "cache_mark_never",
"parameters": {
"command": "ps aux",
"reason": "Process list changes constantly",
"pattern": false
}
}Commands are classified into five strategies:
| Strategy | TTL | Use Case | Examples |
|---|---|---|---|
| NEVER | 0s | Status/monitoring commands | git status, ls, docker ps |
| SHORT | 30s | Directory context | pwd |
| MEDIUM | 5m | Config files | cat package.json |
| LONG | 30m | Documentation | cat README.md |
| PERMANENT | 1h | Static content | node --version |
The cache system learns through four phases:
Runtime control through the 5 MCP tools listed above.
- Monitors command outputs using SHA256 hashing
- Detects when identical commands produce identical results within 5 seconds
- Creates never-cache rules for commands with changing outputs
- Saves learned rules to
~/.mcp-cache-rules.json - Maintains up to 1000 rules with LRU eviction
- Tracks usage statistics and timestamps
- Survives server restarts
Detects dynamic content patterns in command output:
- Timestamps: Date/time patterns
- Process IDs: Numeric identifiers that change
- Counters: Incrementing values
- File Sizes: Byte measurements
- IP Addresses: Network addresses
- High Change Patterns: Frequently changing values
User Command → Cache Check → Execute if needed → Output Analysis
↓ ↓
Duplicate Detection ← ─ ─ ─ ─ ─ → Pattern Detection
↓ ↓
Rule Creation ← ─ ─ ─ ─ ─ ─ ─ → Dynamic Prevention
↓
Persistent Storage
MCP_DISABLE_CACHE=true- Disable cachingMCP_CACHE_DEBUG=true- Enable cache logging
- Cache rules:
~/.mcp-cache-rules.json - Log files: Check server logs for cache decisions
Status and monitoring commands execute fresh:
- Git:
status,diff,log,branch - Docker:
ps,stats,logs - System:
ps,top,htop,df,du - File:
ls,find,tail -f - Network:
curl,wget,ping - Time:
date,uptime
Static or slowly-changing content:
- Version checks:
--versioncommands (1 hour) - Documentation:
README.md, help files (30 minutes) - Configuration:
package.json, config files (5 minutes) - Working directory:
pwd(30 seconds)
- Learning: The system adapts to usage patterns
- Manual Override: Use
cache_mark_neverfor commands that should never be cached - Clear When Needed: Use
cache_clear_commandafter changes - Monitor Performance: Check
cache_statsto see cache effectiveness
- Check the cache strategy:
cache_explain - Clear the command:
cache_clear_command - Mark as never-cache if needed:
cache_mark_never
export MCP_DISABLE_CACHE=truerm ~/.mcp-cache-rules.jsonThe cache system provides:
- Time saved: 10-50ms per cached command
- Hit rates: 30-60% for mixed workloads
- Memory usage: Under 10MB
- Learning overhead: <1ms per command execution
The system uses pattern detection and learning for cache management.