MCP ExplorerExplorer

Redis

@prajwalnayak7on a month ago
22 MIT
FreeCommunity
Databases
MCP server to interact with Redis Server, AWS Memory DB, etc for caching or other use-cases where in-memory and key-value based storage is appropriate

Overview

What is Redis

The mcp-server-redis is a server designed for seamless integration with Redis, allowing users to manage key-value data effectively through a structured framework. It includes various tools and resources for performing basic operations, managing lists, hashes, and sets, along with Pub/Sub capabilities. This project utilizes a modular structure for better maintenance and extension.

Use cases

This server can be used for a variety of applications, such as storing user data, caching responses, handling real-time messaging through Pub/Sub, and managing key-value pairs for applications requiring fast access to data. It’s suitable for both small-scale projects and larger systems needing robust Redis functionality.

How to use

To use the server, first install the required dependencies and set up a virtual environment. Configure your Redis connection using the .env.example file as a reference. Finally, run the server with the command python src/server.py to start managing data through the provided resources and tools.

Key features

Key features include connection status monitoring, detailed Redis server information retrieval, and an array of tools for basic operations like setting, getting, and deleting keys. The server supports complex data types via lists, hashes, and sets, along with message publishing capabilities through Pub/Sub. It incorporates automatic reconnection for reliability.

Where to use

The mcp-server-redis can be implemented in any application that requires fast data retrieval and storage with Redis. It is especially useful in web applications, real-time analytics, caching solutions, and any environment where efficient data handling and pub/sub messaging are necessary.

Content

MseeP.ai Security Assessment Badge

Usage

The structure is as follows:

mcp-server-redis/
├── src/
│   ├── __init__.py
│   ├── main.py           # Main entry point
│   ├── config.py         # Configuration
│   ├── connection.py     # Redis connection management
│   ├── resources/        # Resource implementations
│   │   ├── __init__.py
│   │   ├── status.py     # Connection status resources
│   │   └── keys.py       # Key-related resources
│   └── tools/           # Tool implementations
│       ├── __init__.py
│       ├── basic.py     # Basic Redis operations
│       ├── lists.py     # List operations
│       ├── hashes.py    # Hash operations
│       ├── sets.py      # Set operations
│       └── pubsub.py    # Pub/Sub operations
├── tests/              # Test directory
│   └── __init__.py
├── README.md
└── pyproject.toml

To use this server, you’ll need to:

Install the required dependencies:

[If not already installed] https://docs.astral.sh/uv/

uv venv

source .venv/bin/activate

uv sync

Refer to the .env.example file to configure your Redis connection by adding the appropriate variables.

Run the server:

python src/server.py

Capabilities of this server

Resources:

  • redis://status - Current connection status
  • redis://info - Redis server information
  • redis://keys/{pattern} - List keys matching a pattern

Tools:

  • Basic operations:
    • get_value - Get a value
    • set_value - Set a value with optional expiry
    • delete_key - Delete a key
    • increment - Increment a numeric value
  • List operations:
    • list_push - Push values to a list
    • list_range - Get range of list values
  • Hash operations:
    • hash_set - Set hash fields
    • hash_get - Get hash fields
  • Set operations:
    • set_add - Add to a set
    • set_members - Get set members
  • Pub/Sub:
    • publish_message - Publish a message

Each tool includes error handling and returns meaningful responses. The server will automatically reconnect to Redis if the connection is lost.

You can test it with the MCP Inspector:
mcp dev src/server.py

Or install it in Claude Desktop:
mcp install src/server.py

Example

User: What's the current Redis connection status?
LLM: Let me check the Redis connection status for you.

[Reading resource redis://status]

The Redis server is currently connected and running on localhost:6379, database 0.

User: Can you store my name "Alice" in Redis?
LLM: I'll help you store your name in Redis using the set_value tool.

[Calling set_value with key="name" value="Alice"]
Successfully set key 'name'

I've stored your name "Alice" in Redis under the key "name". Would you like me to verify the value was stored correctly by retrieving it?

User: Yes please verify it
LLM: I'll retrieve the value using the get_value tool.

[Calling get_value with key="name"]
Alice

Yes, I can confirm that your name "Alice" was successfully stored in Redis and can be retrieved correctly. The value matches exactly what we stored.

This implementation provides a solid foundation for Redis integration through MCP. You can extend it further by adding more Redis commands as needed for your specific use case.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers