Get the FREE Ultimate OpenClaw Setup Guide →

postgresql

A Spring Boot application implementing an MCP (Model Context Protocol) server that provides read-only access to a PostgreSQL database via STDIO transport.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio krdk01-postgresql-mcp-server docker run -i --rm -e DATABASE_URL=${input:pg_url} -e DATABASE_USERNAME=${input:pg_user} -e DATABASE_PASSWORD=${input:pg_password} -e APP_CURRENT_SCHEMA=${input:pg_schema:public} mcp-postgres-spring \
  --env DATABASE_URL="jdbc:postgresql://host:5432/db" \
  --env DATABASE_PASSWORD="db_password" \
  --env DATABASE_USERNAME="db_user" \
  --env APP_CURRENT_SCHEMA="public"

How to use

This MCP server provides read-only access to a PostgreSQL database via STDIO transport using a Spring Boot implementation. It exposes a query tool that lets you execute restricted SQL queries with paging, and a dynamic resource discovery endpoint that surfaces table schemas from information_schema.columns. To use it, deploy the server (for example as a Docker container using the provided image mcp-postgres-spring). Once running, you can issue the read-only query operation by supplying a SQL statement that contains a WHERE clause, does not use wildcard selects, and is executed within a read-only transaction with LIMIT/OFFSET for paging. You can also request resource metadata for a given table to learn about its columns and data types. The server will return results as JSON arrays and schema metadata as JSON objects, with dynamic discovery performed on each request.

How to install

Prerequisites:

  • Java JDK 17+ and Maven if you are building from source
  • Docker (for containerized deployment) or a Java runtime if you plan to run a packaged jar

Installation steps:

  1. Build the project (optional if using pre-built image): mvn clean package

    This will generate a postgresql-mcp-server.jar in the target directory

  2. Run with Docker (using the provided image name from the README): docker run -i --rm
    -e DATABASE_URL=jdbc:postgresql://host:5432/db
    -e DATABASE_USERNAME=db_user
    -e DATABASE_PASSWORD=db_pass
    -e APP_CURRENT_SCHEMA=public
    mcp-postgres-spring

  3. Alternatively, run as a Java application (if you built the jar): java -jar target/postgresql-mcp-server.jar

  4. Verify server is up (example command): curl http://localhost:8080/metrics # or the appropriate health/endpoint for your setup

Additional notes

Notes and tips:

  • The server exposes a read-only SQL interface via the query tool. Ensure your provided SQL includes a WHERE clause and avoids SELECT * or ambiguous wildcard usage.
  • The dynamic resource discovery fetches schema metadata from information_schema.columns on each request, so there is no preloading at startup.
  • For SSE (Server-Sent Events) usage, configure the server in async mode and access the /sse endpoint as described in the README.
  • When using Docker/Podman, ensure environment variables (DATABASE_URL, DATABASE_USERNAME, DATABASE_PASSWORD, APP_CURRENT_SCHEMA) are correctly set for your database connection. These are placeholders in the mcp_config and should be replaced with real values in production.
  • If you modify Dockerfiles or image names, update the docker run command and image tag accordingly.

Related MCP Servers

Sponsor this space

Reach thousands of developers