BerkantACUN

redis-guard-mcp

Community BerkantACUN
Updated

A Redis MCP server whose allowlist IS the tool surface — no generic command-execution escape hatch, plus real ACL enforcement verified with ACL DRYRUN ground truth.

redis-guard-mcp

A Redis MCP server whose "read-only" isn't a label — it's the entire toolsurface. Every tool maps to exactly one safe, read-only Redis commandthrough redis-py's typed API. There is no "run this command string" toolto mislabel.

Why this exists

Redis is one of the most deployed pieces of infrastructure in professionalbackends (cache, session store, queue, rate limiter, pub/sub), and itscommand surface includes some of the most dangerous single commands in anywidely-used data store:

  • EVAL/EVALSHA/FCALL — arbitrary Lua execution inside the Redisprocess.
  • CONFIG SET dir + CONFIG SET dbfilename + SAVE — the standard,widely-documented technique for writing an arbitrary file (e.g. a webshell into a web root, or a cron job) to disk through Redis alone.
  • MODULE LOAD — loads an arbitrary shared library into the Redisprocess. Direct RCE if an attacker can get a .so/.dll onto disk.
  • FLUSHALL/FLUSHDB — deletes every key in the database, immediately,no confirmation.
  • SHUTDOWN, DEBUG, SLAVEOF/REPLICAOF, ACL, CLIENT KILL —server-crashing, replication-hijacking, permission-rewriting, andsession-terminating admin surface.

A published audit of MCP servers found one where a command-execution toolwas labeled readonly: true in its metadata but still accepted and ranEVAL and FLUSHALL — the metadata was decorative, not enforced. Checkeddirectly against the official redis/mcp-redis server: its owndocumentation states the only mitigation for any of the above isconfiguring Redis ACLs yourself — the server ships with no built-inblocking of EVAL, FLUSHALL, CONFIG, MODULE, or DEBUG, and noread-only mode of its own. Safety is entirely the operator's responsibility,by default, out of the box.

How redis-guard-mcp is different

  1. The allowlist isn't a filter — it's the tool surface. Nothing inthis server takes an arbitrary command string. Every tool is a specificPython function that calls one specific redis-py method (r.get(key),r.hget(key, field), ...). There is no code path through which EVAL,CONFIG, MODULE, FLUSHALL, or any other command not explicitlyimplemented as its own tool could ever be sent — not because it'schecked and rejected, but because the client code to send it simplydoesn't exist here.
  2. Real privilege enforcement too, not just app-level restriction. Therecommended (and startup-checked) setup connects with a Redis ACL usercreated with +@read -@write -@admin -@dangerous. Even a bug in thisserver's own code couldn't run a write or admin command against acorrectly-configured connection, because Redis itself would refuse itat the protocol level. Rule order matters — CLIENT KILL/PAUSE/LIST/UNBLOCK belong to both @admin and @connection, so... -@admin +@connection (the wrong order) silently re-grants thosefour commands. This is not a hypothetical: an early version of thisproject's own setup script had exactly that ordering, and a securityreview ran CLIENT PAUSE against the shipped "correctly-configured"user and it worked — a server-wide DoS primitive, from a user thisproject's own documentation claimed couldn't do it. Fixed by putting+@connection first; see scripts/setup_dev_redis.sh for the correctorder and a comment explaining why it can't be swapped back.
  3. Cursor-based, never single-shot, for every collection. KEYS is inRedis's own built-in @dangerous category because a single call canblock the entire server serializing a large keyspace — the same istrue of HGETALL on a large hash and SMEMBERS on a large set, justless famously. Every "give me a collection" tool here is eithercursor-based (redis_scan_keys/redis_hscan/redis_sscan) or cappedat 1000 items per call with an explicit truncated flag(redis_lrange/redis_zrange) — never a call that can make theserver materialize an arbitrarily large collection in one shot.
  4. A privilege check that asks Redis, not a re-implementation of Redis'sown semantics. redis_check_permissions() uses ACL DRYRUN — Redis'sown "would this command actually succeed for this user" answer — againsta curated list of dangerous commands, rather than trying to re-derivethe answer from parsing the ACL rule list (which is exactly how therule-order bug above happened: a category-list read in isolation can'tsee that @admin and @connection overlap). would_succeed shouldalways come back empty.

Tools

Tool Does
redis_get(key) Get a string value
redis_mget(keys) Get multiple string values as {key: value} (max 200 keys)
redis_type(key) Report a key's Redis type
redis_ttl(key) Seconds until expiry (-1 none, -2 missing)
redis_exists(keys) Count how many of the given keys exist (max 200 keys)
redis_scan_keys(pattern="*", cursor=0) One SCAN page of matching keys
redis_hget(key, field) One hash field
redis_hscan(key, cursor=0) One HSCAN page of a hash's fields
redis_lrange(key, start=0, stop=None) List elements, capped at 1000 per call
redis_sscan(key, cursor=0) One SSCAN page of a set's members, sorted
redis_zrange(key, start=0, stop=None, with_scores=False) Sorted set members, capped at 1000 per call
redis_dbsize() Total key count
redis_check_permissions() Ground-truth ACL DRYRUN check against a curated dangerous-command list — would_succeed should always be empty

Setup

pip install redis-guard-mcp
export REDIS_GUARD_URL="redis://readonly_user:password@localhost:6379/0"
redis-guard-mcp

REDIS_GUARD_URL is required — there is no default. Point your MCP client at the redis-guard-mcp command with it set in its env config. See scripts/setup_dev_redis.sh for a working, correctly-ordered example of provisioning the restricted ACL user (+@connection +@read -@write -@admin -@dangerous, plus the three narrow ACL WHOAMI/ACL GETUSER/ACL DRYRUN exceptions redis_check_permissions itself needs — see client.py for why those are safe to grant despite being individually outside @read).

Testing

pip install -e ".[dev]"
scripts/setup_dev_redis.sh   # starts a Redis container + provisions the ACL user + seeds data
pytest tests/ -v

34 tests, almost all against the real local container (a couple of pure config-validation tests need no Redis and skip-check independently); skips automatically if the container isn't reachable. Includes a regression test for the exact CLIENT PAUSE rule-order bug above, and an AST-based structural test asserting the precise set of redis-py methods commands.py calls, so a new tool being added later gets noticed here rather than silently passing review.

Status

v0.1.0. Went through adversarial security review before its first commit, which found and this now fixes: the ACL rule-order bug above (confirmed by actually running CLIENT PAUSE against the shipped setup), two blind spots in the original category-based permission check (now replaced with ACL DRYRUN), unbounded collection reads on a shared Redis instance (now capped/paginated), a non-idempotent dev seed script, and a lazy-singleton thread-safety race in the MCP tool layer.

License

MIT

MCP Server · Populars

MCP Server · New

    lifan-builds

    Faster Mac Use (fmu)

    Background-first, multi-cursor browser and native macOS computer-use engine for AI agents

    Community lifan-builds
    agent360dev

    Agent360 Browser MCP

    The browser tool that can stop and ask you. A 2FA code, a CAPTCHA, a choice only you can make: it asks on your screen, then carries on in the same signed-in Chrome. 41 tools, MCP clients that run local servers, MIT.

    Community agent360dev
    robinAKL

    Agent Room

    Put Claude Code, Cursor, Codex, Gemini & Antigravity in one room — real-time multi-agent AI collaboration over MCP for distributed dev, code review, PR handoff & frontend↔backend integration. Free, self-hostable, MCP-native.

    Community robinAKL
    blen-labs

    Capture MCP

    AI-native Model Context Protocol (MCP) server that integrates SAM.gov, USASpending.gov, and Tango APIs to capture and analyze federal procurement and spending data through natural language queries. Responses include both human-readable text and structured JSON so MCP-compatible clients can consume the data programmatically.

    Community blen-labs
    PanStudio

    ZulipChat MCP Server

    ZulipChat MCP Server - A Model Context Protocol server that bridges AI agents with Zulip Chat. Built with FastMCP for lightning-fast performance, featuring comprehensive chat management and intelligent summarization. Transform your Zulip workspace into an AI-powered collaboration hub!

    Community PanStudio