Redis操作协议服务器

一个基于FastMCP构建的Redis操作协议服务器,支持核心Redis操作、批量操作、模式键扫描和多种传输协议。

  • by OAuthBringer
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 oauthbringer/redis-mcp

使用说明

Redis MCP服务器

使用FastMCP构建的用于Redis操作的模型上下文协议(MCP)服务器。

特性

  • Redis核心操作:get、set、delete、list
  • 批量操作:mget、mset
  • 基于模式的密钥扫描
  • 连接池用于高效访问Redis
  • 多种传输支持(stdio、SSE、可流式传输http)
  • 基于环境的配置
  • 类型提示和全面的错误处理

安装

来自PyPI

pip install redis-mcp

或使用紫外线:

uv tool install redis-mcp

来源

# Clone the repository
git clone https://github.com/yourusername/redis-mcp.git
cd redis-mcp

# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install the package
pip install -e .

配置

服务器可以通过环境变量进行配置:

  • REDIS_HOST:Redis服务器主机名(默认值:localhost)
  • REDIS_PORT:Redis服务器端口(默认值:6379)
  • REDIS_DB:Redis数据库编号(默认值:0)
  • REDIS_PASSWORDRedis密码(可选)
  • REDIS_USERNAME:Redis用户名(可选)

用法

作为CLI工具

# Using stdio transport (default)
redis-mcp

# Using SSE transport
redis-mcp --transport sse

# With custom Redis connection
redis-mcp --host redis.example.com --port 6380 --db 1

在克劳德桌面

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "redis": {
      "command": "uvx",
      "args": ["redis-mcp"],
      "env": {
        "REDIS_HOST": "localhost",
        "REDIS_PORT": "6379"
      }
    }
  }
}

可用工具

  • 得到:按键检索值
  • 集:存储具有可选到期和条件的键值对
  • 删除:取下一个或多个钥匙
  • 列表:列出与模式匹配的键
  • mget:在一次操作中获取多个值
  • mset:在一次操作中设置多个键值对
  • 扫描:迭代匹配模式的键而不阻塞

示例用法

from fastmcp import Client

async def main():
    async with Client("http://localhost:8000/sse") as client:
        # Set a value
        await client.call_tool("set", {"key": "user:123", "value": "John Doe"})
        
        # Get a value
        result = await client.call_tool("get", {"key": "user:123"})
        print(result)  # "John Doe"
        
        # List keys
        keys = await client.call_tool("list", {"pattern": "user:*"})
        print(keys)  # ["user:123"]

发展

设置

# Install development dependencies
pip install -e ".[dev]"

运行测试

pytest

代码质量

# Format code
black .
isort .

# Type checking
mypy .

# Linting
ruff check .

需求

  • Python 3.10+
  • Redis服务器
  • FastMCP 2.3.3+

许可证

麻省理工学院