GreptimeDB-MCP-Server是一个为GreptimeDB实现模型上下文协议(MCP)的服务器。它为AI助手提供了安全且结构化的接口,助力其探索和分析数据库。通过该服务器,AI助手可以列出表格、读取数据并执行SQL查询,同时通过受控接口确保数据库访问的安全性和责任性。
GreptimeDB-MCP-Server为AI助手与GreptimeDB之间搭建了安全桥梁。以下将介绍如何安装、配置和使用该服务器。
你可以使用pip命令来安装GreptimeDB-MCP-Server:
pip install greptimedb-mcp-server
你可以通过设置环境变量或使用命令行参数来配置GreptimeDB-MCP-Server。
设置以下环境变量:
GREPTIMEDB_HOST=localhost # 数据库主机
GREPTIMEDB_PORT=4002 # 可选:数据库端口(未指定时默认为4002)
GREPTIMEDB_USER=root
GREPTIMEDB_PASSWORD=
GREPTIMEDB_DATABASE=public
你也可以通过命令行参数进行配置:
--host:数据库主机--port:数据库端口--user:数据库用户名--password:数据库密码--database:数据库名称你可以在Claude Desktop的配置文件中设置MCP服务器。
配置文件位置:~/Library/Application Support/Claude/claude_desktop_config.json
配置文件位置:%APPDATA%/Claude/claude_desktop_config.json
以下是配置文件示例:
{
"mcpServers": {
"greptimedb": {
"command": "uv",
"args": [
"--directory",
"/path/to/greptimedb-mcp-server",
"run",
"-m",
"greptimedb_mcp_server.server"
],
"env": {
"GREPTIMEDB_HOST": "localhost",
"GREPTIMEDB_PORT": "4002",
"GREPTIMEDB_USER": "root",
"GREPTIMEDB_PASSWORD": "",
"GREPTIMEDB_DATABASE": "public"
}
}
}
}
本项目采用MIT License,详情请参见LICENSE.md文件。
uv包管理器# 克隆仓库
git clone https://github.com/GreptimeTeam/greptimedb-mcp-server.git
cd greptimedb-mcp-server
# 创建虚拟环境
python -m venv venv
source venv/bin/activate # 或 `venv\Scripts\activate` 在Windows上
# 安装开发依赖项
pip install -r requirements-dev.txt
# 运行测试
pytest
你可以使用MCP Inspector进行调试:
npx @modelcontextprotocol/inspector uv \
--directory \
/path/to/greptimedb-mcp-server \
run \
-m \
greptimedb_mcp_server.server
本库的实现借鉴了以下两个仓库的代码,在此表示感谢: