关于 Mcp Server Redis
Mcp Server Redis 是一个 MCP 服务,用于通过 MCP 客户端访问 Redis 服务器及 AWS Memory DB 等兼容实例。它适用于缓存及其他基于内存和键值存储的场景。
主要功能
- 01读取连接状态与服务器信息资源
- 02按模式列出键(redis://keys/{pattern})
- 03字符串、列表、哈希、集合的读写工具
- 04发布消息的 Pub/Sub 工具
- 05连接断开后自动重连
适用场景
- 01通过 MCP 客户端读写缓存数据
- 02在 Agent 中管理列表、哈希或集合类数据
- 03通过 Pub/Sub 向 Redis 频道发布消息
MCP 相关
该项目是一个 MCP 服务,向 MCP 客户端提供 resources(连接状态、服务器信息、键列表)和 tools(get_value、set_value、list_push、hash_set、publish_message 等)。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
用法
结构如下:
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
要使用此服务,你需要:
安装所需的依赖项:
[如果尚未安装] https://docs.astral.sh/uv/
uv venv
source .venv/bin/activate
uv sync
参考 .env.example 文件,通过添加相应的变量来配置你的 Redis 连接。
运行服务:
python src/server.py
此服务的功能
资源:
- redis://status - 当前连接状态
- redis://info - Redis 服务器信息
- redis://keys/{pattern} - 列出匹配某个模式的键
工具:
- 基本操作:
- get_value - 获取一个值
- set_value - 设置一个值,可选设置过期时间
- delete_key - 删除一个键
- increment - 递增一个数值
- 列表操作:
- list_push - 将值推入列表
- list_range - 获取列表值的范围
- 哈希操作:
- hash_set - 设置哈希字段
- hash_get - 获取哈希字段
- 集合操作:
- set_add - 添加到集合
- set_members - 获取集合成员
- 发布/订阅:
- publish_message - 发布一条消息
每个工具都包含错误处理,并返回有意义的响应。如果连接丢失,服务会自动重新连接到 Redis。
你可以使用 MCP Inspector 进行测试:
mcp dev src/server.py
或在 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.
此实现为通过 MCP 集成 Redis 提供了一个坚实的基础。你可以根据特定的用例,通过添加更多 Redis 命令来进一步扩展它。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。
