mcpField
S
SQL MCP Server (TypeScript)

SQL MCP Server (TypeScript)

Local
github.com/t3taDatabases1Updated 81w ago

About SQL MCP Server (TypeScript)

SQL MCP Server (TypeScript) is a TypeScript MCP server for querying PostgreSQL, including AWS RDS accessed through SSH bastion tunnels. It is intended for language models and MCP clients that need read-only database access over a stdio connection.

Key features

  1. 01Read-only PostgreSQL queries
  2. 02SSH bastion tunnel support
  3. 03STDIO MCP transport
  4. 04Environment-variable configuration
  5. 05Jest tests with mocks

Use cases

  1. 01Query private PostgreSQL instances through an SSH bastion
  2. 02Provide read-only PostgreSQL access to an MCP client

MCP support

It exposes PostgreSQL query access to MCP-compatible clients over stdin and stdout. SSH bastion tunnels can be used to reach private RDS instances.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"sql": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-postgres"
]
}
}
}
Run commandnpx -y @modelcontextprotocol/server-postgres

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@modelcontextprotocol/server-postgres

Tools

1

Saved tool list · updated 3w ago

ParameterTypeRequiredDescription
sqlstringNo

Details

From the project README

SQL MCP Server (TypeScript)

TypeScript Build License: MIT Platform

This project provides a TypeScript implementation of a Model Context Protocol (MCP) server that enables language models and other MCP-compatible clients to query PostgreSQL databases—via SSH bastion tunnels when required.

Built for flexibility and secure database access, it supports AWS RDS with read-only transactions and uses stdin/stdout-based communication, making it suitable for local, containerized, or AI-driven use cases.

Features

  • 🔒 SSH bastion support for secure access to private RDS instances via SSH tunnels
  • 🐘 PostgreSQL read-only query engine using the pg library
  • 📡 STDIO-based MCP protocol transport
  • 🧠 Compatible with memory-bank-mcp-server
  • ⚙️ Easily configurable via .env or environment variables
  • 🧪 Fully testable with Jest and mocks

Installation

Clone the repository and install dependencies:

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

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.