Dicedb Mcp

Dicedb Mcp

🚀 DiceDB MCP 服务端实现

这是一个用于实现 AI 应用程序(宿主/客户端)与 DiceDB 数据库服务器之间交互的服务端。它基于 模型上下文协议 (MCP),并使用 DiceDB Go SDK 与 DiceDB 进行通信。查看 演示视频,了解其运行情况!

🚀 快速开始

本服务端可让 AI 应用程序与 DiceDB 数据库服务器进行交互,使用 MCP 协议通信,为数据交互提供便利。

✨ 主要特性

  • 🔌 PING DiceDB:检查与 DiceDB 的连接性。
  • 💬 通过 DiceDB 回显消息:实现消息的回显功能。
  • 📖 根据键从 DiceDB 获取值:方便获取数据库中的数据。
  • 📝 在 DiceDB 中设置键值对:灵活存储数据。
  • 🗑️ 删除一个或多个键的值从 DiceDB:清理不需要的数据。
  • 增加某个键的整数值一:对数值进行递增操作。
  • 减少某个键的整数值一:对数值进行递减操作。

📦 安装指南

下载二进制文件

你可以从 "Releases" 页下载适用于你的操作系统和处理器架构的适当二进制文件:下载

使用 Go 安装

先决条件:

  • Go 1.24 或更高版本
go install github.com/pottekkat/dicedb-mcp@latest

获取 dicedb-mcp 可执行文件的路径:

which dicedb-mcp

从源代码构建

请参阅下方的 开发 部分。

💻 使用示例

基础用法

带 MCP 宿主/客户端

将以下内容添加到你的 claude_desktop_config.json(用于 Claude Desktop)或 mcp.json(用于 Cursor)中:

{
"mcpServers": {
"dicedb-mcp": {
"command": "path/to/dicedb-mcp"
}
}
}

带 OpenAI 代理 SDK

以下示例展示了如何使用 dicedb-mcp 服务端与 OpenAI 代理 SDK

from agents import Agent, Runner, trace
from agents.mcp import MCPServer, MCPServerStdio
from dotenv import load_dotenv
import os
import openai
import asyncio

load_dotenv()


async def run(mcp_server: MCPServer, prompt: str, server_url: str):
agent = Agent(name="dicedb-mcp",
system_prompt="You are an AI assistant that interacts with the DiceDB database using the Model Context Protocol (MCP).")
runner = Runner(agent, print_steps=True)
result = await runner.run(
"Use the MCP protocol to interact with the DiceDB database as specified by the user's prompt.",
mcp_server=mcp_server,
server_url=server_url,
prompt=prompt
)
return result


async def main():
# 初始化 MCPServerStdio 实例
mcp_server = await MCPServerStdio.create()

# 添加自定义路由
mcp_server.add_route("/custom", lambda: "Custom route response")

# 启动服务器
server_url = await mcp_server.start()

# 运行示例
result = await run(mcp_server, "告诉我数据库中的内容。", server_url)
print(f"结果:{result}")


if __name__ == "__main__":
asyncio.run(main())

可用工具

  • ping - 检查连接性。
  • echo - 通过 DiceDB 回显消息。
  • get - 根据键从 DiceDB 获取值。
  • set - 在 DiceDB 中设置键值对。
  • delete - 删除一个或多个键的值从 DiceDB。
  • increment - 增加某个键的整数值一。
  • decrement - 减少某个键的整数值一。

📚 详细文档

开发

克隆仓库

git clone https://github.com/pottekkat/dicedb-mcp.git
cd dicedb-mcp

构建项目

make deps  # 安装依赖项
make build # 编译项目

运行测试

make test

配置本地构建

编辑 config.go 文件以配置你的本地环境。

📄 许可证

此项目使用 MIT 许可证,具体内容如下:

MIT License

Copyright (c) 2023-present pottekkat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
  • 0 关注
  • 0 收藏,8 浏览
  • system 提出于 2025-09-23 15:06

相似服务问题