Redis MCP Server

repository·main·Indexed 19 days ago

https://github.com/redis/mcp-redis

A Model Context Protocol (MCP) implementation that provides AI agents with a natural language interface to interact with Redis. It enables agents to perform CRUD operations, manage streams, handle pub/sub, and execute vector searches across standard Redis data structures including hashes, lists, sets, sorted sets, JSON, and more. Supports stdio transport, EntraID authentication for Azure Managed Redis, and integration with MCP clients like Claude Desktop.

Tokens
13.5K
Snippets
62
Records
72
Agent score
68%

What's inside redis-mcp-server

  1. Overview of Redis MCP Server

    main

    The Redis MCP Server provides a natural language interface for agentic applications to manage and search data in Redis. It integrates with MCP (Model Content Protocol) clients, allowing AI agents to perform complex Redis operations using natural language commands.

    Key capabilities include:

    • Natural Language Queries: Agents can issue commands like "Store the entire conversation in a stream" or "Cache this item".
    • Full Redis Support: Handles hashes, lists, sets, sorted sets, streams, and more.
    • Search & Filtering: Supports efficient data retrieval and vector search.
    • Transport Support: Currently supports the stdio transport. Support for stremable-http is planned for the future.
  2. Configure Redis MCP Server for Claude Desktop

    main

    To use the Redis MCP Server with Claude Desktop, add a configuration entry to your claude_desktop_config.json. You must provide the full path to the uvx executable.

    Basic Redis connection

    Connects to a local Redis instance via stdio.

    Azure Managed Redis with EntraID authentication

    For Azure Managed Redis, provide the connection URL and set the following environment variables to handle EntraID authentication:

    • REDIS_ENTRAID_AUTH_FLOW: Set to default_credential.
    • REDIS_ENTRAID_SCOPES: Set to https://redis.azure.com/.default.
    {
      "mcpServers": {
        "redis-mcp-server": {
            "type": "stdio",
            "command": "/FULL/PATH/TO/uvx",
            "args": [
                "--from", "redis-mcp-server@latest",
                "redis-mcp-server",
                "--url", "redis://localhost:6379/0"
            ]
        }
      }
    }
  3. Install Redis MCP Server via PyPI

    main

    The recommended way to install the Redis MCP Server is via PyPI using uvx. This command downloads the server on the fly, creates a temporary environment, and runs it.

    To configure it in an MCP-compatible tool (like Claude Desktop), use the following JSON structure:

    {
      "mcpServers": {
        "RedisMCPServer": {
          "command": "uvx",
          "args": [
            "--from",
            "redis-mcp-server@latest",
            "redis-mcp-server",
            "--url",
            "\"redis://localhost:6379/0\""
          ]
        }
      }
    }
    {
      "mcpServers": {
        "RedisMCPServer": {
          "command": "uvx",
          "args": [
            "--from",
            "redis-mcp-server@latest",
            "redis-mcp-server",
            "--url",
            "\"redis://localhost:6379/0\""
          ]
        }
      }
    }
  4. Install Redis MCP Server from GitHub

    main

    You can run the server directly from the GitHub repository using uvx. It is recommended to use a tagged release rather than the main branch to avoid breaking changes.

    Example running version 0.2.0:

    uvx --from git+https://github.com/redis/mcp-redis.git@0.2.0 redis-mcp-server --url redis://localhost:6379/0
    uvx --from git+https://github.com/redis/mcp-redis.git@0.2.0 redis-mcp-server --url redis://localhost:6379/0
  5. Configure logging verbosity

    main

    The server uses Python's standard logging. By default, it logs at the WARNING level. You can control the verbosity using the MCP_REDIS_LOG_LEVEL environment variable.

    Accepted values (case-insensitive):

    • DEBUG
    • INFO
    • WARNING (or WARN)
    • ERROR
    • CRITICAL (or FATAL)
    • NOTSET
    • Numeric values (e.g., "10", "+20")

    Note on Handlers: If the host environment (like VS Code or uv) has already installed console handlers, the server will not add its own. It will only adjust existing handler thresholds to ensure your chosen level is not filtered out.

    # Set log level to DEBUG for troubleshooting
    MCP_REDIS_LOG_LEVEL=DEBUG uvx --from redis-mcp-server@latest redis-mcp-server --url redis://localhost:6379/0
  6. Integrate Redis MCP Server with OpenAI Agents SDK

    main

    To use the Redis MCP Server within the OpenAI Agents SDK, install the required Python SDK and configure your OpenAI API key. You can then run the provided assistant example to start your agent workflow.

    1. Install the SDK: pip install openai-agents
    2. Set your API key: export OPENAI_API_KEY="<openai_token>"
    3. Run the application: python3.14 redis_assistant.py
    pip install openai-agents
    export OPENAI_API_KEY="<openai_token>"
    python3.14 redis_assistant.py
  7. Configure Redis MCP Server connection settings

    main

    The Redis MCP Server can be configured using command line arguments or environment variables. Command line arguments take precedence over environment variables, which in turn take precedence over default values.

    Command Line Arguments

    Use CLI flags to specify connection details. This is useful for quick starts or when running via uvx.

    Environment Variables

    Use environment variables for persistent configuration. Common variables include REDIS_HOST, REDIS_PORT, REDIS_DB, REDIS_USERNAME, and REDIS_PWD.

    # Basic Redis connection via CLI
    uvx --from redis-mcp-server@latest redis-mcp-server \
      --host localhost \
      --port 6379 \
      --password mypassword
    
    # Using Redis URI (simpler)
    uvx --from redis-mcp-server@latest redis-mcp-server \
      --url redis://user:pass@localhost:6379/0
  8. Configure Redis MCP Server for VS Code with GitHub Copilot

    main

    To use the Redis MCP Server in VS Code, you must first enable agent mode in your settings.json:

    {
      "chat.agent.enabled": true
    }

    Starting with VS Code v1.102, MCP servers should be configured in a dedicated mcp.json file rather than settings.json.

    You can use uvx to run the server. To prevent uvx installation messages from appearing as warnings in your MCP client logs, use the -qq flag to enable silent mode.

    For local development, you can use uv to run the server directly from your source directory. This allows you to pass connection details via environment variables like REDIS_HOST, REDIS_PORT, REDIS_USERNAME, and REDIS_PWD.

    // mcp.json example using uvx with silent mode
    {
      "servers": {
        "redis": {
          "type": "stdio",
          "command": "uvx",
          "args": [
            "-qq",
            "--from", "redis-mcp-server@latest",
            "redis-mcp-server",
            "--url", "redis://localhost:6379/0"
          ]
        }
      }
    }
  9. Development Installation and Claude Desktop Configuration

    main

    For development, clone the repository and use uv to manage the environment. When running the server directly via src/main.py, you must use environment variables for configuration.

    Setup steps:

    1. git clone https://github.com/redis/mcp-redis.git
    2. cd mcp-redis
    3. uv venv && source .venv/bin/activate && uv sync

    Claude Desktop Configuration:

    To use the development version in Claude Desktop, edit claude_desktop_config.json (on macOS: ~/Library/Application Support/Claude/) with the following structure. Note that you must provide the full path to your uv executable.

    Required Environment Variables:

    • REDIS_HOST
    • REDIS_PORT
    • REDIS_PWD
    • REDIS_SSL (True|False)
    • REDIS_SSL_CA_PATH
    • REDIS_CLUSTER_MODE (True|False)
    {
        "mcpServers": {
            "redis": {
                "command": "<full_path_uv_command>",
                "args": [
                    "--directory",
                    "<your_mcp_server_directory>",
                    "run",
                    "src/main.py"
                ],
                "env": {
                    "REDIS_HOST": "<your_redis_database_hostname>",
                    "REDIS_PORT": "<your_redis_database_port>",
                    "REDIS_PWD": "<your_redis_database_password>",
                    "REDIS_SSL": true,
                    "REDIS_SSL_CA_PATH": "<your_redis_ca_path>",
                    "REDIS_CLUSTER_MODE": false
                }
            }
        }
    }
  10. Deploy Redis MCP Server with Docker

    main

    You can use a Dockerized deployment. You can either build your own image using the provided Dockerfile or use the official mcp/redis image from Docker Hub.

    Build your own image:

    docker build -t mcp-redis .

    Claude Desktop Configuration (Docker):

    To run the server inside a container via Claude Desktop, add this to your claude_desktop_config.json:

    {
      "mcpServers": {
        "redis": {
          "command": "docker",
          "args": [
            "run",
            "--rm",
            "--name",
            "redis-mcp-server",
            "-i",
            "-e", "REDIS_HOST=<redis_hostname>",
            "-e", "REDIS_PORT=<redis_port>",
            "-e", "REDIS_USERNAME=<redis_username>",
            "-e", "REDIS_PWD=<redis_password>",
            "mcp-redis"
          ]
        }
      }
    }

    To use the official image, replace mcp-redis with mcp/redis in the arguments.

    {
      "mcpServers": {
        "redis": {
          "command": "docker",
          "args": [
            "run",
            "--rm",
            "--name",
            "redis-mcp-server",
            "-i",
            "-e", "REDIS_HOST=<redis_hostname>",
            "-e", "REDIS_PORT=<redis_port>",
            "-e", "REDIS_USERNAME=<redis_username>",
            "-e", "REDIS_PWD=<redis_password>",
            "mcp-redis"
          ]
        }
      }
    }
  11. Configure EntraID (Azure AD) authentication

    main

    The Redis MCP Server supports EntraID authentication for Azure Managed Redis, providing automatic token management and renewal. You can choose from three authentication flows:

    1. Service Principal: Application-based authentication using client credentials.
    2. Managed Identity: For Azure-hosted applications (supports system_assigned and user_assigned).
    3. Default Azure Credential: Automatic credential discovery (recommended for local development with Azure CLI).

    To use EntraID, set REDIS_ENTRAID_AUTH_FLOW and the corresponding identity credentials via environment variables.

    # Example: Local development with Azure CLI
    az login
    export REDIS_ENTRAID_AUTH_FLOW=default_credential
    export REDIS_URL=redis://your-azure-redis.redis.cache.windows.net:6379
  12. Configure Redis MCP Server in Augment

    main

    The preferred method for Augment is using the Easy MCP feature. Alternatively, you can manually import the server by adding the following JSON configuration to your Augment setup. This example uses uvx to run the latest version of the server pointing to a local Redis instance.

    {
      "mcpServers": {
        "Redis MCP Server": {
          "command": "uvx",
          "args": [
            "--from",
            "redis-mcp-server@latest",
            "redis-mcp-server",
            "--url",
            "redis://localhost:6379/0"
          ]
        }
      }
    }