LabscoMCP early access ↗
NetanelBollagMCP SERVER

Simple PostgreSQL MCP Server Template

A deliberately small PostgreSQL MCP server — run a query, test the connection, browse the schema as resources — written to be read and forked.

by NetanelBollag ↗Relational SQL DatabasesCommunity

LABSCO SUMMARY

Its real output is the code, not the query tool.

Tools, resources and prompts are all demonstrated against one small domain, which is exactly what is missing from most MCP examples — and the bundled docs make the fork path short. Take the author's warning literally though: the only guard on a query is that it begins with SELECT, so this belongs on a scratch database, not on anything with customers in it.

What it is

A template project that happens to be a working PostgreSQL MCP server. It demonstrates all three MCP primitives against a real database: tools that execute queries, resources that expose the schema, and prompts that generate query templates. The code is kept straightforward with the MCP documentation bundled alongside it, so it can be read end to end and adapted into your own server.

What you get

  • SQL run against your database, and a connection check for when nothing is coming back — execute_query, test_connection
  • Schema browsable as resources rather than queries: every table in the schema, one table's structure, or the whole schema at once — db://tables, db://tables/{table_name}, db://schema
  • Prompt templates for query generation and analytical query building
  • A worked example database: a script that starts a PostgreSQL container pre-populated with sample users and addresses tables
  • A config generator script that writes the client configuration from your DSN and schema name, rather than editing JSON by hand
  • A layout intended to be copied: add a directory under /src, implement the server, add it to [project.scripts] in pyproject.toml

Requirements

A PostgreSQL database you can reach, and its DSN. Python 3.8+, the uv package manager, and npx from Node.js for the MCP Inspector. Create the environment with uv venv and install from requirements.txt. Two environment variables carry the configuration: DSN in the form postgresql://<YOUR_DB_USER>:<YOUR_DB_PASSWORD>@<YOUR_DB_HOST>:<YOUR_DB_PORT>/<YOUR_DB_NAME>, and SCHEMA, typically public. The client runs it as uv --directory <YOUR_PATH_TO_SIMPLE_PSQL_MCP> run postgres; the pyproject is simple-psql-mcp 1.0.0 with a postgres entry point. The author's own security note is blunt: the server checks that a query starts with SELECT and nothing beyond that is guaranteed, so do not point it at a production database.

Setup effort

Build from source — git clone https://github.com/NetanelBollag/simple-psql-mcp.git