Neon MCP Server

Neon MCP servers enable AI models to interact with serverless PostgreSQL databases, providing capabilities for structured data operations, SQL queries, database branching, and automatic scaling in a fully managed environment.

GitHub starsnpm versionnpm downloads

Overview

The MCP Neon Server bridges AI and serverless databases by letting language models (LLMs) work directly with Neon's serverless PostgreSQL platform. Neon provides instant database provisioning, automatic scaling, and database branching capabilities that make it ideal for modern development workflows.

Created by:

Developed by Neon

Key Features

Serverless PostgreSQL

Instant provisioning with automatic scaling and zero operational overhead

🌿

Database Branching

Create instant database branches for development, testing, and migrations

🔄

Project Management

Manage projects, branches, and compute resources programmatically

🎯

Advanced Operations

Schema migrations, query tuning, and performance optimization workflows

Available Tools

Quick Reference

ToolPurposeCategory
list_projectsList all Neon projectsProject Mgmt
create_projectCreate new projectProject Mgmt
describe_projectGet project detailsProject Mgmt
delete_projectRemove projectProject Mgmt
create_branchCreate database branchBranch Mgmt
delete_branchRemove branchBranch Mgmt
describe_branchGet branch detailsBranch Mgmt
list_branch_computesList compute endpointsBranch Mgmt
run_sqlExecute SQL queryQuery
run_sql_transactionExecute transactionQuery
get_database_tablesList tablesSchema
describe_table_schemaGet table structureSchema
get_connection_stringGet connection URLConnection
list_slow_queriesAnalyze performancePerformance
explain_sql_statementQuery execution planPerformance
prepare_database_migrationStart migration workflowMigration
complete_database_migrationFinish migrationMigration
prepare_query_tuningStart query optimizationPerformance
complete_query_tuningApply optimizationsPerformance
provision_neon_authSetup Neon AuthAuth

Detailed Usage

list_projects

Retrieve a list of your Neon projects with summary information.

use_mcp_tool({
  server_name: "neon",
  tool_name: "list_projects",
  arguments: {
    limit: 10  // Optional: default 10
  }
});

Returns project IDs, names, regions, and creation timestamps.

create_project

Create a new Neon project with custom configuration.

use_mcp_tool({
  server_name: "neon",
  tool_name: "create_project",
  arguments: {
    name: "production-db",
    region_id: "aws-us-east-2"
  }
});

Creates project with default database and compute endpoint.

create_branch

Create a new database branch for development or testing.

use_mcp_tool({
  server_name: "neon",
  tool_name: "create_branch",
  arguments: {
    project_id: "project-id-123",
    parent_branch: "main",
    name: "feature-new-schema"
  }
});

Instantly creates a copy-on-write branch from parent.

run_sql

Execute SQL queries with optional parameterization.

use_mcp_tool({
  server_name: "neon",
  tool_name: "run_sql",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    sql: "SELECT * FROM users WHERE id = $1",
    params: [42]
  }
});

Supports both read and write operations with parameters.

run_sql_transaction

Execute multiple SQL statements as an atomic transaction.

use_mcp_tool({
  server_name: "neon",
  tool_name: "run_sql_transaction",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    queries: [
      "INSERT INTO accounts (name, balance) VALUES ('Alice', 1000)",
      "INSERT INTO accounts (name, balance) VALUES ('Bob', 500)",
      "UPDATE stats SET total_accounts = total_accounts + 2"
    ]
  }
});

All queries succeed or fail together.

get_database_tables

List all tables in a database with optional schema filtering.

// List all tables in public schema
use_mcp_tool({
  server_name: "neon",
  tool_name: "get_database_tables",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    schema: "public"  // Optional, defaults to 'public'
  }
});

Returns table names and metadata.

describe_table_schema

Get detailed schema information for a specific table.

use_mcp_tool({
  server_name: "neon",
  tool_name: "describe_table_schema",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    table: "users",
    schema: "public"
  }
});

Returns columns, data types, constraints, and indexes.

prepare_database_migration

Initiate a safe migration workflow using database branching.

use_mcp_tool({
  server_name: "neon",
  tool_name: "prepare_database_migration",
  arguments: {
    project_id: "project-id-123",
    branch_id: "main",
    migration_sql: "ALTER TABLE users ADD COLUMN email_verified BOOLEAN DEFAULT false"
  }
});

Creates temporary branch and tests migration safely.

list_slow_queries

Identify performance bottlenecks by analyzing slow queries.

use_mcp_tool({
  server_name: "neon",
  tool_name: "list_slow_queries",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    min_duration_ms: 1000,  // Queries slower than 1s
    limit: 10
  }
});

Requires pg_stat_statements extension enabled.

explain_sql_statement

Analyze query execution plans for optimization.

use_mcp_tool({
  server_name: "neon",
  tool_name: "explain_sql_statement",
  arguments: {
    project_id: "project-id-123",
    branch_id: "branch-id-456",
    database: "neondb",
    sql: "SELECT * FROM orders WHERE user_id = 123 AND created_at > NOW() - INTERVAL '30 days'"
  }
});

Returns detailed execution plan with cost estimates.

provision_neon_auth

Setup Neon Auth integration with Stack Auth.

use_mcp_tool({
  server_name: "neon",
  tool_name: "provision_neon_auth",
  arguments: {
    project_id: "project-id-123"
  }
});

Configures authentication infrastructure automatically.

Installation

{
  "mcpServers": {
    "neon": {
      "command": "npx",
      "args": [
        "-y",
        "@neondatabase/mcp-server-neon",
        "start",
        "<YOUR_NEON_API_KEY>"
      ]
    }
  }
}

API Key Required:

You need to create a Neon API key from the Neon Console under Account Settings → API Keys.

Setup Guide

1. Create Neon Account

  1. Sign up at Neon Console
  2. Create your first project (or use existing one)
  3. Note your project ID from the project dashboard

2. Generate API Key

  1. Go to Account SettingsAPI Keys
  2. Click "Create API Key"
  3. Give it a descriptive name (e.g., "MCP Integration")
  4. Copy the API key immediately (shown only once)
  5. Store it securely

3. Configure MCP Server

Add the API key to your MCP configuration as shown in the Installation section above.

Project Selection:

The server can work with multiple projects. Specify the project_id in each tool call to target different projects.

Common Use Cases

1. Development Branch Workflow

Create isolated database branches for feature development:

// Create feature branch
use_mcp_tool({
  server_name: "neon",
  tool_name: "create_branch",
  arguments: {
    project_id: "my-project",
    parent_branch: "main",
    name: "feature-user-profiles"
  }
});

// Run migrations on feature branch
use_mcp_tool({
  server_name: "neon",
  tool_name: "run_sql",
  arguments: {
    project_id: "my-project",
    branch_id: "feature-user-profiles",
    database: "neondb",
    sql: `
      CREATE TABLE user_profiles (
        id SERIAL PRIMARY KEY,
        user_id INTEGER REFERENCES users(id),
        bio TEXT,
        avatar_url TEXT,
        created_at TIMESTAMPTZ DEFAULT NOW()
      )
    `
  }
});

// Test the changes, then delete branch when done
use_mcp_tool({
  server_name: "neon",
  tool_name: "delete_branch",
  arguments: {
    project_id: "my-project",
    branch_id: "feature-user-profiles"
  }
});

2. Safe Schema Migrations

Use the migration workflow for production changes:

// Prepare migration (creates test branch)
use_mcp_tool({
  server_name: "neon",
  tool_name: "prepare_database_migration",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    migration_sql: `
      ALTER TABLE orders
      ADD COLUMN tracking_number VARCHAR(100),
      ADD COLUMN shipped_at TIMESTAMPTZ
    `
  }
});

// Test migration on temporary branch...
// If successful, complete the migration

use_mcp_tool({
  server_name: "neon",
  tool_name: "complete_database_migration",
  arguments: {
    project_id: "my-project",
    migration_id: "migration-xyz"
  }
});

3. Query Performance Analysis

Identify and optimize slow queries:

// Find slow queries
use_mcp_tool({
  server_name: "neon",
  tool_name: "list_slow_queries",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    database: "neondb",
    min_duration_ms: 500,
    limit: 10
  }
});

// Analyze specific query
use_mcp_tool({
  server_name: "neon",
  tool_name: "explain_sql_statement",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    database: "neondb",
    sql: "SELECT * FROM orders WHERE status = 'pending' ORDER BY created_at DESC"
  }
});

// Optimize using query tuning workflow
use_mcp_tool({
  server_name: "neon",
  tool_name: "prepare_query_tuning",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    query: "SELECT * FROM orders WHERE status = 'pending' ORDER BY created_at DESC"
  }
});

4. Multi-Environment Management

Manage development, staging, and production databases:

// List all projects
use_mcp_tool({
  server_name: "neon",
  tool_name: "list_projects",
  arguments: { limit: 20 }
});

// Get details for production project
use_mcp_tool({
  server_name: "neon",
  tool_name: "describe_project",
  arguments: {
    project_id: "prod-project-id"
  }
});

// List compute endpoints for scaling info
use_mcp_tool({
  server_name: "neon",
  tool_name: "list_branch_computes",
  arguments: {
    project_id: "prod-project-id",
    branch_id: "main"
  }
});

5. Database Inspection and Schema Discovery

Explore database structure programmatically:

// List all tables
use_mcp_tool({
  server_name: "neon",
  tool_name: "get_database_tables",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    database: "neondb",
    schema: "public"
  }
});

// Get detailed schema for specific table
use_mcp_tool({
  server_name: "neon",
  tool_name: "describe_table_schema",
  arguments: {
    project_id: "my-project",
    branch_id: "main",
    database: "neondb",
    table: "users",
    schema: "public"
  }
});

Neon-Specific Features

Database Branching

Neon's branching is a game-changer for database workflows:

  • Instant copies: Create database branches in seconds using copy-on-write
  • Cost-effective: Only changed data consumes additional storage
  • Safe testing: Test migrations and schema changes without affecting production
  • CI/CD integration: Create ephemeral databases for each pull request

Autoscaling

Neon automatically scales compute resources:

  • Scale to zero: Compute automatically suspends during inactivity
  • Auto-resume: Instantly resumes when queries arrive
  • Cost optimization: Pay only for actual usage, not idle time

Connection Pooling

Built-in connection pooling for better performance:

  • Managed connection pool included
  • Reduces connection overhead
  • Better resource utilization

Best Practices

  1. Use branches for development: Never test schema changes on production branches
  2. Enable pg_stat_statements: Required for query performance analysis
  3. Monitor slow queries: Regularly check for performance bottlenecks
  4. Use transactions: Ensure data consistency with run_sql_transaction
  5. Leverage autoscaling: Design apps to handle compute suspension gracefully
  6. Clean up branches: Delete unused branches to optimize storage costs

Sources