@neon/skills 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/package.json +2 -2
- package/plugin.json +1 -1
- package/skills/neon/SKILL.md +206 -212
- package/skills/neon/references/auth.md +12 -0
- package/skills/neon/references/claimable-neon.md +10 -14
- package/skills/neon/references/function-triggers.md +53 -0
- package/skills/neon/references/logs-loki.md +61 -0
- package/skills/neon/references/parse-env.md +32 -0
- package/skills/neon/references/sdk.md +7 -0
- package/skills/neon-ai-gateway/SKILL.md +13 -15
- package/skills/neon-auth/SKILL.md +155 -0
- package/skills/neon-auth/references/managed-auth.md +173 -0
- package/skills/neon-auth/references/self-managed.md +25 -0
- package/skills/neon-functions/SKILL.md +146 -81
- package/skills/neon-functions/references/ai-sdk.md +4 -6
- package/skills/neon-functions/references/function-triggers.md +247 -0
- package/skills/neon-functions/references/mastra-studio.md +3 -3
- package/skills/neon-functions/references/mcp.md +1 -1
- package/skills/neon-functions/references/sse.md +8 -5
- package/skills/neon-object-storage/SKILL.md +10 -11
- package/skills/neon-postgres/SKILL.md +119 -17
- package/skills/neon-postgres/references/full-text-search.md +99 -0
- package/skills/neon-postgres/references/hybrid-search.md +90 -0
- package/skills/neon-postgres/references/vector-search.md +137 -0
- package/skills/neon-postgres-branches/SKILL.md +1 -1
- package/skills/neon-postgres-egress-optimizer/SKILL.md +1 -1
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Function Triggers
|
|
2
|
+
|
|
3
|
+
A Function Trigger is a branch-scoped rule that POSTs to a Neon Function so recurring work does not need a separate scheduler. The request is a normal `fetch` invocation: same public URL, same 15-minute time-to-first-byte limit, same injected env (`DATABASE_URL`, …).
|
|
4
|
+
|
|
5
|
+
Same regions as Functions: `aws-us-east-2`, `aws-us-east-1`, `aws-eu-central-1`, and `aws-ap-southeast-1`. Needs Neon CLI 4.21 or newer to declare triggers in `neon.ts`.
|
|
6
|
+
|
|
7
|
+
If `neon deploy` returns 404 `function triggers not available for this project`, the project does not have Function Triggers yet. Deploy the function without applying the trigger (`neon functions deploy <slug> --src <entry>`) and retry `neon deploy` once the project has them.
|
|
8
|
+
|
|
9
|
+
## Supported types
|
|
10
|
+
|
|
11
|
+
`triggers` is a keyed map on `defineConfig`. Types:
|
|
12
|
+
|
|
13
|
+
| `type` | When it fires | `neon.ts` fields | CLI create |
|
|
14
|
+
| ------------------------ | -------------------------------------------------- | ---------------------------------------- | ----------------------------------------------- |
|
|
15
|
+
| `schedule` | On a five-field UTC cron expression | `function`, `cron` | `neon triggers create --cron '…'` |
|
|
16
|
+
| `storage_object_created` | When an object is created in a declared bucket | `function`, `bucket`, optional `prefix` | `neon triggers create --bucket <name>` |
|
|
17
|
+
|
|
18
|
+
`create` takes `--cron` or `--bucket`, not both. `@neon/functions` ≥ 0.11.0: `parseTriggerDelivery` accepts both types; `parseTriggerInvocation` and Hono `parseTrigger(c)` stay schedule-only (`storage_object_created` is `invalid_body` there).
|
|
19
|
+
|
|
20
|
+
## Fields
|
|
21
|
+
|
|
22
|
+
The trigger name is the `neon.ts` map key (CLI `--name`). It must be unique among every trigger visible on the branch, including other functions.
|
|
23
|
+
|
|
24
|
+
| Field | Required | Notes |
|
|
25
|
+
| -------------- | -------- | --------------------------------------------------------------------- |
|
|
26
|
+
| `type` | yes | `"schedule"` or `"storage_object_created"` |
|
|
27
|
+
| `function` | yes | Function slug. REST/MCP: `function_slug` |
|
|
28
|
+
| `cron` | schedule | Five-field UTC expression, e.g. `0 * * * *`, `*/15 * * * *` |
|
|
29
|
+
| `bucket` | storage | Bucket name. REST: `storage_object_created.bucket_name` |
|
|
30
|
+
| `prefix` | no | Object-key prefix filter. REST: `storage_object_created.prefix` |
|
|
31
|
+
| `functionPath` | no | Path on the function. Default `/`. CLI: `--function-path` |
|
|
32
|
+
| `enabled` | no | Default `true`. CLI: `--enabled false` to create disabled |
|
|
33
|
+
|
|
34
|
+
## neon.ts (preferred)
|
|
35
|
+
|
|
36
|
+
Declare `triggers` next to `functions` (and `buckets` when using storage). `neon deploy` applies triggers **after** the functions they target. Triggers that exist remotely but are omitted from `neon.ts` are left alone.
|
|
37
|
+
|
|
38
|
+
```typescript
|
|
39
|
+
import { defineConfig } from "@neon/config/v1";
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
functions: {
|
|
43
|
+
ingest: { name: "Object ingest", source: "src/index.ts" },
|
|
44
|
+
cron: { name: "Cron", source: "src/cron.ts" },
|
|
45
|
+
},
|
|
46
|
+
buckets: { assets: { access: "public_read" } },
|
|
47
|
+
triggers: {
|
|
48
|
+
"on-upload": {
|
|
49
|
+
type: "storage_object_created",
|
|
50
|
+
function: "ingest",
|
|
51
|
+
bucket: "assets",
|
|
52
|
+
prefix: "logos/",
|
|
53
|
+
functionPath: "/object",
|
|
54
|
+
},
|
|
55
|
+
"every-minute": {
|
|
56
|
+
type: "schedule",
|
|
57
|
+
function: "cron",
|
|
58
|
+
cron: "* * * * *",
|
|
59
|
+
functionPath: "/cron",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
neon deploy
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Change the cron string, bucket, or prefix and deploy again to reschedule. Starter: `neon bootstrap --template cron-job`.
|
|
70
|
+
|
|
71
|
+
## CLI
|
|
72
|
+
|
|
73
|
+
Use when you are not applying `neon.ts`, or to list, enable, disable, or delete.
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
neon triggers create --function-slug cron --name hourly --cron '0 * * * *' --function-path /cron
|
|
77
|
+
neon triggers create --function-slug ingest --name on-upload --bucket assets --prefix 'logos/' --function-path /object
|
|
78
|
+
neon triggers list
|
|
79
|
+
neon triggers list --output json
|
|
80
|
+
neon triggers update <id> --branch <branch> --cron '*/30 * * * *'
|
|
81
|
+
neon triggers update <id> --branch <branch> --bucket assets --prefix 'incoming/'
|
|
82
|
+
neon triggers enable <id> --branch <branch>
|
|
83
|
+
neon triggers disable <id> --branch <branch>
|
|
84
|
+
neon triggers delete <id> --branch <branch>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`enable` / `disable` wrap `update --enabled`. Updating the cron recomputes `Next Run At`. Disabling clears `Next Run At`. Alias: `neon trigger`. `--cron` on a storage trigger, or `--bucket` / `--prefix` on a schedule trigger, is rejected.
|
|
88
|
+
|
|
89
|
+
Inspect a trigger with `neon triggers list --output json`. Pass `--branch` on get/update/enable/disable/delete: without it the CLI resolves the trigger id as a branch name.
|
|
90
|
+
|
|
91
|
+
Project and branch otherwise resolve from `--project-id` / `--branch`, then `.neon`, then a single-project auto-detect.
|
|
92
|
+
|
|
93
|
+
## MCP backup
|
|
94
|
+
|
|
95
|
+
The Neon MCP server (`?category=functions`) exposes `list_triggers`, `get_trigger`, `create_trigger`, `update_trigger`, and `delete_trigger`. `branch_id` is a `br-…` id, not a branch name (`list_branches` to resolve). Create a schedule trigger with snake_case:
|
|
96
|
+
|
|
97
|
+
```json
|
|
98
|
+
{
|
|
99
|
+
"type": "schedule",
|
|
100
|
+
"function_slug": "cron",
|
|
101
|
+
"name": "hourly",
|
|
102
|
+
"function_path": "/cron",
|
|
103
|
+
"schedule": { "cron": "0 * * * *" },
|
|
104
|
+
"enabled": true
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
`create_trigger` required fields for schedule: `type`, `function_slug`, `name`, `schedule`. REST is the same payload at `POST /projects/{project_id}/branches/{branch_id}/triggers`. For `storage_object_created`, use CLI or REST with `"type": "storage_object_created"` and `storage_object_created: { "bucket_name": "assets", "prefix": "logos/" }`. CLI docs: https://neon.com/docs/cli/triggers.md.
|
|
109
|
+
|
|
110
|
+
## Delivery payload
|
|
111
|
+
|
|
112
|
+
Neon POSTs JSON. The Functions proxy drops client-supplied `x-neon-*` headers, so a present `x-neon-trigger-invocation-id` is from a trigger delivery. It must match `invocation_id` in the body.
|
|
113
|
+
|
|
114
|
+
Schedule wire JSON (snake_case):
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"version": 1,
|
|
119
|
+
"invocation_id": "…",
|
|
120
|
+
"trigger": {
|
|
121
|
+
"type": "schedule",
|
|
122
|
+
"id": "trigger-…",
|
|
123
|
+
"name": "hourly"
|
|
124
|
+
},
|
|
125
|
+
"data": { "scheduled_at": "2026-09-15T23:35:00Z" }
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Storage-object-created wire JSON:
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"version": 1,
|
|
134
|
+
"invocation_id": "…",
|
|
135
|
+
"trigger": {
|
|
136
|
+
"type": "storage_object_created",
|
|
137
|
+
"id": "trigger-…",
|
|
138
|
+
"name": "on-upload"
|
|
139
|
+
},
|
|
140
|
+
"data": { "bucket_name": "uploads", "object_key": "smoke.txt" }
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Parsed (`@neon/functions` ≥ 0.11.0) is camelCase. `parseTriggerDelivery` also sets a top-level `type`. Schedule: `data.scheduledAt`. Storage: `data.bucketName`, `data.objectKey`. Narrow on `invocation.type` (or `isScheduleTriggerInvocation` / `isStorageObjectCreatedTriggerInvocation`) before reading `data` — a check on `trigger.type` does not narrow the sibling `data` field.
|
|
145
|
+
|
|
146
|
+
### `parseTriggerDelivery` (both types)
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { parseTriggerDelivery } from "@neon/functions/triggers";
|
|
150
|
+
|
|
151
|
+
export default {
|
|
152
|
+
async fetch(request: Request): Promise<Response> {
|
|
153
|
+
const parsed = await parseTriggerDelivery(request);
|
|
154
|
+
if (!parsed.ok) {
|
|
155
|
+
const status = parsed.error === "invalid_body" ? 400 : 401;
|
|
156
|
+
return new Response(parsed.error, { status });
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const invocation = parsed.invocation;
|
|
160
|
+
if (invocation.type === "storage_object_created") {
|
|
161
|
+
return Response.json({
|
|
162
|
+
bucketName: invocation.data.bucketName,
|
|
163
|
+
objectKey: invocation.data.objectKey,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return Response.json({
|
|
168
|
+
scheduledAt: invocation.data.scheduledAt,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
`parseTriggerDelivery(request)` clones the Request before `json()`, so `request.json()` still works. If you already have the body: `parseTriggerDelivery({ headers, body })` (sync). `parsed.error` is `missing_header`, `invalid_body`, or `invocation_id_mismatch`. Unknown `trigger.type` values fail as `invalid_body`.
|
|
175
|
+
|
|
176
|
+
Hono: `parseTriggerDelivery(c.req.raw)`.
|
|
177
|
+
|
|
178
|
+
### `parseTrigger` (Hono, schedule only)
|
|
179
|
+
|
|
180
|
+
Throws `HTTPException`. `c.req.json()` still works afterwards. Returns `ScheduleTriggerInvocation`. A `storage_object_created` delivery is `invalid_body`.
|
|
181
|
+
|
|
182
|
+
| Failure | Status | Message |
|
|
183
|
+
| ------------------------ | ------ | --------------------------------------------- |
|
|
184
|
+
| missing header | 401 | `Missing x-neon-trigger-invocation-id header` |
|
|
185
|
+
| header ≠ `invocation_id` | 401 | `Invocation id mismatch` |
|
|
186
|
+
| invalid JSON or payload | 400 | `Invalid trigger payload` |
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
import { parseTrigger } from "@neon/functions/hono";
|
|
190
|
+
|
|
191
|
+
app.post("/cron", async (c) => {
|
|
192
|
+
const invocation = await parseTrigger(c);
|
|
193
|
+
return c.json({ ok: true, invocationId: invocation.invocationId });
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### `parseTriggerInvocation` (`fetch`, schedule only)
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
import { parseTriggerInvocation } from "@neon/functions/triggers";
|
|
201
|
+
|
|
202
|
+
export default {
|
|
203
|
+
async fetch(request: Request): Promise<Response> {
|
|
204
|
+
const parsed = await parseTriggerInvocation(request);
|
|
205
|
+
if (!parsed.ok) {
|
|
206
|
+
const status = parsed.error === "invalid_body" ? 400 : 401;
|
|
207
|
+
return new Response(parsed.error, { status });
|
|
208
|
+
}
|
|
209
|
+
return Response.json({
|
|
210
|
+
ok: true,
|
|
211
|
+
invocationId: parsed.invocation.invocationId,
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
};
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Local `neon dev`
|
|
218
|
+
|
|
219
|
+
`neon dev` forwards `x-neon-trigger-invocation-id`, so you can simulate a tick:
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
curl -X POST http://localhost:8787/cron \
|
|
223
|
+
-H 'content-type: application/json' \
|
|
224
|
+
-H 'x-neon-trigger-invocation-id: local-dev' \
|
|
225
|
+
-d '{
|
|
226
|
+
"version": 1,
|
|
227
|
+
"invocation_id": "local-dev",
|
|
228
|
+
"trigger": { "type": "schedule", "id": "trigger-local", "name": "hourly" },
|
|
229
|
+
"data": { "scheduled_at": "2026-09-15T00:00:00Z" }
|
|
230
|
+
}'
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
A public POST to the **deployed** function that includes that header still returns 401: the proxy strips client `x-neon-*` headers.
|
|
234
|
+
|
|
235
|
+
## Inheritance
|
|
236
|
+
|
|
237
|
+
Triggers are branch-scoped. A trigger created on a parent is visible on children (`inherited: true`, `source_branch_id` points at the origin) and starts disabled there.
|
|
238
|
+
|
|
239
|
+
`neon deploy` of a `neon.ts` that declares the same trigger (default `enabled: true`) enables that inherited copy on the child. Omit it from `neon.ts` to leave the inherited trigger disabled. Enable without applying `neon.ts` with `neon triggers enable <id> --branch <branch>`.
|
|
240
|
+
|
|
241
|
+
## Logs
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
neon logs query --source function --since 1h
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Pass `--branch` when the function is not on the branch in `.neon`.
|
|
@@ -6,7 +6,7 @@ The shape mirrors any other Node integration (see [sentry.md](sentry.md)): insta
|
|
|
6
6
|
|
|
7
7
|
## 1. Define the agent against the Neon AI Gateway
|
|
8
8
|
|
|
9
|
-
With `@mastra/core` 1.47+, use a `neon/<model>` magic string — Mastra reads `NEON_AI_GATEWAY_BASE_URL` and `NEON_AI_GATEWAY_TOKEN` from the environment (injected by `neon deploy` / `neon env pull` when `
|
|
9
|
+
With `@mastra/core` 1.47+, use a `neon/<model>` magic string — Mastra reads `NEON_AI_GATEWAY_BASE_URL` and `NEON_AI_GATEWAY_TOKEN` from the environment (injected by `neon deploy` / `neon env pull` when `aiGateway` is enabled in `neon.ts`). No manual `url`/`apiKey` or MLflow dialect swap is needed; Mastra routes each model to the correct gateway endpoint.
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
12
|
// src/mastra/agents/pricing.ts
|
|
@@ -102,8 +102,8 @@ functions: {
|
|
|
102
102
|
name: "my app",
|
|
103
103
|
source: "src/index.ts",
|
|
104
104
|
env: {
|
|
105
|
-
MASTRA_PROJECT_ID: process.env.MASTRA_PROJECT_ID
|
|
106
|
-
MASTRA_PLATFORM_ACCESS_TOKEN: process.env.MASTRA_PLATFORM_ACCESS_TOKEN
|
|
105
|
+
MASTRA_PROJECT_ID: process.env.MASTRA_PROJECT_ID!,
|
|
106
|
+
MASTRA_PLATFORM_ACCESS_TOKEN: process.env.MASTRA_PLATFORM_ACCESS_TOKEN!,
|
|
107
107
|
},
|
|
108
108
|
},
|
|
109
109
|
}
|
|
@@ -89,7 +89,7 @@ Key points:
|
|
|
89
89
|
> [!WARNING]
|
|
90
90
|
> A Neon Function has a **public HTTPS URL — anyone can reach it.** An unauthenticated MCP server hands every caller your tools (and the database behind them). Authenticate at the top of the handler before touching the transport, exactly as for [any client-facing function](../SKILL.md#functions-as-an-agent-backend-nextjs-and-similar-frameworks).
|
|
91
91
|
|
|
92
|
-
[Better Auth](https://better-auth.com)
|
|
92
|
+
[Better Auth](https://better-auth.com) covers both common MCP shapes when you need an OAuth authorization server or API keys. Managed Auth does not. Keep existing app login (Clerk, Managed Auth, or Better Auth) unless the user asked to migrate it. Confirm the **installed** Better Auth version before copying imports: the MCP plugin is moving out of `better-auth/plugins` into `@better-auth/mcp` (`withMcpAuth` → `requireMcpAuth`, `createMcpAuthClient` → `createMcpResourceClient`). Docs: https://better-auth.com/docs/plugins/mcp
|
|
93
93
|
|
|
94
94
|
### Option 1 — OAuth via the Better Auth MCP plugin (best for third-party clients)
|
|
95
95
|
|
|
@@ -17,17 +17,20 @@ export default {
|
|
|
17
17
|
const url = new URL(request.url);
|
|
18
18
|
if (url.pathname !== "/events") return new Response("ok");
|
|
19
19
|
|
|
20
|
+
let timer: ReturnType<typeof setInterval>;
|
|
20
21
|
const stream = new ReadableStream<Uint8Array>({
|
|
21
22
|
start(controller) {
|
|
22
23
|
// An SSE frame is `data: <payload>\n\n`. A line starting with `:` is a
|
|
23
24
|
// comment — used here as a heartbeat to keep the stream from going idle.
|
|
24
25
|
controller.enqueue(encoder.encode("data: hello\n\n"));
|
|
25
|
-
|
|
26
|
+
timer = setInterval(
|
|
26
27
|
() => controller.enqueue(encoder.encode(": ping\n\n")),
|
|
27
28
|
25_000,
|
|
28
29
|
);
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
},
|
|
31
|
+
// cancel() fires when the client disconnects.
|
|
32
|
+
cancel() {
|
|
33
|
+
clearInterval(timer);
|
|
31
34
|
},
|
|
32
35
|
});
|
|
33
36
|
|
|
@@ -42,7 +45,7 @@ export default {
|
|
|
42
45
|
};
|
|
43
46
|
```
|
|
44
47
|
|
|
45
|
-
> `cancel()` is
|
|
48
|
+
> `cancel()` is a method on the stream's underlying source; it fires when the client disconnects. Use it to drop the client from any broadcast set and clear timers. A cleanup function returned from `start()` is ignored, so it has to be a real `cancel()` method.
|
|
46
49
|
|
|
47
50
|
## With Hono
|
|
48
51
|
|
|
@@ -91,7 +94,7 @@ const CHANNEL = "events";
|
|
|
91
94
|
// One dedicated DIRECT connection per isolate to receive events (LISTEN needs a
|
|
92
95
|
// real session — use DATABASE_URL_UNPOOLED, not the pooled URL).
|
|
93
96
|
// Don't call attachDatabasePool here: it would silence the idle drop that killed the feed.
|
|
94
|
-
//
|
|
97
|
+
// The error listener keeps the process alive; reconnect the client on error in production (omitted here).
|
|
95
98
|
const listener = new Client({
|
|
96
99
|
connectionString: process.env.DATABASE_URL_UNPOOLED,
|
|
97
100
|
});
|
|
@@ -22,12 +22,12 @@ metadata:
|
|
|
22
22
|
If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
|
|
23
23
|
|
|
24
24
|
```bash
|
|
25
|
-
|
|
25
|
+
neon skills -s neon -y
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
# Neon Object Storage
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
Currently available in `aws-us-east-2`, `aws-us-east-1`, `aws-eu-central-1`, and `aws-ap-southeast-1`.
|
|
31
31
|
|
|
32
32
|
Neon Object Storage is S3-compatible object storage that branches with your projects: every branch gets its own isolated storage state, so files and database rows stay in sync across dev, preview, staging, and production.
|
|
33
33
|
|
|
@@ -53,7 +53,7 @@ If the files in question ship with the app itself — HTML, JS bundles, CSS, the
|
|
|
53
53
|
|
|
54
54
|
## Availability
|
|
55
55
|
|
|
56
|
-
Check this precondition before setting anything up: Neon Object Storage is
|
|
56
|
+
Check this precondition before setting anything up: Neon Object Storage is currently available in `aws-us-east-2`, `aws-us-east-1`, `aws-eu-central-1`, and `aws-ap-southeast-1`. Confirm the user's Neon project is in one of these regions before proceeding. Region coverage: https://neon.com/docs/get-started/backend-overview.md
|
|
57
57
|
|
|
58
58
|
## Architecture: Where Object Storage Fits
|
|
59
59
|
|
|
@@ -64,18 +64,16 @@ Neon (Object Storage included) is **backend primitives, not full-stack app hosti
|
|
|
64
64
|
|
|
65
65
|
## Setup
|
|
66
66
|
|
|
67
|
-
Object storage is part of the `neon.ts` infrastructure-as-code config (see the `neon` skill for the branch-first workflow, `link`/`checkout`, and `neon.ts` basics). Declare buckets under `
|
|
67
|
+
Object storage is part of the `neon.ts` infrastructure-as-code config (see the `neon` skill for the branch-first workflow, `link`/`checkout`, and `neon.ts` basics). Declare buckets under `buckets`, keyed by bucket name:
|
|
68
68
|
|
|
69
69
|
```typescript
|
|
70
70
|
// neon.ts
|
|
71
71
|
import { defineConfig } from "@neon/config/v1";
|
|
72
72
|
|
|
73
73
|
export default defineConfig({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"public-assets": { access: "public_read" },
|
|
78
|
-
},
|
|
74
|
+
buckets: {
|
|
75
|
+
images: {}, // private by default
|
|
76
|
+
"public-assets": { access: "public_read" },
|
|
79
77
|
},
|
|
80
78
|
});
|
|
81
79
|
```
|
|
@@ -88,7 +86,7 @@ neon deploy # alias for `neon config apply`
|
|
|
88
86
|
|
|
89
87
|
## Neon Infrastructure as Code (`neon.ts`)
|
|
90
88
|
|
|
91
|
-
The `
|
|
89
|
+
The `buckets` block above is part of `neon.ts`, Neon's infrastructure-as-code file — one TypeScript file declares your buckets alongside every other service the branch should have (see the `neon` skill for the full reference). Reconcile the declaration against a branch the Terraform way:
|
|
92
90
|
|
|
93
91
|
```bash
|
|
94
92
|
neon config status # print the branch's live config (which buckets exist)
|
|
@@ -100,7 +98,7 @@ Buckets are **branch-scoped**: when a `neon.ts` is present, `neon checkout` appl
|
|
|
100
98
|
|
|
101
99
|
## Environment Variables
|
|
102
100
|
|
|
103
|
-
When `
|
|
101
|
+
When `buckets` is declared, Neon injects **AWS-standard** S3 env vars so the AWS SDKs work from the environment with zero extra config. Inside a deployed Neon Function these are injected automatically; locally, pull them onto disk (or inject them at runtime) via the CLI:
|
|
104
102
|
|
|
105
103
|
```bash
|
|
106
104
|
neon env pull # writes the branch's vars into .env (or .env.local)
|
|
@@ -218,6 +216,7 @@ The Neon documentation is the source of truth and Object Storage is evolving rap
|
|
|
218
216
|
|
|
219
217
|
## Further Reading
|
|
220
218
|
|
|
219
|
+
- https://neon.com/docs/get-started/backend-overview.md
|
|
221
220
|
- https://neon.com/docs/storage/overview.md
|
|
222
221
|
- https://neon.com/docs/storage/get-started.md
|
|
223
222
|
- https://neon.com/docs/storage/buckets.md
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: neon-postgres
|
|
3
3
|
description: >-
|
|
4
|
-
Guides and best practices for working with Lakebase Postgres
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"Neon connection pooling", or "schema migrations".
|
|
4
|
+
Guides and best practices for working with Lakebase Postgres on Neon:
|
|
5
|
+
connections, pooled vs direct, schema migrations, branching, autoscaling,
|
|
6
|
+
scale-to-zero, instant restore, read replicas, IP allow lists, logical
|
|
7
|
+
replication, and Lakebase Search. Use when the work is an existing
|
|
8
|
+
DATABASE_URL, SQL, schema, inspect, or search. New backends, Auth, files,
|
|
9
|
+
Functions, and LLM calls go to the parent `neon` skill. Also use for
|
|
10
|
+
"@neondatabase/serverless", "@neondatabase/neon-js", "neon inspect db",
|
|
11
|
+
"semantic search", "vector search", "full-text search", "BM25", or
|
|
12
|
+
"hybrid search".
|
|
14
13
|
metadata:
|
|
15
14
|
parent: neon
|
|
16
15
|
source: https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres
|
|
@@ -21,7 +20,7 @@ metadata:
|
|
|
21
20
|
If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
|
|
22
21
|
|
|
23
22
|
```bash
|
|
24
|
-
|
|
23
|
+
neon skills -s neon -y
|
|
25
24
|
```
|
|
26
25
|
|
|
27
26
|
# Lakebase Postgres
|
|
@@ -30,15 +29,21 @@ Lakebase Postgres is the database at the core of Neon. It runs on the lakebase a
|
|
|
30
29
|
|
|
31
30
|
It is the same database whether you reach it through Neon or through Databricks; this skill covers the Neon access path.
|
|
32
31
|
|
|
32
|
+
Login, users, sessions, and `@neondatabase/auth` belong in `neon-auth`.
|
|
33
|
+
|
|
33
34
|
## Setup Flow
|
|
34
35
|
|
|
35
36
|
### 1. Select the organization and project
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
If a `DATABASE_URL` is already supplied (prompt, environment, or repo) or a `.neon` file points at a project, use it. Do not list organizations or create a second project for schema work.
|
|
39
|
+
|
|
40
|
+
Otherwise use the CLI (default) or MCP server to list organizations and projects. Let the user select an existing project or create a new one.
|
|
38
41
|
|
|
39
42
|
### 2. Get the connection string
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
If a `DATABASE_URL` is already supplied, use it. Do not fetch another through the CLI or MCP.
|
|
45
|
+
|
|
46
|
+
Otherwise use the CLI (default), `neon env pull`, or the MCP server to get the connection string. Store it in `.env` as `DATABASE_URL`. Read the file first before modifying it, to avoid overwriting existing values.
|
|
42
47
|
|
|
43
48
|
#### When to use pooled vs direct connections
|
|
44
49
|
|
|
@@ -54,11 +59,10 @@ Use the CLI (default), `neon env pull`, or the MCP server to get the connection
|
|
|
54
59
|
|
|
55
60
|
### 3. Pick the connection method and driver
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
Preserve the existing ORM and driver. For new TypeScript schema work with no established choice, Drizzle is a suggestion: https://neon.com/docs/guides/drizzle.md. Refer to the connection methods guide to pick the correct driver based on how the runtime treats your code: https://neon.com/docs/connect/choose-connection.md.
|
|
58
63
|
|
|
59
|
-
|
|
64
|
+
Driver notes:
|
|
60
65
|
|
|
61
|
-
- Drizzle as ORM (see https://neon.com/docs/guides/drizzle.md)
|
|
62
66
|
- On Vercel, use `node-postgres` (`npm install pg`) with Vercel Fluid compute and `import { attachDatabasePool } from "@vercel/functions";`
|
|
63
67
|
- On Cloudflare, use `node-postgres` with Cloudflare Hyperdrive
|
|
64
68
|
- On Neon Functions, use `node-postgres`, as the functions are long-running and reuse the pool across requests.
|
|
@@ -85,7 +89,7 @@ Link: https://neon.com/docs/introduction/branching.md
|
|
|
85
89
|
For detailed branch creation workflows (normal vs schema-only branches, reset-from-parent, CLI/MCP selection), use the `neon-postgres-branches` skill. If it isn't installed, fetch it from https://neon.com/docs/ai/skills/neon-postgres-branches/SKILL.md or install it with:
|
|
86
90
|
|
|
87
91
|
```bash
|
|
88
|
-
|
|
92
|
+
neon skills -s neon-postgres-branches -y
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
## Migrations
|
|
@@ -94,6 +98,90 @@ Test a migration on a branch of production, against production-like data, before
|
|
|
94
98
|
|
|
95
99
|
Use a **direct (non-pooled)** connection string when you run the migration, not a pooled one. `neon connection-string` returns the direct string by default; make sure the hostname does not include the `-pooler` suffix.
|
|
96
100
|
|
|
101
|
+
## Troubleshooting and Neon-Specific Performance
|
|
102
|
+
|
|
103
|
+
Use Neon's predefined, read-only diagnostics before writing catalog queries by hand. The Neon CLI `neon inspect db` subcommands and the Neon MCP server's `inspect_database` tool run the same checks.
|
|
104
|
+
|
|
105
|
+
This section covers Neon-specific diagnostic tools, compute cache behavior, and platform signals. When the evidence points to generic Postgres work such as rewriting a query, choosing an index, changing a schema, or interpreting plan nodes, load the [`postgres-best-practices`](https://github.com/neondatabase/postgres-skills/tree/main/skills/postgres-best-practices) skill and carry the diagnostic evidence into that workflow.
|
|
106
|
+
|
|
107
|
+
Docs:
|
|
108
|
+
|
|
109
|
+
- CLI: https://neon.com/docs/cli/inspect.md
|
|
110
|
+
- Query performance: https://neon.com/docs/postgresql/query-performance.md
|
|
111
|
+
- `pg_stat_statements`: https://neon.com/docs/extensions/pg_stat_statements.md
|
|
112
|
+
- Neon Local File Cache: https://neon.com/docs/extensions/neon.md
|
|
113
|
+
|
|
114
|
+
### Choose CLI or MCP
|
|
115
|
+
|
|
116
|
+
Prefer the Neon CLI when terminal access and authentication are available:
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
neon inspect db <check>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The CLI resolves the project and branch from the current Neon context. Use `--project-id`, `--branch`, and `--database-name` to override it. Omit `--database-name` to inspect every database on the branch. Use `--db-url` only when inspecting a Postgres database directly instead of resolving it through the Neon API.
|
|
123
|
+
|
|
124
|
+
When using Neon MCP, call `inspect_database` with `projectId` and one `check`. Pass `branchId`, `databaseName`, or `computeId` only when needed. Omit `databaseName` to inspect all databases on the branch. Increase `limit` only when the result says it was truncated.
|
|
125
|
+
|
|
126
|
+
### Pick the Diagnostic
|
|
127
|
+
|
|
128
|
+
| Symptom or question | Checks |
|
|
129
|
+
| ---------------------------------------------- | ------------------------------------ |
|
|
130
|
+
| Which relations consume storage? | `table-sizes`, `index-sizes` |
|
|
131
|
+
| Is an index unused or a table scanned heavily? | `unused-indexes`, `seq-scans` |
|
|
132
|
+
| What has run for 5+ minutes or holds locks? | `long-running-queries`, `locks` |
|
|
133
|
+
| Which queries consume the most total time? | `outliers` |
|
|
134
|
+
| Which queries run most often? | `calls` |
|
|
135
|
+
| Does the active data fit in compute cache? | `lfc-hit-rate`, `working-set` |
|
|
136
|
+
| Is autovacuum behind or is space wasted? | `vacuum-stats`, `bloat` |
|
|
137
|
+
| Is logical replication healthy? | `replication-slots`, `subscriptions` |
|
|
138
|
+
|
|
139
|
+
Do not confuse these checks:
|
|
140
|
+
|
|
141
|
+
- `long-running-queries` reports statements running **right now** for more than five minutes.
|
|
142
|
+
- `outliers` ranks the top queries by cumulative execution time since statistics were reset. It does not rank by mean latency.
|
|
143
|
+
- `calls` ranks by execution count over the same statistics history.
|
|
144
|
+
|
|
145
|
+
`outliers` and `calls` require `pg_stat_statements`. `lfc-hit-rate` and `working-set` require the `neon` extension. If a check reports a missing extension, ask before running the suggested `CREATE EXTENSION` statement because installing an extension modifies the database.
|
|
146
|
+
|
|
147
|
+
### Interpret Results Safely
|
|
148
|
+
|
|
149
|
+
- Treat `unused-indexes` as a candidate list, not permission to drop indexes. Confirm the observation window, constraints, and workload before removal.
|
|
150
|
+
- A sequential scan can be correct for a small table or a query reading much of a table. Check table size, selectivity, and the query plan before adding an index.
|
|
151
|
+
- `bloat` is a statistical estimate. Confirm the impact and plan locks or maintenance before `VACUUM FULL`, `REINDEX`, or similar remediation.
|
|
152
|
+
- Cache and Postgres statistics reset when compute restarts, including scale-to-zero suspension. Run a representative workload before interpreting fresh `lfc-hit-rate`, `working-set`, `vacuum-stats`, or `pg_stat_statements` results.
|
|
153
|
+
- Compute-wide checks (`lfc-hit-rate`, `working-set`, and `replication-slots`) run once even when inspecting every database.
|
|
154
|
+
- One failing database can fail an all-databases inspection; retry the relevant check with an explicit `databaseName` to isolate it.
|
|
155
|
+
|
|
156
|
+
### Inspect Neon Cache Behavior Per Query
|
|
157
|
+
|
|
158
|
+
Standard `EXPLAIN (ANALYZE, BUFFERS)` reports Postgres shared-buffer activity, but it does not show Neon's Local File Cache (LFC) or page prefetching. For a safe read-only query, add Neon's `FILECACHE` and `PREFETCH` options:
|
|
159
|
+
|
|
160
|
+
```sql
|
|
161
|
+
EXPLAIN (ANALYZE, BUFFERS, PREFETCH, FILECACHE)
|
|
162
|
+
SELECT ...;
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
- `File cache: hits` counts pages found in the compute's LFC.
|
|
166
|
+
- `File cache: misses` counts pages not found in the LFC and fetched from database storage.
|
|
167
|
+
- `Prefetch: hits`, `misses`, `expired`, and `duplicates` show how effectively Neon fetched pages before the executor requested them.
|
|
168
|
+
|
|
169
|
+
`FILECACHE` and `PREFETCH` provide metrics for this query and do not require the `neon` extension. By contrast, `neon inspect db lfc-hit-rate` and `working-set` provide compute-wide statistics and do require the extension.
|
|
170
|
+
|
|
171
|
+
The MCP `explain_sql_statement` tool can produce a standard plan but does not expose `FILECACHE` or `PREFETCH` options. To collect those Neon-specific metrics through MCP, use `run_sql` with the explicit, read-only `EXPLAIN` statement above.
|
|
172
|
+
|
|
173
|
+
Because `ANALYZE` executes the statement, use it only when execution is safe; do not run it autonomously for mutating SQL. Compare cold- and warm-cache runs carefully because the first execution can populate the cache and materially change later results.
|
|
174
|
+
|
|
175
|
+
### Performance Workflow
|
|
176
|
+
|
|
177
|
+
1. Reproduce the symptom and note its time window.
|
|
178
|
+
2. Run the smallest relevant `inspect` checks from the table above.
|
|
179
|
+
3. Identify a specific query before changing schema or compute. Use MCP `explain_sql_statement` for a standard plan, or the Neon-specific `EXPLAIN` above when LFC or prefetch behavior matters.
|
|
180
|
+
4. If the bottleneck is query shape, indexing, schema, locking, or vacuum behavior, load `postgres-best-practices` and carry forward the inspection results and query plan. Keep Neon compute, cache, connection, and platform decisions in this skill.
|
|
181
|
+
5. Re-run the same check and workload to verify the change.
|
|
182
|
+
|
|
183
|
+
Use MCP `list_slow_queries` instead of `inspect_database` when the user specifically needs queries ranked by average execution time with a custom threshold and limit. Outside the explicit `EXPLAIN` case above, use `run_sql` only for read-only diagnostic SQL when the predefined checks do not answer the question.
|
|
184
|
+
|
|
97
185
|
## Autoscaling
|
|
98
186
|
|
|
99
187
|
Use this when the user needs compute to scale automatically with workload and wants guidance on CU sizing and runtime behavior.
|
|
@@ -165,6 +253,20 @@ Key points:
|
|
|
165
253
|
|
|
166
254
|
Link: https://neon.com/docs/guides/logical-replication-guide.md
|
|
167
255
|
|
|
256
|
+
## Lakebase Search
|
|
257
|
+
|
|
258
|
+
Use Lakebase Search for semantic, full-text, and hybrid search:
|
|
259
|
+
|
|
260
|
+
- For semantic search, read [Vector search](references/vector-search.md).
|
|
261
|
+
- For full-text search with BM25 ranking, read [Full-text search](references/full-text-search.md).
|
|
262
|
+
- For combining semantic and lexical results, read [Hybrid search](references/hybrid-search.md).
|
|
263
|
+
|
|
264
|
+
Links:
|
|
265
|
+
|
|
266
|
+
- [Get started with Lakebase Search](https://neon.com/docs/ai/lakebase-search-get-started)
|
|
267
|
+
- [`lakebase_vector` reference](https://neon.com/docs/extensions/lakebase-vector)
|
|
268
|
+
- [`lakebase_text` reference](https://neon.com/docs/extensions/lakebase-text)
|
|
269
|
+
|
|
168
270
|
## Gotchas
|
|
169
271
|
|
|
170
272
|
### Pooled vs direct connections: use the direct URL for migrations, dumps, and replication
|