SQL MCP Server logo

SQL MCP Server

by t3ta

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. It supports AWS RDS with read-only transactions and uses stdin/stdout-based communication.

View on GitHub

Last updated: N/A

What is SQL MCP Server?

The SQL MCP Server is a TypeScript implementation of a Model Context Protocol (MCP) server designed to allow language models and other MCP-compatible clients to securely query PostgreSQL databases, even those behind SSH bastion tunnels.

How to use SQL MCP Server?

First, clone the repository and install dependencies using npm install. Configure your database connection details in a .env file or via environment variables. Then, build the project using npm run build. Finally, run the server using npx -y @modelcontextprotocol/server-postgres postgresql://<user>:<pass>@localhost:5433/<dbname>. Input is provided via stdin in JSON format, and output is returned via stdout, also in JSON format.

Key features of SQL MCP Server

  • SSH bastion support for secure access to private RDS instances

  • PostgreSQL read-only query engine using the pg library

  • STDIO-based MCP protocol transport

  • Compatible with memory-bank-mcp-server

Use cases of SQL MCP Server

  • Securely querying databases from language models

  • Integrating PostgreSQL databases with AI-driven applications

  • Accessing databases behind SSH tunnels

  • Building MCP-compatible tools and services

FAQ from SQL MCP Server

What databases are supported?

Currently, only PostgreSQL is supported.

Does it support write operations?

No, it only supports read-only queries for security reasons.

How do I configure the SSH tunnel?

You can configure the SSH tunnel settings in the .env file or via environment variables, including the bastion host, user, and private key path.

Is this compatible with other MCP servers?

Yes, it is designed to be compatible with other MCP servers, such as memory-bank-mcp-server.

What is the Model Context Protocol (MCP)?

The Model Context Protocol (MCP) is a standard for communication between language models and external tools or services, enabling them to access and utilize external data and functionality.