neon 8.11.0 → 8.11.2

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.
Files changed (106) hide show
  1. package/README.md +1 -1
  2. package/dist/_chunks/api-GbEaBZJ5.js +388 -0
  3. package/dist/_chunks/api_keys-CNnnugbQ.js +281 -0
  4. package/dist/_chunks/ask-DVwy0eUL.js +155 -0
  5. package/dist/_chunks/auth-CIUtXByB.js +495 -0
  6. package/dist/_chunks/bootstrap-wPZWa1sT.js +499 -0
  7. package/dist/_chunks/branches-BNa1xX1L.js +460 -0
  8. package/dist/_chunks/bucket-BCdryTkD.js +409 -0
  9. package/dist/_chunks/checkout-CXIOydqZ.js +348 -0
  10. package/dist/_chunks/claim-DqAvAvDm.js +473 -0
  11. package/dist/_chunks/config-BH_qRHiG.js +1113 -0
  12. package/dist/_chunks/connection_string-DB4awPzZ.js +154 -0
  13. package/dist/_chunks/credentials-BSjE9fRR.js +146 -0
  14. package/dist/_chunks/data_api-Djxj5ZQD.js +263 -0
  15. package/dist/_chunks/databases-Dok4wru7.js +84 -0
  16. package/dist/_chunks/deploy-D7B0Xfjg.js +33 -0
  17. package/dist/_chunks/dev-CSvxAecE.js +945 -0
  18. package/dist/_chunks/diff-DhxxbdQE.js +178 -0
  19. package/dist/_chunks/docs-CrVybkTP.js +197 -0
  20. package/dist/_chunks/env-5HS5qQGd.js +284 -0
  21. package/dist/_chunks/feedback-CMayyTa8.js +88 -0
  22. package/dist/_chunks/functions-Q0zuvtnk.js +464 -0
  23. package/dist/_chunks/git-H32TNt6M.js +356 -0
  24. package/dist/_chunks/init-BkA6RilG.js +111 -0
  25. package/dist/_chunks/inspect-g0wekylj.js +90 -0
  26. package/dist/_chunks/ip_allow-5lLFvIuE.js +106 -0
  27. package/dist/_chunks/link-BgtkOBws.js +936 -0
  28. package/dist/_chunks/logs-DWkpjzIH.js +291 -0
  29. package/dist/_chunks/mcp-Bo-7TKc7.js +253 -0
  30. package/dist/_chunks/neon_auth-CBs1_3qu.js +822 -0
  31. package/dist/_chunks/open-CX3BT3Tp.js +33 -0
  32. package/dist/_chunks/operations-D4I-AxVs.js +37 -0
  33. package/dist/_chunks/orgs-xGfANwHQ.js +52 -0
  34. package/dist/_chunks/plugins-DqD7BDO1.js +169 -0
  35. package/dist/_chunks/profile-yXOiKk9R.js +672 -0
  36. package/dist/_chunks/projects-BwI2Uo0z.js +439 -0
  37. package/dist/_chunks/psql-BM-doe8e.js +64 -0
  38. package/dist/_chunks/realtime-BRqIyGR-.js +79 -0
  39. package/dist/_chunks/roles-B4w3YT_7.js +79 -0
  40. package/dist/_chunks/set_context-DbrwoImy.js +38 -0
  41. package/dist/_chunks/skills-DyiBXKS3.js +255 -0
  42. package/dist/_chunks/snapshots-RJBzW8GM.js +338 -0
  43. package/dist/_chunks/status-DV8Z2kw3.js +44 -0
  44. package/dist/_chunks/triggers-BrRo1z4b.js +302 -0
  45. package/dist/_chunks/user-dlOGXbX9.js +60 -0
  46. package/dist/_chunks/vpc_endpoints-CNb0YfMo.js +105 -0
  47. package/dist/auth_recovery.js +1 -1
  48. package/dist/commands/api.js +1 -388
  49. package/dist/commands/api_keys.js +1 -281
  50. package/dist/commands/ask.js +1 -155
  51. package/dist/commands/auth.js +1 -495
  52. package/dist/commands/bootstrap.js +1 -499
  53. package/dist/commands/branches.js +1 -460
  54. package/dist/commands/bucket.js +1 -409
  55. package/dist/commands/checkout.js +1 -348
  56. package/dist/commands/claim.js +1 -473
  57. package/dist/commands/config.js +1 -1113
  58. package/dist/commands/connection_string.js +1 -154
  59. package/dist/commands/credentials.js +1 -146
  60. package/dist/commands/data_api.js +1 -263
  61. package/dist/commands/databases.js +1 -84
  62. package/dist/commands/deploy.js +1 -33
  63. package/dist/commands/dev.js +1 -945
  64. package/dist/commands/diff.js +1 -178
  65. package/dist/commands/docs.js +1 -197
  66. package/dist/commands/env.js +1 -284
  67. package/dist/commands/feedback.js +1 -88
  68. package/dist/commands/functions.js +1 -464
  69. package/dist/commands/functions_new.js +6 -6
  70. package/dist/commands/git.js +1 -356
  71. package/dist/commands/index.js +45 -45
  72. package/dist/commands/init.js +1 -111
  73. package/dist/commands/inspect.js +1 -90
  74. package/dist/commands/ip_allow.js +1 -106
  75. package/dist/commands/link.js +1 -936
  76. package/dist/commands/logs.js +1 -291
  77. package/dist/commands/mcp.js +1 -253
  78. package/dist/commands/neon_auth.js +1 -822
  79. package/dist/commands/open.js +1 -33
  80. package/dist/commands/operations.js +1 -37
  81. package/dist/commands/orgs.js +1 -52
  82. package/dist/commands/plugins.js +1 -169
  83. package/dist/commands/profile.js +1 -672
  84. package/dist/commands/projects.js +1 -439
  85. package/dist/commands/psql.js +1 -64
  86. package/dist/commands/realtime.js +1 -79
  87. package/dist/commands/roles.js +1 -79
  88. package/dist/commands/set_context.js +1 -38
  89. package/dist/commands/skills.js +1 -255
  90. package/dist/commands/snapshots.js +1 -338
  91. package/dist/commands/status.js +1 -44
  92. package/dist/commands/subscribe.js +1 -1
  93. package/dist/commands/triggers.js +1 -302
  94. package/dist/commands/user.js +1 -60
  95. package/dist/commands/vpc_endpoints.js +1 -105
  96. package/dist/functions/registry.js +29 -151
  97. package/dist/functions/source.js +42 -2
  98. package/dist/index.js +1 -1
  99. package/dist/init/auth.js +3 -3
  100. package/dist/init/link.js +2 -2
  101. package/dist/init/run.js +3 -3
  102. package/dist/init/tooling.js +3 -3
  103. package/dist/mcp/mint.js +1 -1
  104. package/dist/test_utils/registry.js +1 -2
  105. package/dist/utils/package_manager.js +1 -0
  106. package/package.json +4 -2
@@ -1,291 +1 @@
1
- import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
- import { log } from "../log.js";
3
- import { isNeonApiError } from "../api.js";
4
- import { writer } from "../writer.js";
5
- import { noPassthrough, single } from "../utils/flags.js";
6
- import { branchIdFromProps, fillSingleProject } from "../utils/enrichers.js";
7
- //#region src/commands/logs.ts
8
- var logs_exports = /* @__PURE__ */ __exportAll({
9
- assertReachableLogsPage: () => assertReachableLogsPage,
10
- buildLogsQueryBody: () => buildLogsQueryBody,
11
- builder: () => builder,
12
- command: () => command,
13
- describe: () => describe,
14
- escapeLogSingleLine: () => escapeLogSingleLine,
15
- escapeLogTableCell: () => escapeLogTableCell,
16
- handler: () => handler
17
- });
18
- const LOGS_EPILOG = `
19
- Logs are currently available only for projects in aws-us-east-2, aws-us-east-1, aws-eu-central-1, and aws-ap-southeast-1.
20
-
21
- For more information, visit https://neon.com/docs/reference/neon-cli`;
22
- const LOG_SOURCES = [
23
- "function",
24
- "storage",
25
- "pg_endpoint"
26
- ];
27
- const LOG_SORT_ORDERS = ["asc", "desc"];
28
- const LOG_SEVERITIES = [
29
- "trace",
30
- "debug",
31
- "info",
32
- "warn",
33
- "error",
34
- "fatal"
35
- ];
36
- const LOG_FIELDS = [
37
- "timestamp",
38
- "source",
39
- "service_name",
40
- "severity_text",
41
- "message"
42
- ];
43
- const escapeLogTableCell = (value) => value.replace(/\p{Cc}/gu, (character) => character === "\n" || character === " " ? character : `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
44
- const escapeLogSingleLine = (value) => value.replace(/\p{Cc}/gu, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
45
- const PORTABLE_LOG_CURSOR = /^[A-Za-z0-9._~+/=-]+$/u;
46
- const assertReachableLogsPage = ({ is_truncated, next_cursor }) => {
47
- if (is_truncated && !next_cursor) throw new Error("Neon returned an incomplete logs page without a pagination cursor. No records were printed because the result cannot be completed; retry the command.");
48
- if (is_truncated && next_cursor !== void 0 && !PORTABLE_LOG_CURSOR.test(next_cursor)) throw new Error("Neon returned a pagination cursor containing characters that are unsafe in supported shells. No records were printed because the next page cannot be requested safely.");
49
- };
50
- const logLimit = (value) => {
51
- if (value === void 0) return void 0;
52
- if (Array.isArray(value) || typeof value !== "number" || !Number.isInteger(value) || value < 1 || value > 1e3) throw new Error("--limit must be an integer from 1 to 1000.");
53
- return value;
54
- };
55
- const CONTENT_FILTERS = [
56
- "source",
57
- "service-name",
58
- "scope-name",
59
- "minimum-severity",
60
- "severity-text",
61
- "body-contains",
62
- "trace-id"
63
- ];
64
- const scopeOptions = {
65
- "project-id": {
66
- describe: "Project ID",
67
- type: "string",
68
- coerce: single("project-id")
69
- },
70
- branch: {
71
- describe: "Branch ID or name",
72
- type: "string",
73
- coerce: single("branch")
74
- }
75
- };
76
- const windowOptions = (defaultWindow) => ({
77
- since: {
78
- describe: `Length of the window, ending at --end-time or now. Defaults to ${defaultWindow}; the maximum window is 7d. Mutually exclusive with --start-time.`,
79
- type: "string",
80
- coerce: single("since")
81
- },
82
- "start-time": {
83
- describe: "Inclusive start of the window (RFC 3339, e.g. 2025-01-01T00:00:00Z). The maximum window is 7d. Mutually exclusive with --since.",
84
- type: "string",
85
- coerce: single("start-time")
86
- },
87
- "end-time": {
88
- describe: "Exclusive end of the window (RFC 3339). Defaults to the current time.",
89
- type: "string",
90
- coerce: single("end-time")
91
- }
92
- });
93
- const command = "logs";
94
- const describe = "Query branch logs";
95
- const builder = (argv) => argv.usage("$0 logs <sub-command> [options]").options(scopeOptions).middleware(fillSingleProject).command("query", "Query log records on a branch", (yargs) => yargs.epilogue(LOGS_EPILOG).options({
96
- ...windowOptions("1h"),
97
- limit: {
98
- describe: "Maximum number of records to return per page (1-1000)",
99
- type: "number",
100
- default: 100,
101
- coerce: logLimit
102
- },
103
- cursor: {
104
- describe: "Pagination cursor returned as next_cursor by a previous call. Repeat the same time range and filters.",
105
- type: "string",
106
- coerce: single("cursor")
107
- },
108
- "sort-order": {
109
- describe: "Order records by timestamp. Defaults to desc (newest first).",
110
- type: "string",
111
- choices: LOG_SORT_ORDERS,
112
- coerce: single("sort-order")
113
- },
114
- source: {
115
- describe: "Only records emitted by this service",
116
- type: "string",
117
- choices: LOG_SOURCES,
118
- coerce: single("source")
119
- },
120
- "service-name": {
121
- describe: "Match the OpenTelemetry service.name resource attribute exactly",
122
- type: "string",
123
- coerce: single("service-name")
124
- },
125
- "scope-name": {
126
- describe: "Match the OpenTelemetry instrumentation scope name exactly",
127
- type: "string",
128
- coerce: single("scope-name")
129
- },
130
- "minimum-severity": {
131
- describe: "Only records at or above this severity. Combines with --severity-text. If Neon reports that this filter is unsupported, use --severity-text instead.",
132
- type: "string",
133
- choices: LOG_SEVERITIES,
134
- coerce: single("minimum-severity")
135
- },
136
- "severity-text": {
137
- describe: "Match the OpenTelemetry severity text exactly. Run `neon logs field-values severity_text` to discover the values present.",
138
- type: "string",
139
- coerce: single("severity-text")
140
- },
141
- "body-contains": {
142
- describe: "Match the case-sensitive rendered message. Structured bodies are rendered as compact JSON.",
143
- type: "string",
144
- coerce: single("body-contains")
145
- },
146
- "trace-id": {
147
- describe: "Match records carrying this trace ID (32 lowercase hex digits)",
148
- type: "string",
149
- coerce: single("trace-id")
150
- },
151
- logql: {
152
- describe: "Raw LogQL expression (stream selectors and line filters only). Replaces the structured filters; the window, --limit, --sort-order and --cursor still apply.",
153
- type: "string",
154
- coerce: single("logql")
155
- }
156
- }).conflicts("since", "start-time").conflicts("logql", [...CONTENT_FILTERS]).example([
157
- ["$0 logs query --since 30m", "The last 30 minutes of logs on the default branch"],
158
- ["$0 logs query --branch main --source pg_endpoint --minimum-severity error", "Postgres compute errors on main"],
159
- ["$0 logs query --since 1h --logql '{entity_type=\"function\"} |= \"timeout\"'", "A raw LogQL selection instead of the structured filters"]
160
- ]).strict().check(noPassthrough("logs query")), (args) => query(args)).command("fields", "List the log fields whose values can be discovered on a branch", (yargs) => yargs.epilogue(LOGS_EPILOG).strict().check(noPassthrough("logs fields")), (args) => fields(args)).command("field-values <field>", "List the distinct values observed for a log field", (yargs) => yargs.epilogue(LOGS_EPILOG).positional("field", {
161
- describe: "The log field to list values for. Must be one of the names `logs fields` reports.",
162
- type: "string",
163
- demandOption: true
164
- }).options({
165
- ...windowOptions("6h"),
166
- source: {
167
- describe: "Only consider records emitted by this service",
168
- type: "string",
169
- choices: LOG_SOURCES,
170
- coerce: single("source")
171
- },
172
- limit: {
173
- describe: "Maximum number of distinct values to return (1-1000)",
174
- type: "number",
175
- coerce: logLimit
176
- }
177
- }).conflicts("since", "start-time").example([["$0 logs field-values service_name --since 6h", "Service names seen in the last six hours"]]).strict().check(noPassthrough("logs field-values")), (args) => fieldValues(args)).epilogue(LOGS_EPILOG);
178
- const handler = (args) => {
179
- return args;
180
- };
181
- /**
182
- * Map the parsed flags onto the request body, dropping everything the user did
183
- * not supply so the API applies its own defaults rather than ours.
184
- */
185
- const buildLogsQueryBody = (flags) => {
186
- const body = {};
187
- if (flags.since !== void 0) body.since = flags.since;
188
- if (flags.startTime !== void 0) body.start_time = flags.startTime;
189
- if (flags.endTime !== void 0) body.end_time = flags.endTime;
190
- if (flags.limit !== void 0) body.limit = flags.limit;
191
- if (flags.cursor !== void 0) body.cursor = flags.cursor;
192
- if (flags.sortOrder !== void 0) body.sort_order = flags.sortOrder;
193
- if (flags.source !== void 0) body.source = flags.source;
194
- if (flags.serviceName !== void 0) body.service_name = flags.serviceName;
195
- if (flags.scopeName !== void 0) body.scope_name = flags.scopeName;
196
- if (flags.minimumSeverity !== void 0) body.minimum_severity = flags.minimumSeverity;
197
- if (flags.severityText !== void 0) body.severity_text = flags.severityText;
198
- if (flags.bodyContains !== void 0) body.body_contains = flags.bodyContains;
199
- if (flags.traceId !== void 0) body.trace_id = flags.traceId;
200
- if (flags.logql !== void 0) body.logql = flags.logql;
201
- return body;
202
- };
203
- const describeWindow = (window, defaultSince) => window.startTime ? `window from ${window.startTime} to ${window.endTime ?? "now"}` : `${window.since ?? defaultSince} window ending ${window.endTime ?? "now"}`;
204
- const apiErrorReason = (data) => {
205
- if (typeof data !== "object" || data === null || !("reason" in data)) return;
206
- return typeof data.reason === "string" ? data.reason : void 0;
207
- };
208
- const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
209
- const isOptionalString = (value) => value === void 0 || typeof value === "string";
210
- const isProjectBranchLogRecord = (value) => isRecord(value) && typeof value.timestamp === "string" && !Number.isNaN(Date.parse(value.timestamp)) && typeof value.message === "string" && (value.source === void 0 || LOG_SOURCES.some((source) => source === value.source)) && isOptionalString(value.entity_id) && isOptionalString(value.service_name) && isOptionalString(value.scope_name) && isOptionalString(value.severity_text) && (value.severity_number === void 0 || typeof value.severity_number === "number" && Number.isInteger(value.severity_number) && value.severity_number >= 0 && value.severity_number <= 24) && isOptionalString(value.trace_id) && isOptionalString(value.span_id) && isRecord(value.attributes);
211
- function assertLogsQueryResponse(value) {
212
- if (!isRecord(value) || !Array.isArray(value.logs) || !value.logs.every(isProjectBranchLogRecord) || !isOptionalString(value.next_cursor) || typeof value.is_truncated !== "boolean") throw new Error("Neon returned an invalid logs query response; expected logs[] and is_truncated.");
213
- }
214
- function assertLogFieldsResponse(value) {
215
- if (!isRecord(value) || !Array.isArray(value.fields) || !value.fields.every((field) => typeof field === "string")) throw new Error("Neon returned an invalid log fields response; expected fields[].");
216
- }
217
- function assertLogFieldValuesResponse(value) {
218
- if (!isRecord(value) || !Array.isArray(value.values) || !value.values.every((field) => typeof field === "string") || typeof value.is_truncated !== "boolean") throw new Error("Neon returned an invalid log field-values response; expected values[] and is_truncated.");
219
- }
220
- const query = async (props) => {
221
- const branchId = await branchIdFromProps(props);
222
- const { data } = await props.apiClient.queryProjectBranchLogs(props.projectId, branchId, buildLogsQueryBody(props));
223
- assertLogsQueryResponse(data);
224
- assertReachableLogsPage(data);
225
- if (props.output === "json" || props.output === "yaml") {
226
- writer(props).end(data, { fields: [
227
- "logs",
228
- "next_cursor",
229
- "is_truncated"
230
- ] });
231
- return;
232
- }
233
- writer(props).end(data.logs.map((record) => ({
234
- timestamp: escapeLogTableCell(record.timestamp),
235
- source: record.source === void 0 ? void 0 : escapeLogTableCell(record.source),
236
- service_name: record.service_name === void 0 ? void 0 : escapeLogTableCell(record.service_name),
237
- severity_text: record.severity_text === void 0 ? void 0 : escapeLogTableCell(record.severity_text),
238
- message: escapeLogTableCell(record.message)
239
- })), {
240
- fields: LOG_FIELDS,
241
- title: "logs",
242
- emptyMessage: `No logs found in the ${describeWindow(props, "1h")}.`
243
- });
244
- if (data.is_truncated && data.next_cursor) log.info(`More logs matched than were returned. Re-run with the same filters plus --cursor=${data.next_cursor} to fetch the next page.`);
245
- };
246
- const fields = async (props) => {
247
- const branchId = await branchIdFromProps(props);
248
- const { data } = await props.apiClient.listProjectBranchLogFields(props.projectId, branchId);
249
- assertLogFieldsResponse(data);
250
- if (props.output === "json" || props.output === "yaml") {
251
- writer(props).end(data, { fields: ["fields"] });
252
- return;
253
- }
254
- writer(props).end(data.fields.map((field) => ({ field: escapeLogTableCell(field) })), {
255
- fields: ["field"],
256
- title: "fields",
257
- emptyMessage: "No log fields found."
258
- });
259
- };
260
- const fieldValues = async (props) => {
261
- const branchId = await branchIdFromProps(props);
262
- let data;
263
- try {
264
- ({data} = await props.apiClient.listProjectBranchLogFieldValues({
265
- projectId: props.projectId,
266
- branchId,
267
- fieldName: props.field,
268
- ...props.since !== void 0 ? { since: props.since } : {},
269
- ...props.startTime !== void 0 ? { start_time: props.startTime } : {},
270
- ...props.endTime !== void 0 ? { end_time: props.endTime } : {},
271
- ...props.source !== void 0 ? { source: props.source } : {},
272
- ...props.limit !== void 0 ? { limit: props.limit } : {}
273
- }));
274
- } catch (error) {
275
- if (isNeonApiError(error) && error.status === 400 && apiErrorReason(error.data) === "unknown_field") throw new Error(`Unknown log field "${escapeLogSingleLine(props.field)}". Run \`neon logs fields --project-id ${escapeLogSingleLine(props.projectId)} --branch ${escapeLogSingleLine(branchId)}\` to list the fields this branch supports.`);
276
- throw error;
277
- }
278
- assertLogFieldValuesResponse(data);
279
- if (props.output === "json" || props.output === "yaml") {
280
- writer(props).end(data, { fields: ["values", "is_truncated"] });
281
- return;
282
- }
283
- writer(props).end(data.values.map((value) => ({ value: escapeLogTableCell(value) })), {
284
- fields: ["value"],
285
- title: "values",
286
- emptyMessage: `No values found in the ${describeWindow(props, "6h")}.`
287
- });
288
- if (data.is_truncated) log.info(`More values exist than were returned for "${escapeLogSingleLine(props.field)}". Narrow the window with --since or --start-time, restrict --source, or raise --limit, then run it again.`);
289
- };
290
- //#endregion
291
- export { assertReachableLogsPage, buildLogsQueryBody, builder, command, describe, escapeLogSingleLine, escapeLogTableCell, handler, logs_exports as t };
1
+ export { t as assertReachableLogsPage, n as buildLogsQueryBody, r as builder, i as command, a as describe, o as escapeLogSingleLine, s as escapeLogTableCell, c as handler } from "../_chunks/logs-DWkpjzIH.js";
@@ -1,253 +1 @@
1
- import { t as __exportAll } from "../_chunks/rolldown-runtime-8H4AJuhK.js";
2
- import { log } from "../log.js";
3
- import { readContextFile } from "../context.js";
4
- import { recordCommandSuccessExtras } from "../analytics.js";
5
- import { getCliName } from "../utils/cli_name.js";
6
- import { helpCsv, helpEpilogue } from "../utils/help_text.js";
7
- import { NEON_MCP_CATEGORIES, NEON_MCP_URL, existingNeonApiKey, installNeonMcpServer, neonMcpUrl, parseMcpCategories, trackedProjectMcpConfig } from "../mcp/install.js";
8
- import { mcpInstallableAgents, resolveInstallTargets } from "../mcp/targets.js";
9
- import { writer } from "../writer.js";
10
- import { noPassthrough, single } from "../utils/flags.js";
11
- import { AGENT_MCP_SKIP_MESSAGE } from "../init/copy.js";
12
- import { mintMcpApiKey, mintedKeyRevokeCommand, withdrawMintedKey } from "../mcp/mint.js";
13
- import { canPickAgentsInteractively, skippableAgentPicker } from "../utils/agent_picker.js";
14
- import { resolveMcpPlan } from "../mcp/plan.js";
15
- //#region src/commands/mcp.ts
16
- var mcp_exports = /* @__PURE__ */ __exportAll({
17
- builder: () => builder,
18
- command: () => "mcp",
19
- describe: () => describe,
20
- handler: () => handler,
21
- mcpInstallError: () => mcpInstallError,
22
- reportMcpInstall: () => reportMcpInstall,
23
- setupNeonMcp: () => setupNeonMcp
24
- });
25
- const command = "mcp";
26
- const describe = "Install the Neon MCP server into coding agents";
27
- const mcpGlobalAgents = mcpInstallableAgents("global");
28
- const mcpProjectAgents = mcpInstallableAgents("project");
29
- const mcpProjectDroppedAgents = mcpGlobalAgents.filter((id) => !mcpProjectAgents.includes(id));
30
- const builder = (argv) => argv.usage("$0 mcp [options]").options({
31
- oauth: {
32
- type: "boolean",
33
- default: false,
34
- describe: "Write the server URL only. The agent prompts for Neon sign-in on first use. No CLI login, no API key minted. Skips the auth question"
35
- },
36
- project: {
37
- type: "boolean",
38
- default: false,
39
- 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"
40
- },
41
- yes: {
42
- alias: "y",
43
- type: "boolean",
44
- default: false,
45
- describe: "Skip prompts. Defaults listed below. --agent, --project, --oauth, --read-only, --project-id and --category still apply"
46
- },
47
- agent: {
48
- alias: "a",
49
- type: "array",
50
- string: true,
51
- describe: "Coding agent to install into (repeatable). Skips the agent picker. Values listed below",
52
- coerce: (value) => {
53
- if (value === void 0) return [];
54
- const list = Array.isArray(value) ? value : [value];
55
- if (list.length === 0) throw new Error("--agent needs a value. Pass one, or omit the flag entirely.");
56
- return list.map((item) => {
57
- if (typeof item !== "string" || item.trim() === "") throw new Error("--agent needs a value. Pass one, or omit the flag entirely.");
58
- return item;
59
- });
60
- }
61
- },
62
- "read-only": {
63
- alias: "readonly",
64
- type: "boolean",
65
- default: false,
66
- describe: "Restrict MCP tools to read-only (?readonly=true). Not prompted. Does not change the minted key"
67
- },
68
- "project-id": {
69
- type: "string",
70
- 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",
71
- coerce: single("project-id")
72
- },
73
- category: {
74
- type: "array",
75
- string: true,
76
- describe: "MCP tool category (repeatable or comma-separated). Default: all. Values listed below",
77
- coerce: (value) => {
78
- if (value === void 0) return [];
79
- const list = Array.isArray(value) ? value : [value];
80
- if (list.length === 0) throw new Error("--category needs a value. Pass one, or omit the flag entirely.");
81
- const parts = [];
82
- for (const item of list) {
83
- if (typeof item !== "string" || item.trim() === "") throw new Error("--category needs a value. Pass one, or omit the flag entirely.");
84
- for (const part of item.split(",")) {
85
- const trimmed = part.trim();
86
- if (trimmed === "") throw new Error("--category needs a value. Pass one, or omit the flag entirely.");
87
- parts.push(trimmed);
88
- }
89
- }
90
- return parseMcpCategories(parts);
91
- }
92
- }
93
- }).example("$0 mcp", "Interactive: config location, agents, then auth").example("$0 mcp -y", "Global config, installed apps else the host CLI agent, reuse or mint an API key").example("$0 mcp --oauth", "Install with OAuth; the agent signs in on first use").example("$0 mcp --agent cursor --agent claude-code", "Install into specific agents").example("$0 mcp --project", "Write project-level config").example("$0 mcp --read-only", "Hide write tools via ?readonly=true").example("$0 mcp --project-id <id>", "Pin tools to one project via ?projectId=").example("$0 mcp --category querying --category schema", "Limit tools to those categories").epilogue(helpEpilogue(`Installs ${NEON_MCP_URL}`, helpCsv("Supported agents at global scope", mcpGlobalAgents), helpCsv("--project does not support", mcpProjectDroppedAgents), helpCsv("Supported categories", NEON_MCP_CATEGORIES), "neon mcp -y:", " global config", " globally installed apps, else the host CLI agent", " reuse an existing Neon MCP API key, else mint an account-wide key", " write tools on, all categories", " no project pin (including from .neon)")).strict().check(noPassthrough("mcp"));
94
- /**
95
- * Resolves auth, mints or reuses an API key, and writes the Neon MCP server into every
96
- * resolved agent. No CLI-only concerns here (no `writer` table, no
97
- * `recordCommandSuccessExtras`): a caller that only wants the outcome — `neon init` /
98
- * `neon bootstrap` — gets it without rendering a table.
99
- *
100
- * Throws directly when zero agents succeed, since that path never reaches a results table
101
- * worth showing (same as the CLI handler always did).
102
- */
103
- const setupNeonMcp = async (options) => {
104
- const cwd = options.cwd ?? process.cwd();
105
- const interactive = canPickAgentsInteractively() && options.yes !== true;
106
- const linkedProjectId = readContextFile(options.contextFile).projectId;
107
- const plan = await resolveMcpPlan({
108
- project: options.project === true,
109
- oauth: options.oauth === true,
110
- agents: options.agent ?? [],
111
- yes: options.yes === true,
112
- cwd,
113
- interactive,
114
- readOnly: options.readOnly === true,
115
- projectId: options.projectId,
116
- categories: options.category ?? [],
117
- linkedProjectId,
118
- pickAgents: skippableAgentPicker(options.allowAgentSkip, AGENT_MCP_SKIP_MESSAGE)
119
- });
120
- const { install, skipped } = resolveInstallTargets({
121
- agents: plan.agents,
122
- scope: plan.scope
123
- });
124
- const url = neonMcpUrl({
125
- readOnly: plan.readOnly,
126
- projectId: plan.urlProjectId,
127
- categories: plan.categories
128
- });
129
- if (plan.scope === "project" && plan.auth === "api-key") {
130
- const tracked = trackedProjectMcpConfig({
131
- agents: install,
132
- cwd
133
- });
134
- if (tracked) throw new Error(`${tracked} is tracked by git. Untrack it before writing an API key, or pass --oauth.`);
135
- }
136
- const existing = plan.auth === "api-key" ? existingNeonApiKey({
137
- agents: install,
138
- scope: plan.scope,
139
- cwd
140
- }) : void 0;
141
- if (plan.auth === "api-key" && !existing) {
142
- if (!options.apiClient || !options.apiKey) throw new Error(`Authentication required. Run \`${getCliName()} login\`, pass --api-key or use --oauth to install without a Neon credential.`);
143
- if (!canPickAgentsInteractively() && options.yes !== true && (options.agent ?? []).length === 0) throw new Error("No interactive terminal. Pass -y to mint into every detected agent, --agent <name> to name them or --oauth to install without minting.");
144
- }
145
- let auth;
146
- let minted;
147
- if (plan.auth === "oauth") auth = { kind: "oauth" };
148
- else if (existing) {
149
- auth = {
150
- kind: "api-key",
151
- apiKey: existing
152
- };
153
- log.info("Reusing the API key already configured for the Neon MCP server.");
154
- 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.");
155
- } else {
156
- minted = await mintMcpApiKey({
157
- apiClient: options.apiClient,
158
- projectId: plan.urlProjectId
159
- });
160
- auth = {
161
- kind: "api-key",
162
- apiKey: minted.key
163
- };
164
- 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);
165
- else log.warning("This key reaches everything your account can, in every organization.");
166
- }
167
- const rows = [];
168
- let successes = 0;
169
- const failedAgents = [];
170
- for (const agent of install) {
171
- const result = installNeonMcpServer({
172
- agent,
173
- scope: plan.scope,
174
- cwd,
175
- auth,
176
- url
177
- });
178
- if (result.ok) {
179
- successes += 1;
180
- rows.push({
181
- agent,
182
- status: "installed"
183
- });
184
- log.info("Wrote %s", result.path);
185
- } else {
186
- rows.push({
187
- agent,
188
- status: result.unsupported ? "skipped" : "failed",
189
- error: result.error
190
- });
191
- if (!result.unsupported) failedAgents.push(agent);
192
- }
193
- }
194
- for (const row of skipped) rows.push({
195
- agent: row.agent,
196
- status: "skipped",
197
- error: row.error
198
- });
199
- if (successes === 0) {
200
- if (minted && options.apiClient) {
201
- const withdrawn = await withdrawMintedKey(options.apiClient, minted);
202
- 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)}\`.`);
203
- }
204
- throw new Error("Failed to write Neon MCP config to any agent.");
205
- }
206
- return {
207
- scope: plan.scope,
208
- rows,
209
- failedAgents,
210
- url,
211
- auth: auth.kind,
212
- ...minted ? { minted } : {}
213
- };
214
- };
215
- /** The exact error `neon mcp` throws when some (not all) agents failed, or `undefined` on full success. */
216
- const mcpInstallError = (outcome) => outcome.failedAgents.length > 0 ? /* @__PURE__ */ new Error(`Failed to write Neon MCP config for: ${outcome.failedAgents.join(", ")}.`) : void 0;
217
- /** Writes the results table plus the URL/minted-key/OAuth notices. Shared by `neon mcp` and any in-process caller that wants the same human output. */
218
- const reportMcpInstall = (props, outcome) => {
219
- log.info("URL: %s", outcome.url);
220
- const out = writer(props);
221
- out.write(outcome.rows, {
222
- fields: [
223
- "agent",
224
- "status",
225
- "error"
226
- ],
227
- title: "MCP"
228
- });
229
- out.end();
230
- if (outcome.minted) log.info("Minted API key %s (id %d, %s). Revoke with: %s", outcome.minted.name, outcome.minted.id, outcome.minted.projectId ? "project" : "account", mintedKeyRevokeCommand(outcome.minted));
231
- if (outcome.auth === "oauth") log.info("The agent will prompt for Neon sign-in on first use.");
232
- };
233
- const handler = async (props) => {
234
- const outcome = await setupNeonMcp({
235
- apiClient: props.apiClient,
236
- apiKey: props.apiKey,
237
- contextFile: props.contextFile,
238
- cwd: props.cwd,
239
- yes: props.yes,
240
- oauth: props.oauth,
241
- project: props.project,
242
- agent: props.agent,
243
- readOnly: props.readOnly,
244
- projectId: props.projectId,
245
- category: props.category
246
- });
247
- reportMcpInstall(props, outcome);
248
- const error = mcpInstallError(outcome);
249
- if (error) throw error;
250
- recordCommandSuccessExtras({ scope: outcome.scope });
251
- };
252
- //#endregion
253
- export { builder, command, describe, handler, mcpInstallError, reportMcpInstall, setupNeonMcp, mcp_exports as t };
1
+ export { t as builder, n as command, r as describe, i as handler, a as mcpInstallError, s as reportMcpInstall, c as setupNeonMcp } from "../_chunks/mcp-Bo-7TKc7.js";