DiceDB MCP
A. 模型上下文协议(MCP) DiceDB的服务器实现,以实现AI应用程序(主机/客户端)和DiceDB数据库服务器之间的交互。
此实现使用 DiceDB Go SDK 与DiceDB通信。
看看 演示视频 看看它在行动!
特性
- PING DiceDB检查连接。
- ECHO通过DiceDB发送消息。
- 按键从DiceDB中获取值。
- 在DiceDB中设置一个键值对。
- 从DiceDB中删除一个或多个密钥。
- 将键的整数值加1。
- DECR键的整数值乘以1。
安装
下载二进制文件
你可以 下载 并从“发布”页面为您的操作系统和处理器架构使用适当的二进制文件。
通过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 对于光标:
{
"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",
instructions=f"""You can interact with a DiceDB database
running at {server_url}, use
this for url.""",
mcp_servers=[mcp_server],)
result = await Runner.run(starting_agent=agent, input=prompt)
print(result.final_output)
async def main():
openai.api_key = os.getenv("OPENAI_API_KEY")
prompt = "Can you change the value of the 'name' key to 'Rachel Green'?"
server_url = "localhost:7379"
async with MCPServerStdio(
cache_tools_list=True,
params={"command": "path/to/dicedb-mcp", "args": [""]},
) as server:
with trace(workflow_name="DiceDB MCP"):
await run(server, prompt, server_url)
if __name__ == "__main__":
asyncio.run(main())可用工具
拼
Ping DiceDB服务器以检查连接。
回声
通过DiceDB服务器回显消息。
得到
按键从DiceDB检索值。
集
在DiceDB中设置键值对。
删除
从DiceDB中删除一个或多个密钥。
增加
将键的整数值递增1。
decr
将键的整数值减1。
发展
分叉并克隆存储库:
git clone https://github.com/username/dicedb-mcp.git切换到目录:
cd dicedb-mcp安装依赖项:
make deps构建项目:
make build更新MCP服务器配置以指向本地版本:
{
"mcpServers": {
"dicedb-mcp": {
"command": "/path/to/dicedb-mcp/dist/dicedb-mcp"
}
}
}