PostgreSQL MCP Server

PostgreSQL MCP Server

A Model Context Protocol server that enables interaction with PostgreSQL databases to list tables, retrieve schemas, and execute read-only SQL queries.

Category
Visit Server

README

MCP PostgreSQL Server

This is a Model Context Protocol server for interacting with PostgreSQL databases. It provides a read-only interface to query PostgreSQL databases and inspect their schema.

Installation

npm install -g @hthuong09/postgres-mcp

Configuration

The server can be configured in multiple ways, listed in order of priority:

  1. Environment Variables

    • POSTGRES_URL: Full database URL (e.g., postgres://user:pass@host:5432/dbname)
    • Individual connection parameters:
      • POSTGRES_HOST: Database host
      • POSTGRES_PORT: Database port (default: 5432)
      • POSTGRES_DB: Database name
      • POSTGRES_USER: Database user
      • POSTGRES_PASSWORD: Database password
      • POSTGRES_SSL: Enable SSL mode (set to 'true' to enable)
      • POSTGRES_SCHEMA: Database schema (default: 'public')
    • Additional configuration:
      • DOTENV_PATH: Custom path to .env file
      • DEBUG_MCP: Enable debug logging (set to 'true' to enable)
  2. Command Line

    npx @hthuong09/postgres-mcp "postgres://user:pass@host:5432/dbname"
    

Resources

  • Table schemas: Each table in the database is exposed as a resource
  • Resource URI format: postgres://user@host/dbname/table_name/schema
  • Response format: JSON array of column definitions (name and data type)

Usage Examples

  1. Using environment variables:

    export POSTGRES_HOST=localhost
    export POSTGRES_DB=mydb
    export POSTGRES_USER=myuser
    export POSTGRES_PASSWORD=mypassword
    npx @hthuong09/postgres-mcp
    
  2. Using a connection URL:

    npx @hthuong09/postgres-mcp "postgres://myuser:mypassword@localhost:5432/mydb"
    
  3. Using environment variables with SSL:

    export POSTGRES_HOST=db.example.com
    export POSTGRES_DB=mydb
    export POSTGRES_USER=myuser
    export POSTGRES_PASSWORD=mypassword
    export POSTGRES_SSL=true
    npx @hthuong09/postgres-mcp
    
  4. Using a custom .env file location:

    DOTENV_PATH=/path/to/.env npx @hthuong09/postgres-mcp
    

Security Considerations

  • Database credentials should be kept secure
  • Use environment variables or .env files instead of command line arguments in production to avoid exposing credentials in process lists
  • Consider using SSL in production environments
  • The server only allows read-only transactions for safety
  • Passwords are automatically stripped from resource URIs

Development

To build the server locally:

npm install
npm run build

To run in watch mode during development:

npm run watch

Debugging

Set DEBUG_MCP=true to enable debug logging. Logs will be written to:

  • Unix/macOS: /tmp/postgres-mcp-debug.json
  • Windows: %TEMP%/postgres-mcp-debug.json

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured