这是一个用于实现 AI 应用程序(宿主/客户端)与 DiceDB 数据库服务器之间交互的服务端。它基于 模型上下文协议 (MCP),并使用 DiceDB Go SDK 与 DiceDB 进行通信。查看 演示视频,了解其运行情况!
本服务端可让 AI 应用程序与 DiceDB 数据库服务器进行交互,使用 MCP 协议通信,为数据交互提供便利。
PING DiceDB
:检查与 DiceDB 的连接性。通过 DiceDB 回显消息
:实现消息的回显功能。根据键从 DiceDB 获取值
:方便获取数据库中的数据。在 DiceDB 中设置键值对
:灵活存储数据。删除一个或多个键的值从 DiceDB
:清理不需要的数据。增加某个键的整数值一
:对数值进行递增操作。减少某个键的整数值一
:对数值进行递减操作。你可以从 "Releases" 页下载适用于你的操作系统和处理器架构的适当二进制文件:下载。
先决条件:
go install github.com/pottekkat/dicedb-mcp@latest
获取 dicedb-mcp
可执行文件的路径:
which dicedb-mcp
请参阅下方的 开发 部分。
将以下内容添加到你的 claude_desktop_config.json
(用于 Claude Desktop)或 mcp.json
(用于 Cursor)中:
{
"mcpServers": {
"dicedb-mcp": {
"command": "path/to/dicedb-mcp"
}
}
}
以下示例展示了如何使用 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.