Redis MCP server

Integrates with Redis and AWS MemoryDB for fast, in-memory data storage and retrieval, enabling caching, session management, and real-time analytics.
Back to servers
Setup instructions
Provider
Prajwal S Nayak
Release date
Feb 02, 2025
Language
Python
Stats
22 stars

The MCP Server Redis provides a Model Context Protocol server implementation for Redis database interactions, allowing language models to directly access and manipulate data in Redis through a structured API interface.

Installation

To install the MCP Server Redis, follow these steps:

Prerequisites

Make sure you have UV package manager installed:

# If UV is not installed, follow instructions at https://docs.astral.sh/uv/

Setup

  1. Create and activate a virtual environment:
uv venv
source .venv/bin/activate
  1. Install dependencies:
uv sync
  1. Configure your Redis connection:

    • Create a .env file based on the provided .env.example
    • Add your Redis connection details to this file
  2. Start the server:

python src/server.py

Using the MCP Server

Available Resources

The server provides the following endpoint resources:

  • redis://status - Check current Redis connection status
  • redis://info - Get detailed Redis server information
  • redis://keys/{pattern} - List all keys matching the specified pattern

Available Tools

Basic Operations

  • get_value

    • Retrieves a value from Redis by key
    • Parameters: key
  • set_value

    • Sets a value in Redis with optional expiration
    • Parameters: key, value, expiry (optional)
  • delete_key

    • Deletes a key from Redis
    • Parameters: key
  • increment

    • Increments a numeric value
    • Parameters: key, amount (optional)

List Operations

  • list_push

    • Adds values to a Redis list
    • Parameters: key, values, side (optional: "left" or "right")
  • list_range

    • Gets a range of values from a Redis list
    • Parameters: key, start, end

Hash Operations

  • hash_set

    • Sets field values in a Redis hash
    • Parameters: key, fields (dictionary of field-value pairs)
  • hash_get

    • Gets field values from a Redis hash
    • Parameters: key, fields (list of fields to retrieve)

Set Operations

  • set_add

    • Adds members to a Redis set
    • Parameters: key, members
  • set_members

    • Gets all members from a Redis set
    • Parameters: key

Pub/Sub Operations

  • publish_message
    • Publishes a message to a Redis channel
    • Parameters: channel, message

Testing and Integration

You can test the server using the MCP Inspector:

mcp dev src/server.py

Or install it in Claude Desktop:

mcp install src/server.py

Usage Example

Here's an example conversation showing how to use the MCP Server:

  1. Checking the Redis connection status:
User: What's the current Redis connection status?
LLM: [Reading resource redis://status]
The Redis server is currently connected and running on localhost:6379, database 0.
  1. Storing data in Redis:
User: Can you store my name "Alice" in Redis?
LLM: [Calling set_value with key="name" value="Alice"]
Successfully set key 'name'
  1. Verifying stored data:
User: Yes please verify it
LLM: [Calling get_value with key="name"]
Alice

The server provides automatic reconnection to Redis if the connection is lost and includes error handling for all operations.

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "redis" '{"command":"python","args":["src/server.py"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "redis": {
            "command": "python",
            "args": [
                "src/server.py"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "redis": {
            "command": "python",
            "args": [
                "src/server.py"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later