mcpField
S
SQL MCP Server (TypeScript)

SQL MCP Server (TypeScript)

本地服务
github.com/t3ta数据库181 周前更新

关于 SQL MCP Server (TypeScript)

SQL MCP Server (TypeScript) 是用于查询 PostgreSQL 的 TypeScript MCP 服务,也支持通过 SSH 堡垒隧道访问 AWS RDS。它面向需要通过 stdio 进行只读数据库访问的语言模型和 MCP 客户端。

主要功能

  1. 01只读 PostgreSQL 查询
  2. 02支持 SSH 堡垒隧道
  3. 03STDIO MCP 传输
  4. 04通过环境变量配置
  5. 05使用 Jest 和模拟对象测试

适用场景

  1. 01经由 SSH 堡垒查询私有 PostgreSQL 实例
  2. 02向 MCP 客户端提供只读 PostgreSQL 访问

MCP 相关

它通过 stdin 和 stdout 向兼容 MCP 的客户端提供 PostgreSQL 查询能力。访问私有 RDS 实例时可使用 SSH 堡垒隧道。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"sql": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres"
]
}
}
}
启动命令npx -y @modelcontextprotocol/server-postgres

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@modelcontextprotocol/server-postgres

工具

1

收录的工具列表 · 更新于 3 周前

参数类型必填说明
sqlstring否

详细介绍

SQL MCP 服务(TypeScript)

TypeScript Build License: MIT Platform

本项目提供了一个模型上下文协议(MCP)服务的 TypeScript 实现,让大模型和其他兼容 MCP 的客户端能够查询 PostgreSQL 数据库;必要时可通过 SSH 堡垒隧道连接。

本项目旨在提供灵活、安全的数据库访问,支持采用只读事务的 AWS RDS,并使用基于 stdin/stdout 的通信方式,适用于本地、容器化或由 AI 驱动的使用场景。

功能

  • 🔒 支持 SSH 堡垒连接,通过 SSH 隧道安全访问私有 RDS 实例
  • 🐘 使用 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

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。