MCP Connector

Query PostgreSQL Databases with Claude

An MCP server giving Claude read-only PostgreSQL access for schema inspection and safe, SELECT-only data analysis.

Works with postgres

76
Spark score
out of 100
Updated 7 months ago
Version 1.0.0
Models
claude

Add to Favorites

Why it matters

Enable Claude to directly query PostgreSQL databases for data analysis and schema inspection. Access and understand your database content without manual SQL writing.

Outcomes

What it gets done

01

Execute read-only SQL queries on PostgreSQL.

02

List all tables within the database.

03

Retrieve schema information for specific tables.

04

Analyze database content by generating and executing SQL.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/vb-postgres | bash

Capabilities

Tools your agent gets

query

Execute a read-only SQL query against the PostgreSQL database.

list_tables

List all tables available in the connected PostgreSQL database.

describe_table

Get schema information and column details for a specific table.

Overview

PostgreSQL MCP

This MCP server gives Claude read-only PostgreSQL access - schema inspection, table listing, and SELECT-only query execution. Use it when you want Claude to explore and analyze data in an existing PostgreSQL database without any risk of writing to it.

What it does

The PostgreSQL MCP server gives Claude read-only access to PostgreSQL databases for data analysis and schema inspection. It exposes three tools: query (executes a read-only SQL query, restricted to SELECT statements for safety), list_tables (lists all tables in the database), and describe_table (returns column and schema information for a named table). It also exposes the database schema as resources - a full-schema resource and a per-table schema resource - so Claude can inspect structure without running a query first.

When to use - and when NOT to

Use it when you need Claude to analyze data or inspect schema in an existing PostgreSQL database without risk of writing to it. It is not for write operations: only SELECT queries are permitted, and the security guidance recommends connecting through a read-replica in production and limiting accessible schemas rather than granting broad access.

Capabilities

Given a natural-language request, Claude inspects the relevant table schema, writes an appropriate SQL query, executes it through the query tool, and presents the results - for example, analyzing a users table to show signup distribution by month. The list_tables and describe_table tools let Claude discover database structure on its own before writing a query, rather than requiring the schema to be provided up front. The server also exposes the schema directly as resources - postgres://schema for the full database schema and postgres://tables/{table_name} for an individual table's schema - so Claude can pull structure without invoking a tool call.

How to install

Install globally via npm install -g @modelcontextprotocol/server-postgres, then add the server to your Claude Code MCP configuration with the connection string as an argument to npx.

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:password@localhost:5432/database"
      ]
    }
  }
}

Use a connection string with appropriately scoped credentials - read-only access is the default behavior.

Who it's for

Developers and analysts who want Claude to explore and query a PostgreSQL database directly - inspecting schema, running ad hoc SELECT queries, and summarizing results - without any risk of the connector writing to the database.

Source README

The PostgreSQL MCP server provides Claude with read-only access to PostgreSQL databases for data analysis and schema inspection.

Installation

npm install -g @modelcontextprotocol/server-postgres

Configuration

Add to your Claude Code settings:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://user:password@localhost:5432/database"
      ]
    }
  }
}

Available Tools

query

Execute a read-only SQL query.

query(sql: string): QueryResult

Note: Only SELECT queries are allowed for safety.

list_tables

List all tables in the database.

list_tables(): TableInfo[]

describe_table

Get schema information for a table.

describe_table(table_name: string): ColumnInfo[]

Resources

The server exposes database schema as resources:

  • postgres://schema - Full database schema
  • postgres://tables/{table_name} - Individual table schemas

Security Considerations

  • Read-only access by default
  • Connection string should use appropriate credentials
  • Consider using a read-replica for production
  • Limit accessible schemas if needed

Usage Example

Claude, please analyze the users table and show me
the distribution of users by signup month.

Claude will:

  1. Inspect the table schema
  2. Write an appropriate SQL query
  3. Execute and present the results

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.