neon 4.3.0 → 4.3.1

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 CHANGED
@@ -736,7 +736,7 @@ $ neon mcp -y
736
736
  # OAuth: no API key minted. The agent prompts for Neon sign-in on first use.
737
737
  $ neon mcp --oauth
738
738
 
739
- # Project-level config. A minted key is still account-wide.
739
+ # Project-level config. A minted key is still account-wide unless a project is pinned.
740
740
  $ neon mcp --project
741
741
 
742
742
  $ neon mcp --agent cursor --agent claude-code
@@ -744,7 +744,7 @@ $ neon mcp --agent cursor --agent claude-code
744
744
  # Hide write tools. Does not change the minted key.
745
745
  $ neon mcp --read-only
746
746
 
747
- # Pin MCP tools to one project. Does not change the minted key.
747
+ # Pin MCP tools to one project. A newly minted API key is limited to that project.
748
748
  $ neon mcp --project-id <project-id>
749
749
 
750
750
  # Limit which tool categories are visible.
@@ -753,11 +753,11 @@ $ neon mcp --category querying --category schema
753
753
 
754
754
  On a TTY the command asks for config location (global is the default), then agents, then API key vs OAuth, then a summary to confirm before it writes. Detected agents start selected: globally installed agents or project-folder markers such as `.cursor` when the install is project.
755
755
 
756
- `-y` skips those questions. `--project`, `--oauth` and `--agent` skip the question they answer and still apply with `-y`. `--read-only` and `--category` are flags only and are never prompted. A linked project-folder install asks whether to pin MCP tools to that `.neon` project (`?projectId=`). An unlinked project folder does not ask. Global installs never add that param unless you pass `--project-id`. Without a TTY, pass `-y` to mint into every detected agent, `--agent` to name the agents or `--oauth` to write the URL only.
756
+ `-y` skips those questions. `--project`, `--oauth` and `--agent` skip the question they answer and still apply with `-y`. `--read-only` and `--category` are flags only and are never prompted. A linked project-folder install asks whether to pin MCP tools to that `.neon` project (`?projectId=`). If you pin and selected API-key auth, the minted key is limited to that project too. An unlinked project folder does not ask. Global installs never add that param unless you pass `--project-id`. `-y` does not infer a project from `.neon`. Without a TTY, pass `-y` to mint into every detected agent, `--agent` to name the agents or `--oauth` to write the URL only.
757
757
 
758
758
  `--agent` names: `antigravity`, `cline`, `cline-cli`, `claude-code`, `codex`, `cursor`, `gemini-cli`, `goose`, `github-copilot-cli`, `grok-build`, `mcporter`, `opencode`, `vscode`, `windsurf`, `zed`. Project installs drop `antigravity`, `cline`, `cline-cli`, `goose` and `windsurf`. `claude-desktop` is a known name that is then skipped.
759
759
 
760
- The default mints an account-wide API key (or reuses the Bearer already configured for Neon at `https://mcp.neon.tech/mcp`) and writes it into each selected agent's config. That key reaches everything the account can, in every organization. Revoke it with `neon api-keys revoke <id>`. `--oauth` writes the URL with no `Authorization` header; the agent signs in on first use. `--project` writes into the project config (`.cursor/mcp.json` and similar). `--read-only` adds `?readonly=true`. `--project-id` adds `?projectId=`. `--category` adds `?category=` (repeatable or comma-separated: `projects`, `branches`, `schema`, `querying`, `neon_auth`, `data_api`, `observability`, `docs`). Those query params restrict which MCP tools the server exposes; they do not change what the minted key can do.
760
+ The default mints an account-wide API key (or reuses the Bearer already configured for Neon at `https://mcp.neon.tech/mcp`) and writes it into each selected agent's config. That key reaches everything the account can, in every organization. Revoke it with `neon api-keys revoke <id>`. `--oauth` writes the URL with no `Authorization` header; the agent signs in on first use. `--project` writes into the project config (`.cursor/mcp.json` and similar). `--read-only` adds `?readonly=true`. `--project-id` adds `?projectId=` and, when a key is minted, limits that key to the named project. Accepting the linked-project pin does the same. Revoke a project-scoped key with `neon api-keys revoke <id> --org-id <org>`. A reused Bearer keeps the scope it already has. `--category` adds `?category=` (repeatable or comma-separated: `projects`, `branches`, `schema`, `querying`, `neon_auth`, `data_api`, `observability`, `docs`). `--read-only` and `--category` restrict which MCP tools the server exposes; they do not change what the minted key can do.
761
761
 
762
762
  ## Install Neon agent skills (`skills`)
763
763
 
@@ -265,16 +265,16 @@ const revoke = async (props) => {
265
265
  * scoped key — the endpoint that accepts `project_id` is org-only — so that case fails here
266
266
  * with the reason, rather than as a 404 from a URL the user never typed.
267
267
  */
268
- const orgIdForProject = async (client, projectId) => {
268
+ const orgIdForProject = async (client, projectId, usage = "api-keys") => {
269
269
  let orgId;
270
270
  try {
271
271
  const { data: { project } } = await client.getProject(projectId);
272
272
  orgId = project.org_id;
273
273
  } catch (err) {
274
- if (isNeonApiError(err) && err.status === 404) throw new Error(projectId.startsWith("org-") ? `Project ${projectId} not found. That looks like an organization id. Pass it as --org-id instead.` : `Project ${projectId} not found. Check the id with \`neon projects list\`.`);
274
+ if (isNeonApiError(err) && err.status === 404) throw new Error(projectId.startsWith("org-") ? usage === "mcp" ? `Project ${projectId} not found. That looks like an organization id. neon mcp takes a project id on --project-id.` : `Project ${projectId} not found. That looks like an organization id. Pass it as --org-id instead.` : `Project ${projectId} not found. Check the id with \`neon projects list\`.`);
275
275
  throw err;
276
276
  }
277
- if (!orgId) throw new Error(`Project ${projectId} does not belong to an organization, so it cannot have a project-scoped API key. Omit --project-id to create an account key.`);
277
+ if (!orgId) throw new Error(usage === "mcp" ? `Project ${projectId} does not belong to an organization, so it cannot have a project-scoped API key. Pass --oauth to pin tools without minting, or omit --project-id to mint an account-wide key.` : `Project ${projectId} does not belong to an organization, so it cannot have a project-scoped API key. Omit --project-id to create an account key.`);
278
278
  return orgId;
279
279
  };
280
280
  //#endregion
@@ -5,7 +5,7 @@ import { getCliName } from "../utils/cli_name.js";
5
5
  import { writer } from "../writer.js";
6
6
  import { noPassthrough, single } from "../utils/flags.js";
7
7
  import { existingNeonApiKey, installNeonMcpServer, neonMcpUrl, parseMcpCategories, trackedProjectMcpConfig } from "../mcp/install.js";
8
- import { mintMcpApiKey, withdrawMintedKey } from "../mcp/mint.js";
8
+ import { mintMcpApiKey, mintedKeyRevokeCommand, withdrawMintedKey } from "../mcp/mint.js";
9
9
  import { canPickAgentsInteractively } from "../utils/agent_picker.js";
10
10
  import { resolveInstallTargets } from "../mcp/targets.js";
11
11
  import { confirmMcpInstall } from "../mcp/wizard.js";
@@ -28,7 +28,7 @@ const builder = (argv) => argv.usage("$0 mcp [options]").options({
28
28
  project: {
29
29
  type: "boolean",
30
30
  default: false,
31
- describe: "Write project-level MCP config. Skips the config-location question. Does not change the minted key"
31
+ describe: "Write project-level MCP config. Skips the config-location question. A linked project-folder install may still pin a project and scope a newly minted key"
32
32
  },
33
33
  yes: {
34
34
  alias: "y",
@@ -59,7 +59,7 @@ const builder = (argv) => argv.usage("$0 mcp [options]").options({
59
59
  },
60
60
  "project-id": {
61
61
  type: "string",
62
- describe: "Pin MCP tools to one Neon project (?projectId=). Does not change the minted key. Interactive asks only for a linked project-folder install",
62
+ describe: "Pin MCP tools to one Neon project (?projectId=). A newly minted API key is limited to that project. A linked project-folder install asks the same when you pick API-key auth",
63
63
  coerce: single("project-id")
64
64
  },
65
65
  category: {
@@ -131,7 +131,8 @@ const handler = async (props) => {
131
131
  skipped,
132
132
  auth: plan.auth,
133
133
  reuse: existing !== void 0,
134
- url
134
+ url,
135
+ mintProjectId: plan.urlProjectId
135
136
  })) {
136
137
  log.info("Aborted. Nothing was written.");
137
138
  return;
@@ -146,13 +147,18 @@ const handler = async (props) => {
146
147
  apiKey: existing
147
148
  };
148
149
  log.info("Reusing the API key already configured for the Neon MCP server.");
150
+ if (plan.urlProjectId) log.warning("That key keeps its existing scope. Remove the Neon MCP entry to mint a project-scoped key, or pass --oauth to pin tools without a key.");
149
151
  } else {
150
- minted = await mintMcpApiKey({ apiClient: props.apiClient });
152
+ minted = await mintMcpApiKey({
153
+ apiClient: props.apiClient,
154
+ projectId: plan.urlProjectId
155
+ });
151
156
  auth = {
152
157
  kind: "api-key",
153
158
  apiKey: minted.key
154
159
  };
155
- log.warning("This key reaches everything your account can, in every organization.");
160
+ if (minted.projectId) log.info("Limited to %s: it cannot create projects, mint API keys, or read any other project. It can still change and delete everything inside that project.", minted.projectId);
161
+ else log.warning("This key reaches everything your account can, in every organization.");
156
162
  }
157
163
  const rows = [];
158
164
  let successes = 0;
@@ -189,7 +195,7 @@ const handler = async (props) => {
189
195
  if (successes === 0) {
190
196
  if (minted && props.apiClient) {
191
197
  const withdrawn = await withdrawMintedKey(props.apiClient, minted);
192
- throw new Error(withdrawn ? "Failed to write Neon MCP config to any agent. The minted API key has been revoked." : `Failed to write Neon MCP config to any agent. The minted API key could NOT be revoked. Remove it with \`${getCliName()} api-keys revoke ${minted.id}\`.`);
198
+ throw new Error(withdrawn ? "Failed to write Neon MCP config to any agent. The minted API key has been revoked." : `Failed to write Neon MCP config to any agent. The minted API key could NOT be revoked. Remove it with \`${mintedKeyRevokeCommand(minted)}\`.`);
193
199
  }
194
200
  throw new Error("Failed to write Neon MCP config to any agent.");
195
201
  }
@@ -204,7 +210,7 @@ const handler = async (props) => {
204
210
  title: "MCP"
205
211
  });
206
212
  out.end();
207
- if (minted) log.info("Minted API key %s (id %d, account). Revoke with: %s", minted.name, minted.id, `${getCliName()} api-keys revoke ${minted.id}`);
213
+ if (minted) log.info("Minted API key %s (id %d, %s). Revoke with: %s", minted.name, minted.id, minted.projectId ? "project" : "account", mintedKeyRevokeCommand(minted));
208
214
  if (plan.auth === "oauth") log.info("The agent will prompt for Neon sign-in on first use.");
209
215
  if (failedAgents.length > 0) throw new Error(`Failed to write Neon MCP config for: ${failedAgents.join(", ")}.`);
210
216
  };
package/dist/mcp/mint.js CHANGED
@@ -1,24 +1,32 @@
1
1
  import { log } from "../log.js";
2
2
  import { isNeonApiError } from "../api.js";
3
3
  import { getCliName } from "../utils/cli_name.js";
4
+ import { orgIdForProject } from "../commands/api_keys.js";
4
5
  import { mintedKeyName } from "../profile_keys.js";
5
6
  //#region src/mcp/mint.ts
6
7
  const cannotMintMessage = "This CLI credential cannot mint API keys. Organization and project-scoped keys cannot create other keys. Sign in with `neon auth` or pass a personal API key.";
7
- const withdraw = async (client, keyId) => {
8
+ function mintedKeyRevokeCommand(key) {
9
+ return key.orgId ? `${getCliName()} api-keys revoke ${key.id} --org-id ${key.orgId}` : `${getCliName()} api-keys revoke ${key.id}`;
10
+ }
11
+ const withdraw = async (client, keyId, orgId) => {
8
12
  if (!Number.isSafeInteger(keyId) || keyId === void 0 || keyId <= 0) return false;
9
13
  try {
10
- const { data } = await client.revokeApiKey(keyId);
14
+ const { data } = orgId ? await client.revokeOrgApiKey(orgId, keyId) : await client.revokeApiKey(keyId);
11
15
  return data.revoked === true && data.id === keyId;
12
16
  } catch (err) {
13
17
  log.error("Failed to revoke API key %d: %s", keyId, err instanceof Error ? err.message : String(err));
14
18
  return false;
15
19
  }
16
20
  };
17
- const assertUsable = async (client, data, fallbackName) => {
18
- const problem = typeof data.key !== "string" || data.key.trim() === "" ? "Neon returned no key." : data.project_id !== void 0 ? `Neon returned a key scoped to ${data.project_id} rather than the whole account.` : !Number.isSafeInteger(data.id) ? "Neon returned no key id." : null;
21
+ const assertUsable = async (client, data, fallbackName, scope) => {
22
+ const wanted = scope.projectId;
23
+ const problem = typeof data.key !== "string" || data.key.trim() === "" ? "Neon returned no key." : data.project_id !== wanted ? wanted === void 0 ? `Neon returned a key scoped to ${data.project_id} rather than the whole account.` : `Neon returned a key scoped to ${data.project_id ?? "nothing"} rather than ${wanted}.` : !Number.isSafeInteger(data.id) ? "Neon returned no key id." : null;
19
24
  if (problem) {
20
- const withdrawn = await withdraw(client, data.id);
21
- throw new Error(`${problem} ${withdrawn ? "The key has been revoked; nothing was issued." : `The key could NOT be revoked and may still be live${data.id === void 0 ? "" : `. Remove it with \`${getCliName()} api-keys revoke ${data.id}\``}.`}`);
25
+ const withdrawn = await withdraw(client, data.id, scope.orgId);
26
+ throw new Error(`${problem} ${withdrawn ? "The key has been revoked; nothing was issued." : `The key could NOT be revoked and may still be live${data.id === void 0 ? "" : `. Remove it with \`${mintedKeyRevokeCommand({
27
+ id: data.id,
28
+ orgId: scope.orgId
29
+ })}\``}.`}`);
22
30
  }
23
31
  const id = data.id;
24
32
  const key = data.key;
@@ -26,21 +34,37 @@ const assertUsable = async (client, data, fallbackName) => {
26
34
  return {
27
35
  id,
28
36
  name: data.name ?? fallbackName,
29
- key
37
+ key,
38
+ orgId: scope.orgId,
39
+ projectId: scope.projectId
30
40
  };
31
41
  };
32
- async function mintMcpApiKey(options) {
33
- const name = mintedKeyName("mcp");
42
+ const createAndAssert = async (client, create, name, scope) => {
34
43
  try {
35
- const { data } = await options.apiClient.createApiKey({ key_name: name });
36
- return assertUsable(options.apiClient, data, name);
44
+ const { data } = await create();
45
+ return assertUsable(client, data, name, scope);
37
46
  } catch (err) {
38
47
  if (isNeonApiError(err) && (err.status === 403 || err.status === 404)) throw new Error(cannotMintMessage);
39
48
  throw err;
40
49
  }
50
+ };
51
+ async function mintMcpApiKey(options) {
52
+ const name = mintedKeyName("mcp");
53
+ const projectId = options.projectId;
54
+ if (projectId !== void 0) {
55
+ const orgId = await orgIdForProject(options.apiClient, projectId, "mcp");
56
+ return createAndAssert(options.apiClient, () => options.apiClient.createOrgApiKey(orgId, {
57
+ key_name: name,
58
+ project_id: projectId
59
+ }), name, {
60
+ orgId,
61
+ projectId
62
+ });
63
+ }
64
+ return createAndAssert(options.apiClient, () => options.apiClient.createApiKey({ key_name: name }), name, {});
41
65
  }
42
66
  async function withdrawMintedKey(apiClient, key) {
43
- return withdraw(apiClient, key.id);
67
+ return withdraw(apiClient, key.id, key.orgId);
44
68
  }
45
69
  //#endregion
46
- export { mintMcpApiKey, withdrawMintedKey };
70
+ export { mintMcpApiKey, mintedKeyRevokeCommand, withdrawMintedKey };
package/dist/mcp/plan.js CHANGED
@@ -28,7 +28,7 @@ async function resolveMcpPlan(options) {
28
28
  const auth = options.oauth ? "oauth" : prompt ? await (options.pickAuth ?? pickMcpAuth)() : "api-key";
29
29
  let urlProjectId = options.projectId;
30
30
  if (urlProjectId === void 0 && prompt && scope === "project" && options.linkedProjectId) {
31
- if (await (options.pickProjectPin ?? pickMcpProjectPin)(options.linkedProjectId)) urlProjectId = options.linkedProjectId;
31
+ if (await (options.pickProjectPin ?? pickMcpProjectPin)(options.linkedProjectId, auth === "api-key")) urlProjectId = options.linkedProjectId;
32
32
  }
33
33
  return {
34
34
  scope,
@@ -51,20 +51,20 @@ const pickMcpAuth = async () => {
51
51
  if (auth !== "api-key" && auth !== "oauth") throw new Error("Aborted.");
52
52
  return auth;
53
53
  };
54
- const pickMcpProjectPin = async (linkedProjectId) => {
54
+ const pickMcpProjectPin = async (linkedProjectId, willMintKey = false) => {
55
55
  if (!canPickAgentsInteractively()) return false;
56
56
  const { pin } = await prompts({
57
57
  onState: restoreCursorOnAbort,
58
58
  type: "confirm",
59
59
  name: "pin",
60
- message: `Pin MCP tools to the linked project ${linkedProjectId}?`,
60
+ message: willMintKey ? `Pin MCP tools to the linked project ${linkedProjectId}? A newly minted API key would be limited to that project.` : `Pin MCP tools to the linked project ${linkedProjectId}?`,
61
61
  initial: true
62
62
  });
63
63
  return pin === true;
64
64
  };
65
65
  const mcpInstallSummary = (options) => {
66
66
  const agents = options.install.map(getAgentDisplayName).join(", ");
67
- const auth = options.auth === "oauth" ? "OAuth, agent signs in on first use" : options.reuse ? "reuse the API key already in agent config" : "mint an account-wide API key that reaches every organization";
67
+ const auth = options.auth === "oauth" ? "OAuth, agent signs in on first use" : options.reuse ? "reuse the API key already in agent config" : options.mintProjectId ? `mint an API key limited to ${options.mintProjectId}` : "mint an account-wide API key that reaches every organization";
68
68
  const rows = [
69
69
  ["Config", options.scope === "project" ? "this directory" : "user-level"],
70
70
  ["Agents", agents],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neon",
3
- "version": "4.3.0",
3
+ "version": "4.3.1",
4
4
  "description": "CLI tool for Neon, the cloud backend primitives built around Lakebase Postgres",
5
5
  "keywords": [
6
6
  "neon",
@@ -64,8 +64,8 @@
64
64
  "yargs": "17.7.2",
65
65
  "yoctocolors": "^2.1.2",
66
66
  "@neon/config": "1.0.2",
67
- "@neon/config-runtime": "1.0.2",
68
- "@neon/sdk": "2.2.0"
67
+ "@neon/sdk": "2.2.0",
68
+ "@neon/config-runtime": "1.0.2"
69
69
  },
70
70
  "optionalDependencies": {
71
71
  "@napi-rs/keyring": "1.3.0",