Neon PostgreSQL MCP Server

Neon PostgreSQL MCP Server

neon-pg-mcp-server•byspragginsdesigns

A Model Context Protocol server that gives AI assistants standardized tools for securely querying, modifying, and inspecting Neon PostgreSQL databases.

License: MIT License•Runtime: Awaiting documentation review•Category: databases storage

WHAT IT DOES

  • •Provides a query tool that runs read-only SELECT, WITH, and EXPLAIN statements inside a read-only transaction, capping unbounded results at 100 rows.
  • •Provides an execute tool for data-modifying statements such as INSERT, UPDATE, DELETE, and DDL, requiring an explicit project for writes.
  • •Offers schema inspection tools including table listing, table description, data sampling, and schema search.
  • •Lists the slowest statements tracked by pg_stat_statements for query tuning.

BEST FOR

  • •AI assistants that need to explore and query a Neon PostgreSQL database through natural-language-driven tool calls.
  • •Developers managing several Neon projects from one server instance with per-project read-only safeguards.
  • •Database tuning workflows where an agent identifies and investigates slow queries before optimizing them.

ABOUT NEON-PG-MCP-SERVER

Neon PostgreSQL MCP Server is cataloged as an MCP server attributed to spragginsdesigns. A Model Context Protocol server that gives AI assistants standardized tools for securely querying, modifying, and inspecting Neon PostgreSQL databases. It is categorized under databases storage. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.

HOW TO INSTALL

Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.

LICENSE

Catalog license label: MIT License. Check the source repository's current license and terms before using, modifying or distributing this software.

能力检查器

能力定义尚未审核。未核验的采集内容不会作为可信接口展示。

Tools (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Resources (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Prompts (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

NEWSLETTER - COMING LATER

Newsletter subscriptions are not open yet

Email delivery is not connected. This page does not collect email addresses or create subscriptions.

Browse the registry for current listings instead.

Community Reviews

Coming later

Reviews for Neon PostgreSQL MCP Server are not available yet

Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.

FREQUENTLY ASKED QUESTIONS

Can the server work with multiple Neon projects at once?

Yes. One server instance can serve several Neon projects, with pools created lazily per project on first use.

How does the server prevent writes to specific projects?

Projects listed in NEON_PG_READONLY_PROJECTS have the execute tool refused outright, while reads still work.

What safety measures apply to the query tool?

The query tool only accepts SELECT, WITH, and EXPLAIN statements and runs them in a read-only transaction with results capped at 100 rows.

上游原版 README

在 GitHub 查看同一版本原文

README.md · 5ad5b87a3e80 · 采集于 2026-11-13 12:51:25 UTC

保留上游原文,不做 AI 改写。为安全起见过滤脚本、表单和不安全链接。

当前显示最后一次成功采集的文档快照,请以来源页面为准。

Neon PostgreSQL MCP Server

A Model Context Protocol (MCP) server that provides secure access to Neon PostgreSQL databases, enabling AI assistants like Claude to interact with your database through standardized tools.

Overview

This MCP server allows AI assistants to:

  • Query data using SELECT statements
  • Execute data modifications (INSERT, UPDATE, DELETE)
  • List available tables
  • Describe table structures

The server implements multiple versions to demonstrate different approaches:

  • pg-mcp-server.js - Modern ES module implementation using the latest MCP SDK
  • index.js - CommonJS implementation with class-based architecture
  • basic-pg-server.js - Simplified implementation with basic MCP protocol handling
  • src/index.ts - TypeScript implementation (requires compilation)

Features

  • Secure Connection: SSL/TLS encrypted connections to Neon PostgreSQL
  • Connection Pooling: Efficient database connection management
  • Type Safety: Input validation for all operations
  • Error Handling: Comprehensive error handling with meaningful messages
  • MCP Compliance: Full implementation of the Model Context Protocol specification

Prerequisites

  • Node.js 18+
  • A Neon PostgreSQL database account and connection string
  • An MCP-compatible client (e.g., Claude Desktop, Cursor IDE)

Installation

  1. Clone this repository:
git clone <repository-url>
cd neon-pg-server
  1. Install dependencies:
npm install
  1. Configure your Neon PostgreSQL connection(s) via environment variables (see below):
export NEON_PG_CONNECTION_STRING="postgresql://user:password@host/database?sslmode=require"

Environment Variables

VariableRequiredPurpose
NEON_PG_CONNECTION_STRINGone of the twoSingle connection string, registered as the project named default. The original single-database setup — still fully supported.
NEON_PG_CONNECTIONSone of the threeJSON object mapping project names to connection strings, e.g. {"versemind":"postgresql://...","linecrush":"postgresql://..."}. Can be combined with NEON_PG_CONNECTION_STRING.
NEON_PG_CONNECTIONS_FILEone of the threePath to a JSON file with the same name → connection-string map. Useful for sharing one connections map across many MCP registrations on a machine (keep the file out of version control, e.g. ~/.secrets/neon-connections.json).
NEON_PG_READONLY_PROJECTSnoComma-separated project names for which the execute tool is refused outright (reads still work).

At least one of the first three must be set. Sources merge in order — NEON_PG_CONNECTION_STRING (as default), then NEON_PG_CONNECTIONS_FILE, then NEON_PG_CONNECTIONS — with later sources overriding earlier ones per name (a warning is logged to stderr on override).

Multi-Project Setup

One server instance can serve several Neon projects. Pools are created lazily per project on first use, so configuring six projects does not open six pools at startup.

{
  "neon-pg": {
    "command": "node",
    "args": ["/path/to/neon-pg-server/pg-mcp-server.js"],
    "env": {
      "NEON_PG_CONNECTION_STRING": "postgresql://user:pw@ep-old-host.aws.neon.tech/verceldb?sslmode=require",
      "NEON_PG_CONNECTIONS": "{\"versemind\":\"postgresql://user:pw@ep-vm-host.aws.neon.tech/neondb?sslmode=require\",\"linecrush\":\"postgresql://user:pw@ep-lc-host.aws.neon.tech/verceldb?sslmode=require\"}",
      "NEON_PG_READONLY_PROJECTS": "linecrush"
    }
  }
}

With this config:

  • get_tables with no arguments runs against default (the legacy connection string) — existing setups keep working unchanged.
  • get_tables with project: "versemind" runs against the versemind database.
  • execute with project: "linecrush" is refused because linecrush is in NEON_PG_READONLY_PROJECTS.
  • list_projects shows all three names with their host and database (never credentials).

Default project resolution: the project named default (from NEON_PG_CONNECTION_STRING or a default key in NEON_PG_CONNECTIONS) is the default for read tools. If no default exists but exactly one project is configured, that one is the default. With multiple named projects and no default, read tools require an explicit project argument.

Multi-Project Safety Rules

These exist so it is impossible to read a tool result — or run a write — without knowing which database it touched:

  1. execute always requires an explicit project argument. There is no default and no inference for writes; a missing or unknown project is an error that lists the valid names and runs nothing.
  2. Every tool result carries a source block (project, database, host) — success or error, read or write. Error text is prefixed with [project=... database=...].
  3. NEON_PG_READONLY_PROJECTS hard-blocks execute per project, even with an explicit project argument.
  4. MCP resources (neon://...) are served from the default project only.

Usage

Running the Server

Choose one of the available implementations:

ES Module version (recommended):

node pg-mcp-server.js

CommonJS version:

node index.js

Basic version:

node basic-pg-server.js

TypeScript version:

# First compile
npm run build
# Then run
node build/index.js

Integrating with Claude Desktop

  1. Open Claude Desktop settings
  2. Navigate to Developer → MCP Servers
  3. Add a new server configuration:
{
  "neon-postgres": {
    "command": "node",
    "args": ["/path/to/neon-pg-server/pg-mcp-server.js"],
    "env": {
      "NEON_PG_CONNECTION_STRING": "your-connection-string-here"
    }
  }
}

Integrating with Cursor IDE

  1. Open File → Preferences → Cursor Settings → MCP
  2. Add New Server
  3. Configure with the path to your server script

Available Tools

Production pg-mcp-server.js exposes 9 tools. Each tool includes Claude/Codex-friendly titles, read/write annotations, structured output schemas, and JSON text fallbacks.

Every tool except list_projects accepts an optional project argument selecting the named connection to run against (default: the default project). On execute the project argument is required. Every result includes a source block stating the project, database, and host it ran against.

0. List Projects Tool

List the configured project connections: name, host, database, default flag, and read-only flag. Never returns credentials.

Parameters: None

1. Query Tool

Execute read-only SELECT, WITH, and EXPLAIN queries to retrieve data from your database.

The query tool runs inside a read-only transaction and safely caps unbounded top-level result sets at 100 rows, so agents can omit LIMIT during exploration. A trailing semicolon is accepted.

Parameters:

  • sql (required): SQL SELECT, WITH, or EXPLAIN statement to execute
  • params (optional): Array of query parameters for parameterized queries

Example:

SELECT * FROM users WHERE age > $1

2. Execute Tool

Execute SQL statements that modify data (INSERT, UPDATE, DELETE, DDL).

Parameters:

  • sql (required): SQL statement to execute
  • project (required): Named project to write to — no default is applied for writes
  • params (optional): Array of statement parameters

Refused outright for projects listed in NEON_PG_READONLY_PROJECTS.

Example:

INSERT INTO users (name, email) VALUES ($1, $2)

3. List Slow Queries Tool

List the slowest statements tracked by pg_stat_statements.

Parameters:

  • limit (optional): Max queries to return, default 10, hard cap 25
  • order_by (optional): Sort metric, one of mean_exec_time, total_exec_time, calls, or rows
  • min_mean_ms (optional): Minimum mean execution time in milliseconds

If pg_stat_statements is not installed, the tool returns a structured setup note instead of a cryptic database error.

4. Get Tables Tool

List public schema tables with approximate size and column counts.

Parameters: None

5. Get Schema Tool

Return schema overview: table names, sizes, row estimates, column counts, and pagination metadata.

Parameters:

  • tables (optional): Specific public tables to include
  • limit (optional): Max tables to return, default 50, hard cap 200
  • offset (optional): Tables to skip for pagination
  • include_all (optional): Include backup/archive tables

6. Describe Table Tool

Get detailed structure information about a specific public table.

Parameters:

  • table (required): Name of the table to describe

Returns:

  • Column information (name, data type, nullable, default value)
  • Primary key columns, foreign keys, indexes, enum values, JSONB keys (sampled from up to 50 non-null rows per column), size, row estimate

7. Sample Data Tool

Return a few rows from a public table plus inferred JSONB structure.

Parameters:

  • table (required): Name of the table to sample
  • limit (optional): Number of rows, default 3, hard cap 10

8. Search Schema Tool

Search public table and column names by case-insensitive text pattern.

Parameters:

  • pattern (required): Text to search for in table and column names

Agent Ergonomics

  • Server instructions tell Claude/Codex how to use schema discovery tools and avoid unnecessary LIMIT retries.
  • Tool annotations mark read-only vs write tools for safer host permissions and confirmations.
  • Completions provide suggestions for table names, prompt arguments, resource template arguments, and sample limits.
  • Structured logging supports client-controlled log levels without writing protocol-breaking output to stdout.
  • Payload budgeting trims oversized query, sample, and slow-query results below host limits before Claude receives them.
  • Slow-query discovery gives agents a safe pg_stat_statements entry point before they start tuning queries.

Security Considerations

  • Connection String: Store your connection strings as environment variables, never commit them to version control
  • SSL/TLS: The server enforces SSL connections to Neon PostgreSQL
  • Source Attribution: Every tool result and error names the project, database, and host it ran against, so results can never be misattributed to the wrong database
  • Write Targeting: execute requires an explicit project argument and honors NEON_PG_READONLY_PROJECTS
  • Query Validation: The server validates that:
    • Query tool only accepts SELECT, WITH, and EXPLAIN statements
    • Query tool runs inside a read-only transaction
    • Unbounded top-level query results are capped at 100 rows without requiring agents to write LIMIT
    • Execute tool rejects SELECT statements (use Query tool instead)
  • Payload Control: Query and sample results are reduced below host payload limits by truncating large cells, then rows as a last resort
  • Parameterized Queries: Use parameterized queries to prevent SQL injection

Configuration

Connection Pool Settings

The server uses the following default pool settings:

  • Maximum connections: 10
  • Idle timeout: 30 seconds

You can modify these in the connection pool initialization:

this.pool = new pg.Pool({
  connectionString: CONNECTION_STRING,
  ssl: { rejectUnauthorized: true },
  max: 10,  // Adjust as needed
  idleTimeoutMillis: 30000  // Adjust as needed
});

Development

Project Structure

neon-pg-server/
├── pg-mcp-server.js      # Main ES module implementation
├── index.js              # CommonJS implementation
├── basic-pg-server.js    # Basic implementation
├── src/
│   └── index.ts         # TypeScript implementation
├── build/               # Compiled TypeScript output
├── package.json         # Project dependencies
├── tsconfig.json        # TypeScript configuration
└── README.md           # This file

Building from TypeScript

If you want to use the TypeScript version:

# Install dev dependencies
npm install

# Compile TypeScript
npx tsc

# Run compiled version
node build/index.js

Troubleshooting

Connection Issues

  • Verify your connection string is correct
  • Ensure your Neon database is active
  • Check that SSL is enabled (required for Neon)

MCP Client Issues

  • Ensure the MCP client can find the server executable
  • Check that environment variables are properly passed to the server
  • Review server logs (output to stderr) for error messages

Query Errors

  • Verify SQL syntax is correct
  • Check that tables and columns exist
  • Ensure proper permissions for database operations

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

License

MIT License - see LICENSE file for details

Acknowledgments

Install configuration

Are you the maintainer?

Claim this server with your GitHub account to request manual ownership verification.

README Embed Badge
Markdown

Link to the catalog listing for Neon PostgreSQL MCP Server from your README. This badge does not certify ownership, compatibility or security.

[![MCP catalog listing](https://img.shields.io/badge/MCP-awesome--mcp-orange?style=flat-square)](https://awesome-mcp.com/servers/neon-pg-mcp-server)

REPOSITORY STATS

GitHub StarsUnavailable
ForksUnavailable

Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.

下载与拉取统计

来源、范围和时段分别列出;不相加,不代表安装人数、活跃用户或安全审核。

尚无已审核的包 / 镜像标识,暂不展示下载统计。

Related databases storage MCP Servers

Alternative and complementary servers in the same category

View all in databases storage →
AIStor MCP server
mcp-server-aistor•minio

This is a Model Context Protocol (MCP) server for interacting with AIStor object stores.

Repository stats unavailable
Databases & Storage
InfluxDB v2 MCP Server
influxdb-mcp-server•idoru

A Model Context Protocol (MCP) server that exposes access to an InfluxDB v2 instance using the InfluxDB OSS API v2.

Repository stats unavailable
Databases & Storage