关于 mcp-tool-server-redis
mcp-tool-server-redis 是一个以 Redis 为后端的 MCP 服务,为 MCP 客户端提供键值数据操作工具,可设置、读取、删除键并按模式列出键。
主要功能
- 01设置键值对并可选过期时间
- 02按键获取值
- 03删除一个或多个键
- 04按模式列出键
适用场景
- 01在 Redis 中存储应用数据
- 02按键读取数据
- 03删除指定的 Redis 键
- 04查找符合模式的键
MCP 相关
通过 streamable HTTP 向 MCP 客户端提供四种 Redis 键值操作工具。README 介绍了使用 Docker Compose 启动服务。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
mcp-tool-server-redis
一个 MCP 服务,提供用于获取和设置由 Redis 支持的键值对数据的工具。
运行 MCP 服务
使用 docker compose 启动服务
docker compose up -d
这将启动一个以 Redis 为后端的 MCP 服务。服务将在 http://localhost:3000 上可用。
与 MCP 服务交互
选项 1:来自 typescript-sdk 的流式 HTTP 客户端
你可以使用 MCP typescript-sdk 仓库中的简单流式 HTTP 客户端与 MCP 服务交互: https://github.com/modelcontextprotocol/typescript-sdk.git
使用方法如下:
git clone https://github.com/modelcontextprotocol/typescript-sdk.git
cd typescript-sdk
npm install
npx tsx src/examples/client/simpleStreamableHttp.ts
默认情况下,客户端会连接到 http://localhost:3000,你应该会看到以下输出:
MCP Interactive Client
=====================
Connecting to http://localhost:3000/mcp...
Transport created with session ID: 44dff10f-89bc-4965-b280-e1df3eb56a51
Connected to MCP server
Available commands:
connect [url] - Connect to MCP server (default: http://localhost:3000/mcp)
disconnect - Disconnect from server
terminate-session - Terminate the current session
reconnect - Reconnect to the server
list-tools - List available tools
call-tool <name> [args] - Call a tool with optional JSON arguments
greet [name] - Call the greet tool
multi-greet [name] - Call the multi-greet tool with notifications
start-notifications [interval] [count] - Start periodic notifications
list-prompts - List available prompts
get-prompt [name] [args] - Get a prompt with optional JSON arguments
list-resources - List available resources
help - Show this help
quit - Exit the program
>
随后你将进入交互式提示模式。若要连接到其他 MCP 服务,只需输入 connect [url] 并按回车键。
使用 list-tools 命令列出所有可用工具。共有 4 个可用工具:
> list-tools
Available tools:
- set: Set a Redis key-value pair with optional expiration
- get: Get value by key from Redis
- delete: Delete one or more keys from Redis
- list: List Redis keys matching a pattern
使用 call-tool <name> 命令调用工具,并可选择传入 JSON 参数。例如,你可以使用 set 工具向 Redis 添加键值对:
> call-tool set {"key": "this is a new key", "value": "value for the new key"}
Calling tool 'set' with args: { key: 'this is a new key', value: 'value for the new key' }
Tool result:
Successfully set key: this is a new key
选项 2:MCP-Cli
你也可以使用 mcp-cli 命令行工具与 MCP 服务交互。运行以下命令即可使用:
npx @wong2/mcp-cli --url http://localhost:3000/mcp
此命令将通过流式 HTTP 连接到 MCP 服务。它会提示你查看可用工具列表,并允许你使用 JSON 参数调用它们。例如:
$ npx @wong2/mcp-cli --url http://localhost:3000/mcp
✔ Connected, server capabilities: tools
? Pick a primitive ›
❯ tool(set) - Set a Redis key-value pair with optional expiration
tool(get) - Get value by key from Redis
tool(delete) - Delete one or more keys from Redis
tool(list) - List Redis keys matching a pattern
你可以使用光标浏览列表并选择所需的原语。随后,系统会提示你输入所选原语的参数。
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。