mcp-server-redis

mcp-server-redis avatar

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

What is mcp-server-redis

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.

Leave a Comment

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.

Related MCP Servers

PostgreSQL MCP Server avatar

PostgreSQL MCP Server

A Model Context Protocol server that provides read-only access to PostgreSQL databases. This server enables LLMs to inspect database schemas and execute read-only queries.

databasepostgresqlcommunity
AWS Knowledge Base Retrieval avatar

AWS Knowledge Base Retrieval

An MCP server implementation for retrieving information from the AWS Knowledge Base using the Bedrock Agent Runtime.

awscloudcommunity
prisma prisma avatar

prisma prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

cockroachdbgomcp
yaoxiaolinglong mcp mongodb mysql server avatar

yaoxiaolinglong mcp mongodb mysql server

η”¨δΊŽmysqlε’Œmongodbηš„mcp

mcpgodatabase
OpenLinkSoftware mcp pyodbc server avatar

OpenLinkSoftware mcp pyodbc server

A simple MCP ODBC server using FastAPI, ODBC and PyODBC.

mcpapidatabase
executeautomation mcp database server avatar

executeautomation mcp database server

MCP Database Server is a new MCP Server which helps connect with Sqlite, SqlServer and Posgresql Databases

posgresqlsqlitemcp
dreamfactorysoftware df mcp avatar

dreamfactorysoftware df mcp

DreamFactory MCP Server enables AI assistants like Claude to directly query your databases through DreamFactory's auto-generated REST APIs.

apimcpai
attarmau FastMCP RecSys avatar

attarmau FastMCP RecSys

A mockup full stack app built with React, FastAPI, MongoDB, and Docker, powered by AWS Rekognition & CLIP for multi-tagging and clothing recommendations

goapimcp
TheRaLabs legion mcp avatar

TheRaLabs legion mcp

A server that helps people access and query data in databases using the Legion Query Runner with Model Context Protocol (MCP) in Python.

mcpmcp-serverlegion-ai
spences10 mcp turso cloud avatar

spences10 mcp turso cloud

πŸ—‚οΈ A Model Context Protocol (MCP) server that provides integration with Turso databases for LLMs. This server implements a two-level authentication system to handle both organization-level and database-level operations, making it easy to manage and query Turso databases directly from LLMs.

model-context-protocoltursomcp

Submit Your MCP Server

Share your MCP server with the community

Submit Now