S

SQL-MCP服务器

一个用 TypeScript 实现的 Model Context Protocol 服务器,它使语言模型能够安全地查询 PostgreSQL 数据库,包括位于 SSH 堡垒机隧道后面的数据库。

databases

2.0k 查看 · 2026-07-07 更新

简介

一个用 TypeScript 实现的 Model Context Protocol 服务器,它使语言模型能够安全地查询 PostgreSQL 数据库,包括位于 SSH 堡垒机隧道后面的数据库。

简介

一个用 TypeScript 实现的 Model Context Protocol 服务器,它使语言模型能够安全地查询 PostgreSQL 数据库,包括位于 SSH 堡垒机隧道后面的数据库。

SQL MCP 服务器 (TypeScript)

TypeScript Build License: MIT Platform

该项目提供了一个使用 TypeScript 实现的 Model Context Protocol (MCP) 服务器,它使语言模型和其他兼容 MCP 的客户端能够查询 PostgreSQL 数据库——必要时通过 SSH 堡垒隧道进行。

该服务器为灵活性和安全的数据库访问而构建,支持具有只读事务的 AWS RDS,并使用基于 stdin/stdout 的通信方式,适用于本地、容器化或 AI 驱动的用例。

特性

  • 🔒 通过 SSH 隧道安全访问私有 RDS 实例的 SSH 堡垒支持
  • 🐘 使用 pg 库的 PostgreSQL 只读查询引擎
  • 📡 基于 STDIO 的 MCP 协议传输
  • 🧠 与 memory-bank-mcp-server 兼容
  • ⚙️ 通过 .env 或环境变量轻松配置
  • 🧪 完全可使用 Jest 和模拟进行测试

安装

克隆仓库并安装依赖项:

git clone https://github.com/your-org/sql-mcp-server.git cd sql-mcp-server npm install npm run build Configuration (Optional .env file) Create a .env file in the project root: DB_USER=postgres DB_PASS=yourpassword DB_HOST=localhost DB_PORT=5432 DB_NAME=mydatabase USE_SSH_TUNNEL=true SSH_BASTION_HOST=bastion.example.com SSH_BASTION_USER=ec2-user SSH_PRIVATE_KEY_PATH=~/.ssh/id_rsa Usage Run the server using npx: npx -y @modelcontextprotocol/server-postgres postgresql://<user>:<pass>@localhost:5433/<dbname> For direct connection without SSH tunneling, set the appropriate environment variables: DB_HOST=rds-host.amazonaws.com DB_PORT=5432 npx -y @modelcontextprotocol/server-postgres postgresql://<user>:<pass>@rds-host.amazonaws.com/<dbname> Sample Input { "type": "call_tool", "params": { "name": "query", "arguments": { "sql": "SELECT * FROM users LIMIT 10" } } } Sample Output { "content": [ { "type": "text", "text": "[{\"id\":1,\"name\":\"Alice\"}]" } ], "isError": false } ⸻ Related Docs • Architecture • Domain Models • Glossary • Coding Standards • Tech Stack • User Guide ⸻ License MIT ⸻ Contribution Guide We welcome community contributions! Please see CONTRIBUTING.md for details. ⸻ Compatibility This implementation follows the Model Context Protocol (MCP) and has been tested for compatibility with: • memory-bank-mcp-server • Claude Desktop (via STDIO) • Cursor IDE • Supabase + MCP integration

来源