by prajwalnayak7
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.
mcp-server-redis is a Python-based MCP (Multi-Cloud Platform) server designed to facilitate interaction with Redis Server, AWS Memory DB, and similar in-memory, key-value based storage solutions. It provides a structured way to manage and access Redis functionalities for caching and other data storage needs.
To use mcp-server-redis, follow these steps:
uv venv
, source .venv/bin/activate
, and uv sync
to set up the virtual environment and install required packages..env.example
file to configure your Redis connection by adding the appropriate variables.python src/server.py
to start the server.For testing and development, you can use mcp dev src/server.py
with MCP Inspector or mcp install src/server.py
to install it in Claude Desktop.
mcp-server-redis offers a range of features for managing Redis data:
Resources:
redis://status
: Checks the current connection status to Redis.redis://info
: Retrieves information about the Redis server.redis://keys/{pattern}
: Lists keys matching a specified pattern.Tools (Basic Operations):
get_value
: Retrieves a value associated with a key.set_value
: Sets a value for a key with optional expiry.delete_key
: Deletes a specified key.increment
: Increments a numeric value.Tools (List Operations):
list_push
: Pushes values onto a list.list_range
: Retrieves a range of values from a list.Tools (Hash Operations):
hash_set
: Sets fields within a hash.hash_get
: Retrieves fields from a hash.Tools (Set Operations):
set_add
: Adds members to a set.set_members
: Retrieves all members of a set.Tools (Pub/Sub Operations):
publish_message
: Publishes a message to a channel.Each tool includes robust error handling and provides meaningful responses. The server also features automatic reconnection to Redis if the connection is lost.
mcp-server-redis is ideal for:
Q: How do I check the current Redis connection status?
A: You can use the redis://status
resource. For example, an LLM might respond with: "The Redis server is currently connected and running on localhost:6379, database 0."
Q: Can I store my name in Redis using this server?
A: Yes, you can use the set_value
tool. For instance, if you ask to store "Alice" as your name, the server will call set_value
with key="name"
and value="Alice"
, confirming successful storage.
Q: How can I verify if a value was stored correctly?
A: After storing a value, you can use the get_value
tool with the corresponding key. The server will retrieve and confirm the stored value, e.g., retrieving "Alice" for the key "name".
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
Resources:
Tools:
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
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.
Reviews feature coming soon
Stay tuned for community discussions and feedback