Redis操作协议服务器

一个提供Redis数据库操作访问的模型上下文协议(MCP)服务器。

  • by farhankaz
  • TypeScript
  • 本地部署
  • 6 星标
  • 更新于
在 GitHub 查看 farhankaz/redis-mcp

使用说明

Redis MCP服务器

一种模型上下文协议(MCP)服务器,提供对Redis数据库操作的访问。

项目结构

src/
├── interfaces/
│   └── types.ts           # Shared TypeScript interfaces and types
├── tools/
│   ├── base_tool.ts       # Abstract base class for Redis tools
│   ├── tool_registry.ts   # Registry managing all available Redis tools
│   ├── hmset_tool.ts      # HMSET Redis operation
│   ├── hget_tool.ts       # HGET Redis operation
│   ├── hgetall_tool.ts    # HGETALL Redis operation
│   ├── scan_tool.ts       # SCAN Redis operation
│   ├── set_tool.ts        # SET Redis operation
│   ├── get_tool.ts        # GET Redis operation
│   ├── del_tool.ts        # DEL Redis operation
│   ├── zadd_tool.ts       # ZADD Redis operation
│   ├── zrange_tool.ts     # ZRANGE Redis operation
│   ├── zrangebyscore_tool.ts # ZRANGEBYSCORE Redis operation
│   └── zrem_tool.ts       # ZREM Redis operation
└── redis_server.ts        # Main server implementation

可用工具

工具 类型 描述 输入架构
hmset 哈希命令 将多个哈希字段设置为多个值 key:string(哈希键)
fields:object(要设置的字段值对)
hget 哈希命令 获取哈希字段的值 key:string(哈希键)
field:string(要获取的字段)
hgetall 哈希命令 获取哈希中的所有字段和值 key:string(哈希键)
scan 键命令 扫描与模式匹配的Redis键 pattern:string(要匹配的模式,例如“user:*”)
count:number,可选(返回的键数)
set String Command 使用可选的NX和PX选项设置字符串值 key:string(设置键)
value:string(要设置的值)
nx:boolean,可选(仅在不存在时设置)
px:number,可选(以毫秒为单位过期)
get 字符串命令 获取字符串值 key:string(获取密钥)
del 键命令 删除键 key:string(要删除的键)
zadd 排序集命令 向排序集添加一个或多个成员 key:string(已排序的集合键)
members:对象数组 score:编号和 value:string
zrange 排序集命令 按索引从排序集返回一个成员范围 key:string(已排序的集合键)
start:number(起始索引)
stop:数字(停止索引)
withScores:boolean,可选(在输出中包含分数)
zrangebyscore 排序集命令 从得分在最小值和最大值之间的排序集中返回成员 key:string(已排序的集合键)
min:数字(最低分数)
max:数字(最高分数)
withScores:boolean,可选(在输出中包含分数)
zrem 排序集命令 从排序集中删除一个或多个成员 key:string(已排序的集合键)
members:字符串数组(要删除的成员)
sadd Set Command 向集合中添加一个或多个成员 key:string(设置键)
members:字符串数组(要添加到集合中的成员)
smembers 设置命令 获取集合中的所有成员 key:string(设置键)

用法

在您的MCP客户端(例如,Claude Desktop、Cline)中配置:

{
  "mcpServers": {
    "redis": {
      "command": "npx",
      "args": ["redis-mcp", "--redis-host", "localhost", "--redis-port", "6379"],
      "disabled": false
    }
  }
}

命令行参数

  • --redis-host:Redis服务器主机(默认:localhost)
  • --redis-port:Redis服务器端口(默认值:6379)

通过Smithery安装

通过以下方式自动安装Redis Server for Claude Desktop 史密瑟里:

npx -y @smithery/cli install redis-mcp --client claude

发展

要添加新的Redis工具:

  1. 在中创建新的工具类 src/tools/ 延伸 RedisTool
  2. 在中定义工具的界面 src/interfaces/types.ts
  3. 在中注册该工具 src/tools/tool_registry.ts

工具实现示例:

export class MyTool extends RedisTool {
  name = 'mytool';
  description = 'Description of what the tool does';
  inputSchema = {
    type: 'object',
    properties: {
      // Define input parameters
    },
    required: ['requiredParam']
  };

  validateArgs(args: unknown): args is MyToolArgs {
    // Implement argument validation
  }

  async execute(args: unknown, client: RedisClientType): Promise<ToolResponse> {
    // Implement tool logic
  }
}

许可证

MIT:https://opensource.org/license/mit