@neon/skills 1.2.0 → 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.
@@ -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 `preview.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.
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
@@ -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) (self-hostable, runs alongside your app) is a good fit, and it covers both common shapes. **Better Auth is evolving quickly** — the MCP plugin is moving out of `better-auth/plugins` into its own `@better-auth/mcp` package (built on the OAuth Provider plugin), which renames `withMcpAuth` → `requireMcpAuth` and `createMcpAuthClient` → `createMcpResourceClient`. Verify the current package and import paths against the [Better Auth MCP docs](https://better-auth.com/docs/plugins/mcp) before wiring it up.
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
 
@@ -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
- npx skills add neondatabase/agent-skills --skill neon
25
+ neon skills -s neon -y
26
26
  ```
27
27
 
28
28
  # Neon Object Storage
29
29
 
30
- This is a public beta feature, currently available in `us-east-2` and `eu-central-1`.
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 a public beta feature currently available in `us-east-2` and `eu-central-1`. Confirm the user's Neon project is in one of these regions before proceeding.
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 `preview.buckets`, keyed by bucket name:
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
- preview: {
75
- buckets: {
76
- images: {}, // private by default
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 `preview.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:
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 `preview.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:
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,18 +1,15 @@
1
1
  ---
2
2
  name: neon-postgres
3
3
  description: >-
4
- Guides and best practices for working with Lakebase Postgres, the database
5
- behind Neon. Covers setup, connection methods and drivers, pooled vs direct
6
- connections, branching, schema migrations, autoscaling, scale-to-zero, instant
7
- restore, read replicas, connection pooling, IP allow lists, and logical
8
- replication. Also covers Lakebase Search: semantic vector search, full-text
9
- search with BM25 ranking, and hybrid search.
10
- Use when users ask about "Lakebase Postgres", "Neon setup", "connect to Neon",
11
- "Neon project", "DATABASE_URL", "serverless Postgres", "Neon CLI", "neon", "Neon MCP",
12
- "Neon Auth", "@neondatabase/serverless", "@neondatabase/neon-js",
13
- "scale to zero", "Neon autoscaling", "Neon read replica",
14
- "Neon connection pooling", "schema migrations", "semantic search", "vector
15
- search", "full-text search", "BM25", or "hybrid search".
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".
16
13
  metadata:
17
14
  parent: neon
18
15
  source: https://github.com/neondatabase/agent-skills/tree/main/skills/neon-postgres
@@ -23,7 +20,7 @@ metadata:
23
20
  If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
24
21
 
25
22
  ```bash
26
- npx skills add neondatabase/agent-skills --skill neon
23
+ neon skills -s neon -y
27
24
  ```
28
25
 
29
26
  # Lakebase Postgres
@@ -32,15 +29,21 @@ Lakebase Postgres is the database at the core of Neon. It runs on the lakebase a
32
29
 
33
30
  It is the same database whether you reach it through Neon or through Databricks; this skill covers the Neon access path.
34
31
 
32
+ Login, users, sessions, and `@neondatabase/auth` belong in `neon-auth`.
33
+
35
34
  ## Setup Flow
36
35
 
37
36
  ### 1. Select the organization and project
38
37
 
39
- Use the CLI (default) or MCP server to list organizations and projects. Let the user select an existing project or create a new one. Check the `.neon` file for an existing linked project or branch.
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.
40
41
 
41
42
  ### 2. Get the connection string
42
43
 
43
- 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.
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.
44
47
 
45
48
  #### When to use pooled vs direct connections
46
49
 
@@ -56,11 +59,10 @@ Use the CLI (default), `neon env pull`, or the MCP server to get the connection
56
59
 
57
60
  ### 3. Pick the connection method and driver
58
61
 
59
- Always pair Neon with an ORM such as **Drizzle** for easy schema management and migrations. 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.
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.
60
63
 
61
- Recommendations:
64
+ Driver notes:
62
65
 
63
- - Drizzle as ORM (see https://neon.com/docs/guides/drizzle.md)
64
66
  - On Vercel, use `node-postgres` (`npm install pg`) with Vercel Fluid compute and `import { attachDatabasePool } from "@vercel/functions";`
65
67
  - On Cloudflare, use `node-postgres` with Cloudflare Hyperdrive
66
68
  - On Neon Functions, use `node-postgres`, as the functions are long-running and reuse the pool across requests.
@@ -87,7 +89,7 @@ Link: https://neon.com/docs/introduction/branching.md
87
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:
88
90
 
89
91
  ```bash
90
- npx skills add neondatabase/agent-skills --skill neon-postgres-branches
92
+ neon skills -s neon-postgres-branches -y
91
93
  ```
92
94
 
93
95
  ## Migrations
@@ -96,6 +98,90 @@ Test a migration on a branch of production, against production-like data, before
96
98
 
97
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.
98
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
+
99
185
  ## Autoscaling
100
186
 
101
187
  Use this when the user needs compute to scale automatically with workload and wants guidance on CU sizing and runtime behavior.
@@ -19,7 +19,7 @@ metadata:
19
19
  If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
20
20
 
21
21
  ```bash
22
- npx skills add neondatabase/agent-skills --skill neon
22
+ neon skills -s neon -y
23
23
  ```
24
24
 
25
25
  # Lakebase Postgres Branching
@@ -19,7 +19,7 @@ metadata:
19
19
  If the `neon` skill is not installed, fetch it from https://neon.com/docs/ai/skills/neon/SKILL.md or install it with:
20
20
 
21
21
  ```bash
22
- npx skills add neondatabase/agent-skills --skill neon
22
+ neon skills -s neon -y
23
23
  ```
24
24
 
25
25
  # Postgres Egress Optimizer