neon-serverless

A guide for using Neon's serverless database driver, which connects applications to hosted PostgreSQL through web-friendly connection methods. Serverless environments run code on demand instead of keeping one server running continuously.

In plain words
What is it for?
Querying Neon from Vercel Edge Functions, Cloudflare Workers, AWS Lambda, Google Cloud Functions, and similar serverless applications.
Why use it?
It helps developers choose and configure database connections for edge functions and serverless APIs while keeping connection credentials in environment variables.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/neondatabase/ai-rules/neon-serverless
Clone the repo
git clone --depth 1 https://github.com/neondatabase/ai-rules
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 2,128 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02128
Opus 5 $0.00000 $0.01064
Sonnet 5 $0.00000 $0.00426
Haiku 4.5 $0.00000 $0.00213

Measured 3d ago against content hash 614e037a299c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

neon-serverless scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

neon-serverless.mdc · 295 lines

How it starts

The opening of the file, as written. The whole thing — 295 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Neon Serverless Driver Guidelines

Overview

This guide provides specific patterns and best practices for connecting to Neon databases in serverless environments using the @neondatabase/serverless driver. The driver connects over HTTP for fast, single queries or WebSockets for node-postgres compatibility and interactive transactions. Follow these guidelines to ensure efficient connections and optimal performance.

Installation

Install the Neon Serverless driver with the correct package name:

# Using npm
npm install @neondatabase/serverless

# Using JSR
bunx jsr add @neon/serverless

Note: The driver version 1.0.0 and higher requires Node.js v19 or later.

For projects that depend on pg but want to use Neon's WebSocket-based connection pool:

"dependencies": {
  "pg": "npm:@neondatabase/serverless@^0.10.4"
},
"overrides": {
  "pg": "npm:@neondatabase/serverless@^0.10.4"
}

Avoid incorrect package names like neon-serverless or pg-neon.

Connection String

Always use environment variables for database connection strings to avoid exposing credentials.

// For HTTP queries
import { neon } from '@neondatabase/serverless';
const sql = neon(process.env.DATABASE_URL!);

// For WebSocket connections
import { Pool } from '@neondatabase/serverless';
const pool = new Pool({ connectionString: process.env.DATABASE_URL! });

Never hardcode credentials in your code:

// AVOID: Hardcoded credentials
const sql = neon('postgres://username:[email protected]/neondb');

Querying with the neon function (HTTP)

The neon() function is ideal for simple, "one-shot" queries in serverless and edge environments as it uses HTTP fetch and is the fastest method for single queries.

Parameterized Queries

Use tagged template literals for safe parameter interpolation. This is the primary defense against SQL injection.

const [post] = await sql`SELECT * FROM posts WHERE id = ${postId}`;

Read the full file on GitHub · 295 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 295 lines · 2,128 tokens per session scan A 614e037a299c

Subscribe to this mod's changes

neon-serverless is a cursor rule published in the GitHub repository neondatabase/ai-rules (86 stars, last pushed 3mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,128 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.