openGauss MCP Server 完全配置指南:让 AI 无缝连接你的数据库
openGauss MCP Server 完全配置指南:让 AI 无缝连接你的数据库
一、什么是 MCP + openGauss?
随着大语言模型(LLM)和 AI Agent 的快速发展,如何让 AI 安全、标准化地访问数据库成为了一个关键需求。MCP(Model Context Protocol) 正是为解决这一问题而生的开放协议——它定义了 LLM 与外部数据源、工具之间的标准化通信方式。
openGauss MCP Server 是一个基于 FastMCP 2.0(Python)构建的 MCP 服务,能够将 openGauss 数据库暴露为 MCP 工具,供 LLM / Agent 调用。该特性自 openGauss 7.0.0-RC3 版本开始引入。
项目地址:opengauss/mcp-opengauss(v0.1.0)
架构概览
用户 → Claude Desktop → MCP 协议 → openGauss MCP Server → openGauss 数据库
内置能力
| 类型 | 名称 | 说明 |
|---|---|---|
| 资源 | get_schemas | 获取数据库所有 schema |
| 资源 | get_tables | 获取指定 schema 的表列表 |
| 工具 | execute_query | 执行 SQL 查询(支持读写) |
| 工具 | get_table_definition | 获取表结构定义 |
| 工具 | list_tables_in_current_schema | 列出当前 schema 的表 |
| 工具 | get_current_user_and_schema | 获取当前用户和 schema |
二、环境准备
2.1 安装 Python3 与 uv
# Ubuntu / Debian
sudo apt update
sudo apt install python3 python3-pip -y
# 安装 uv(Python 包管理器)
curl -LsSf https://astral.sh/uv/install.sh | sh
验证安装:
python3 --version
uv --version
2.2 部署 openGauss 数据库(推荐容器方式)
# 拉取 openGauss 镜像
docker pull enmotech/opengauss:latest
# 启动容器
docker run --name opengauss \
-p 5432:5432 \
-e GS_PASSWORD=YourPassword@123 \
-d enmotech/opengauss:latest
详细安装可参考 openGauss 官方安装指南
2.3 下载 Claude Desktop
前往 Claude Desktop 官网下载并安装桌面客户端,后续用它来配置 MCP 服务器。
三、获取源码
git clone https://gitcode.com/opengauss/mcp-opengauss.git
cd mcp-opengauss
项目结构:
mcp-opengauss/
├── src/
│ └── openGauss_mcp_server/
│ ├── server.py # 主服务器入口
│ ├── database.py # 数据库连接层
│ └── tools.py # MCP 工具定义
├── docs/
│ └── openGauss_mcp_server.md # 官方文档
├── env_template # 环境变量模板
└── README.md
四、三种传输模式配置详解
模式 1:Stdio 模式(本地桌面客户端)
最常用模式,适用于 Claude Desktop 本地调用。编辑 claude_desktop_config.json:
{
"mcpServers": {
"openGauss": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mcp-opengauss/src/openGauss_mcp_server",
"run",
"server.py"
],
"env": {
"OPENGAUSS_HOST": "localhost",
"OPENGAUSS_PORT": "5432",
"OPENGAUSS_USER": "gaussdb",
"OPENGAUSS_PASSWORD": "YourPassword@123",
"OPENGAUSS_DBNAME": "postgres",
"ENABLE_MEMORY": "0"
}
}
}
}
重启 Claude Desktop,看到锤子图标即表示连接成功。
模式 2:SSE 模式(远程 HTTP 连接)
cp env_template .env
# 编辑 .env 配置数据库信息
source .env
python3 -m src.openGauss_mcp_server.server \
--transport sse --sse_port 8080 --sse_host 0.0.0.0
客户端配置:
{
"mcpServers": {
"openGauss": {
"type": "sse",
"url": "http://<your-server-ip>:8080/sse"
}
}
}
模式 3:Streamable HTTP 模式
python3 -m src.openGauss_mcp_server.server \
--transport streamable-http \
--streamable_http_port 8080 --streamable_http_host 0.0.0.0
客户端配置:
{
"mcpServers": {
"openGauss": {
"type": "streamableHttp",
"url": "http://<your-server-ip>:8080/mcp"
}
}
}
五、环境变量完整参考
数据库连接
| 变量名 | 说明 | 默认值 | 必需 |
|---|---|---|---|
| OPENGAUSS_HOST | 数据库主机地址 | localhost | 是 |
| OPENGAUSS_PORT | 数据库端口号 | 5432 | 是 |
| OPENGAUSS_USER | 数据库用户名 | 无 | 是 |
| OPENGAUSS_PASSWORD | 数据库密码 | 无 | 否 |
| OPENGAUSS_DBNAME | 数据库名称 | 无 | 是 |
安全建议:推荐交互输入密码,避免明文存储。
记忆系统配置
| 变量名 | 说明 | 默认值 |
|---|---|---|
| ENABLE_MEMORY | 记忆系统开关 1=启用 0=禁用 | 1 |
| EMBEDDING_MODEL_PROVIDER | 嵌入模型提供商 | huggingface |
| REMOTE_MODEL_NAME | HuggingFace 模型名 | BAAI/bge-small-en-v1.5 |
HTTPS/SSL 配置
| 变量名 | 说明 | 默认值 |
|---|---|---|
| ENABLE_HTTPS | 启用 HTTPS | true |
| SSL_KEYFILE | SSL 私钥路径 | certs/server.key |
| SSL_CERTFILE | SSL 证书路径 | certs/server.crt |
六、效果验证
配置完成后可直接向 Claude 提问:
- “查询当前数据库中有哪些 schema?”
- “帮我列出 public schema 下的所有表”
- “帮我查一下 users 表的前 5 条数据”
七、总结
| 模式 | 适用场景 | 优势 |
|---|---|---|
| Stdio | 本地开发、个人使用 | 配置简单、延迟低 |
| SSE | 团队共享、远程访问 | 支持多客户端、可 HTTPS |
| Streamable HTTP | 新协议适配 | 流式传输、兼容性更好 |
参考资料:
- openGauss 官方 MCP 文档:https://docs.opengauss.org/zh/docs/latest/datavec/mcp.html
- mcp-opengauss 源码仓库:https://gitcode.com/opengauss/mcp-opengauss
- 开源中国:MCP + openGauss 连接人工智能与数据库:https://my.oschina.net/u/5059795/blog/18120546
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐

所有评论(0)