Home / MCP / Memory Cache Server

Memory Cache Server

An MCP server that reduces token usage by caching data between language model interactions.

javascript
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "memory_cache": {
            "command": "node",
            "args": [
                "/path/to/ib-mcp-cache-server/build/index.js"
            ],
            "env": {
                "MAX_ENTRIES": "5000",
                "MAX_MEMORY": "209715200",
                "DEFAULT_TTL": "7200",
                "CHECK_INTERVAL": "120000",
                "STATS_INTERVAL": "60000"
            }
        }
    }
}

Memory Cache Server is an MCP server that minimizes token usage by caching data between language model interactions. It works with any MCP client and supports caching across repeated reads or computations, so you get faster responses and lower token costs automatically.

How to use

You use Memory Cache Server by running it as an MCP-backed service that your MCP client talks to. The server automatically stores data when first encountered and serves cached data on subsequent requests, so repeated reads of the same content or repeated analyses become faster and cheaper in tokens.

How to install

Prerequisites: You need Node.js installed on your system. You also need an MCP client configured to communicate with MCP servers.

Manual installation steps: you can add the Memory Cache Server to your MCP client configuration so your client starts the server automatically when you begin interactions.

{
  "mcpServers": {
    "memory-cache": {
      "command": "node",
      "args": ["/path/to/ib-mcp-cache-server/build/index.js"]
    }
  }
}

Additional sections

Configuration, environment overrides, and practical usage tips are provided to help you tune the server for your workload and to verify it is operating as expected.

Configuration

Configure the server via a config.json file or environment variables. Key options include cache size, memory limit, default TTL, and cleanup intervals.

{
  "maxEntries": 1000,
  "maxMemory": 104857600,
  "defaultTTL": 3600,
  "checkInterval": 60000,
  "statsInterval": 30000
}

Environment variable configuration

Override configuration using environment variables in your MCP settings. The following examples show how to set overrides for the cache parameters.

{
  "mcpServers": {
    "memory-cache": {
      "command": "node",
      "args": ["/path/to/build/index.js"],
      "env": {
        "MAX_ENTRIES": "5000",
        "MAX_MEMORY": "209715200",
        "DEFAULT_TTL": "7200",
        "CHECK_INTERVAL": "120000",
        "STATS_INTERVAL": "60000"
      }
    }
  }
}

Testing the cache in practice

Test scenarios help you verify the cache is active and providing token savings. Look for faster responses on repeated reads, consistent answers for unchanged content, and no unnecessary re-reading of data.

  • File Reading Test: read a large file, then read it again; the second read should be faster due to caching.
  • Data Analysis Test: perform the same analysis twice; the second result should come from cache.
  • Project Navigation Test: query the same file/directory multiple times; subsequent requests are served from cache.

Optimization tips

Fine-tune TTLs and memory limits to balance freshness and token savings. Monitor hit rates to determine whether to adjust TTLs or cache size for better performance.

Notes on usage and behavior

The server automatically stores data on first encounter, serves cached data when available, and removes old or unused items based on your settings. It tracks statistics to help you evaluate cache effectiveness.

Security considerations

Treat cached data like any other sensitive data. Use appropriate access controls and avoid caching secrets or credentials in shared environments where unauthorized parties could retrieve them.

Troubleshooting

If you encounter issues, check the MCP client console for errors related to the memory-cache server. Ensure the server process is running and that the configured command and paths are correct.

Available tools

File Content Caching

Caches the contents of files when read for the first time and serves them from cache on subsequent reads to save tokens.

Computation Results Caching

Stores results of computations or analyses so repeated inputs yield cached results, reducing token usage.

Frequently Accessed Data Caching

Keeps frequently accessed data in cache for quick retrieval across multiple requests until TTL expiry.