Redis键值存储工具

一个基于Redis的MCP服务器,提供获取/设置键值对数据的工具功能,适用于需要快速数据存储和检索的场景。

  • by yhwang
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 yhwang/mcp-tool-server-redis

使用说明

mcp工具服务器redis

提供工具功能以获取/设置Redis支持的键值对数据的MCP服务器

运行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] 然后按enter键。

使用 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参数的工具。例如,您可以使用以下命令向Redis添加键值对 set 工具:

> 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

您可以使用光标在列表中导航并选择所需的图元。然后,系统将提示您输入所选图元的参数。