使用说明
PostgreSQL聊天机器人与GitHub Copilot
通过GitHub Copilot提供的web界面使用自然语言查询PostgreSQL数据库。
显示VS Code Copilot Bridge与GPT-4模型连接的Web界面
🚀 快速开始
macOS/Linux:
./start-all.sh
窗户:
start-all.bat
这将:
- 启动MCP服务器(端口3000)
- 启动VS代码+副驾驶桥(端口9001)-在后台最小化
- 启动Web服务器(端口9000)
- 在浏览器中打开聊天机器人http://localhost:9000
要停止所有服务,请执行以下操作:
macOS/Linux:
./stop-all.sh
窗户:
stop-all.bat
特性
| 特性 | 描述 |
|---|---|
| 自然语言查询 | 用简单的英语提问 |
| GitHub Copilot GPT-4 | 由GPT-4通过VS代码副驾驶桥供电 |
| 实时状态 | 显示连接状态和型号信息 |
| 表格可视化 | 结果显示在格式化的表格中 |
| SQL透明度 | 查看生成的SQL查询 |
| 快捷操作 | 用于常见查询的预构建按钮 |
建筑
┌─────────────┐ ┌─────────────────┐ ┌─────────────────┐ ┌────────────┐
│ Browser │───▶│ Web Server │───▶│ VS Code │───▶│ MCP │───▶ PostgreSQL
│ (port 9000)│ │ (Node.js) │ │ Copilot Bridge │ │ Server │
└─────────────┘ └─────────────────┘ │ (GPT-4) │ │ (port 3000)│
└─────────────────┘ └────────────┘
组件:
| 组件 | 端口 | 描述 |
|---|---|---|
| Web服务器 | 9000 | 提供聊天机器人用户界面 |
| Copilot Bridge | 9001 | VS代码扩展连接到GitHub Copilot |
| MCP服务器 | 3000 | PostgreSQL数据库连接器 |
需求
- 已安装VS代码
- GitHub Copilot订阅(活动)
- PostgreSQL数据库
- Python 3.9+
- Node.js
安装
macOS/Linux
-
安装Python依赖项:
cd mcp-server python3 -m venv venv source venv/bin/activate pip install -r requirements.txt -
配置数据库:
cp .env.example .env nano mcp-server/.env # Edit with your database credentials -
安装VS代码扩展:
code --install-extension copilot-web-bridge/copilot-web-bridge-1.0.0.vsix -
开始:
./start-all.sh
视窗
-
安装Python依赖项:
cd mcp-server python -m venv venv venv\Scripts\activate.bat pip install -r requirements.txt -
配置数据库:
copy .env.example .env notepad mcp-server\.env &REM Edit with your database credentials -
安装VS代码扩展:
code --install-extension copilot-web-bridge\copilot-web-bridge-1.0.0.vsix -
开始:
start-all.bat
查询示例
"Show me all tables"
"List employees with salary above 70000"
"What is the average salary by department?"
"Show me the top 5 highest rated products"
"Describe the employees table"
运作原理
- 用户在浏览器中键入问题
- 请求已发送至VS代码复制桥
- GitHub Copilot(GPT-4)生成SQL
- MCP服务器在PostgreSQL上执行SQL
- 使用AI生成的摘要显示结果
数据库工具
MCP服务器提供以下工具:
| 工具 | 说明 |
|---|---|
query_database |
执行SELECT查询 |
execute_sql |
运行INSERT/UPDATE/DELETE |
list_tables |
列出所有表格 |
describe_table |
获取表结构 |
get_table_indexes |
查看索引 |
analyze_query_plan |
解释疑问 |
create_table |
创建新表 |
create_stored_procedure |
创建程序 |
重要说明
| 注 | 详细信息 |
|---|---|
| VS代码必填 | 必须保持运行(最小化即可) |
| GitHub Copilot | 需要主动订阅 |
| 仅限本地 | Web界面在本地主机上工作 |
为什么需要VS Code: GitHub Copilot API只能通过VS Code的 vscode.lm API没有独立的Copilot API可用。
故障排除
聊天机器人未连接?
# Check all services are running
curl http://localhost:9000/health
curl http://localhost:9001/health
curl http://localhost:3000/health
VS代码复制桥断开连接?
- 确保VS代码正在运行(可以最小化)
- 检查GitHub Copilot是否已登录
- 按
Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(macOS)并运行“Copilot Web Bridge:启动服务器”
数据库错误?
- 验证
mcp-server/.env具有正确的凭据 - 检查PostgreSQL是否正在运行
Windows特定问题?
- 确保
python和node在您的系统PATH中 - 确保
curl可用(包含在Windows 10+中) - 跑
start-all.bat从命令提示符(不是PowerShell)获得最佳兼容性 - 查看日志
%TEMP%\mcp-server.log和%TEMP%\web-server.log
文件结构
mcp-postgres/
├── index.html # Web chatbot UI
├── web-server.js # Node.js web server (port 9000)
├── start-all.sh # Start all services (macOS/Linux)
├── stop-all.sh # Stop all services (macOS/Linux)
├── start-all.bat # Start all services (Windows)
├── stop-all.bat # Stop all services (Windows)
├── README.md # Documentation
├── SETUP.md # Setup guide
├── LICENSE # License file
├── docs/ # Screenshots
│ ├── screenshot-ui.png # Hero image
│ └── feature.png # Features image
├── copilot-web-bridge/ # VS Code extension (port 9001)
│ └── src/extension.ts # Extension code
└── mcp-server/ # PostgreSQL MCP Server (port 3000)
├── server.py # HTTP server
└── .env # Database config
用自然语言查询您的数据库!