# nextjs-cache-handler-mcp

This MCP server lets an AI agent inspect a Next.js Redis cache, trace tag state, model SWR reads, and invalidate tags with a confirmation gate.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 6
- Author: leejpsd
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/leejpsd/nextjs-cache-handler/tree/HEAD/mcp
- Updated: 2026-08-26
- HTML: https://affpapa.org/en/nevibecode/mcp/nextjs-cache-handler-mcp

## What it does

The server exposes cache diagnostics for a running Next.js deployment. An agent can test Redis health, search matching keys, decode one entry, and inspect its layer, kind, tags, TTL, age, compression, and size. It can also split a raw Redis key into its namespace parts. `tag_state` checks invalidation across both cache layers, while `simulate_swr` predicts whether a read sees fresh, stale, or expired data.

\`invalidate_tag` offers soft and hard invalidation, but remains a dry run until `confirm: true` is supplied. The process runs on the machine hosting the MCP setup and reaches Redis through `REDIS_URL`, which is required. `DEPLOYMENT_VERSION` scopes namespace-aware operations; custom cache handlers may also need `CACHE_KEY_PREFIX` or `ISR_KEY_PREFIX`. For AWS ElastiCache, a local process needs an SSH tunnel or bastion into the VPC. Without `REDIS_URL`, the server cannot connect to Redis.

## Requirements
- Needs: Node.js (commands run via npx)
- Environment variables: `REDIS_URL`, `DEPLOYMENT_VERSION`, `HASH_TAG` — keys and tokens: ask the human for the values, never commit them or put them in shared files.

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add --env REDIS_URL=<REDIS_URL> --env DEPLOYMENT_VERSION=<DEPLOYMENT_VERSION> --env HASH_TAG=<HASH_TAG> --transport stdio mcp -- npx -y @leejpsd/nextjs-cache-handler-mcp
```
Replace <…> with your own values

### Codex

**Platform CLI**
```bash
codex mcp add mcp --env REDIS_URL=<REDIS_URL> --env DEPLOYMENT_VERSION=<DEPLOYMENT_VERSION> --env HASH_TAG=<HASH_TAG> -- npx -y @leejpsd/nextjs-cache-handler-mcp
```
Replace <…> with your own values

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "mcp": {
            "command": "npx",
            "args": [
                "-y",
                "@leejpsd/nextjs-cache-handler-mcp"
            ],
            "env": {
                "REDIS_URL": "<REDIS_URL>",
                "DEPLOYMENT_VERSION": "<DEPLOYMENT_VERSION>",
                "HASH_TAG": "<HASH_TAG>"
            }
        }
    }
}
```
Replace <…> with your own values

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "mcp": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "@leejpsd/nextjs-cache-handler-mcp"
            ],
            "env": {
                "REDIS_URL": "<REDIS_URL>",
                "DEPLOYMENT_VERSION": "<DEPLOYMENT_VERSION>",
                "HASH_TAG": "<HASH_TAG>"
            }
        }
    }
}
```
Replace <…> with your own values

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add -e REDIS_URL=<REDIS_URL> -e DEPLOYMENT_VERSION=<DEPLOYMENT_VERSION> -e HASH_TAG=<HASH_TAG> mcp npx -y @leejpsd/nextjs-cache-handler-mcp
```
Replace <…> with your own values

## When to use it
- check Redis health and cache contents
- search Next.js keys by pattern
- inspect an entry’s tags and TTL
- trace tag invalidation across cache layers
- predict fresh, stale, or expired reads

## Example prompts
- Ask the agent to run `cache_health` and report the Redis status and cached layers.
- Use `tag_state` to check whether the `products` tag is invalidated on both layers.
- Run `simulate_swr` for this entry and explain what a read will do.

## Similar
- [MCP Toolbox for Databases](https://affpapa.org/en/nevibecode/mcp/googleapis-mcp-toolbox-for-databases.md) — MCP server · ★ 16730
- [PostHog MCP Server](https://affpapa.org/en/nevibecode/mcp/posthog-mcp-server.md) — MCP server · ★ 40459
- [OpenWork MCP Gateway](https://affpapa.org/en/nevibecode/mcp/openwork-mcp-gateway.md) — MCP server · ★ 24271
- [Keploy](https://affpapa.org/en/nevibecode/mcp/keploy.md) — MCP server · ★ 18779
- [Nhost](https://affpapa.org/en/nevibecode/mcp/nhost.md) — MCP server · ★ 9369
- [basebalance.cloud — x402 RPC & MCP gateway](https://affpapa.org/en/nevibecode/mcp/basebalancecloud-x402-rpc-mcp-gateway.md) — MCP server · ★ 7548

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
