@neon/tools 2.14.4 → 2.16.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.
Files changed (96) hide show
  1. package/README.md +195 -5
  2. package/dist/descriptions.gen.js +2 -2
  3. package/dist/effect.d.ts +22 -0
  4. package/dist/effect.d.ts.map +1 -0
  5. package/dist/effect.js +3 -0
  6. package/dist/generated/output.gen.d.ts +3418 -0
  7. package/dist/generated/output.gen.d.ts.map +1 -0
  8. package/dist/generated/output.gen.js +1498 -0
  9. package/dist/generated/zod.gen.d.ts +3 -3
  10. package/dist/index.d.ts +17 -5
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +30 -9
  13. package/dist/lib/custom/auth-config.d.ts +63 -2
  14. package/dist/lib/custom/auth-config.d.ts.map +1 -1
  15. package/dist/lib/custom/auth-config.js +34 -7
  16. package/dist/lib/custom/docs.d.ts +32 -2
  17. package/dist/lib/custom/docs.d.ts.map +1 -1
  18. package/dist/lib/custom/docs.js +18 -1
  19. package/dist/lib/custom/feedback.d.ts +7 -2
  20. package/dist/lib/custom/feedback.d.ts.map +1 -1
  21. package/dist/lib/custom/feedback.js +3 -0
  22. package/dist/lib/custom/fetch.d.ts +15 -1
  23. package/dist/lib/custom/fetch.d.ts.map +1 -1
  24. package/dist/lib/custom/fetch.js +10 -1
  25. package/dist/lib/custom/organizations.d.ts +23 -1
  26. package/dist/lib/custom/organizations.d.ts.map +1 -1
  27. package/dist/lib/custom/organizations.js +3 -0
  28. package/dist/lib/custom/resources.d.ts +15 -1
  29. package/dist/lib/custom/resources.d.ts.map +1 -1
  30. package/dist/lib/custom/resources.js +8 -1
  31. package/dist/lib/custom/sql/connection.d.ts +6 -7
  32. package/dist/lib/custom/sql/connection.d.ts.map +1 -1
  33. package/dist/lib/custom/sql/connection.js +10 -12
  34. package/dist/lib/custom/sql/describe-branch.d.ts +99 -1
  35. package/dist/lib/custom/sql/describe-branch.d.ts.map +1 -1
  36. package/dist/lib/custom/sql/describe-branch.js +11 -2
  37. package/dist/lib/custom/sql/inspect/inspect.d.ts +27 -1
  38. package/dist/lib/custom/sql/inspect/inspect.d.ts.map +1 -1
  39. package/dist/lib/custom/sql/inspect/inspect.js +17 -3
  40. package/dist/lib/custom/sql/migrations.d.ts +46 -2
  41. package/dist/lib/custom/sql/migrations.d.ts.map +1 -1
  42. package/dist/lib/custom/sql/migrations.js +29 -7
  43. package/dist/lib/custom/sql/query-tuning.d.ts +90 -2
  44. package/dist/lib/custom/sql/query-tuning.d.ts.map +1 -1
  45. package/dist/lib/custom/sql/query-tuning.js +31 -8
  46. package/dist/lib/custom/sql/run.d.ts +30 -3
  47. package/dist/lib/custom/sql/run.d.ts.map +1 -1
  48. package/dist/lib/custom/sql/run.js +15 -6
  49. package/dist/lib/custom/sql/schema.d.ts +76 -2
  50. package/dist/lib/custom/sql/schema.d.ts.map +1 -1
  51. package/dist/lib/custom/sql/schema.js +34 -5
  52. package/dist/lib/custom/sql/slow-queries.d.ts +15 -1
  53. package/dist/lib/custom/sql/slow-queries.d.ts.map +1 -1
  54. package/dist/lib/custom/sql/slow-queries.js +11 -3
  55. package/dist/lib/customize.d.ts +1 -1
  56. package/dist/lib/customize.d.ts.map +1 -1
  57. package/dist/lib/customize.js +8 -4
  58. package/dist/lib/effect/errors.d.ts +51 -0
  59. package/dist/lib/effect/errors.d.ts.map +1 -0
  60. package/dist/lib/effect/errors.js +37 -0
  61. package/dist/lib/effect/tools.d.ts +56 -0
  62. package/dist/lib/effect/tools.d.ts.map +1 -0
  63. package/dist/lib/effect/tools.js +67 -0
  64. package/dist/lib/ergonomic/bind.d.ts +25 -7
  65. package/dist/lib/ergonomic/bind.d.ts.map +1 -1
  66. package/dist/lib/ergonomic/bind.js +13 -3
  67. package/dist/lib/ergonomic/catalog.d.ts +5335 -180
  68. package/dist/lib/ergonomic/catalog.d.ts.map +1 -1
  69. package/dist/lib/ergonomic/catalog.js +286 -23
  70. package/dist/lib/ergonomic/composed.d.ts +866 -12
  71. package/dist/lib/ergonomic/composed.d.ts.map +1 -1
  72. package/dist/lib/ergonomic/composed.js +63 -0
  73. package/dist/lib/mcp-json-schema.d.ts +20 -0
  74. package/dist/lib/mcp-json-schema.d.ts.map +1 -1
  75. package/dist/lib/mcp-json-schema.js +89 -1
  76. package/dist/lib/mcp-register.d.ts +1 -1
  77. package/dist/lib/mcp-register.d.ts.map +1 -1
  78. package/dist/lib/mcp-register.js +2 -1
  79. package/dist/lib/operation.d.ts +56 -5
  80. package/dist/lib/operation.d.ts.map +1 -1
  81. package/dist/lib/operation.js +6 -1
  82. package/dist/lib/policy.d.ts +24 -0
  83. package/dist/lib/policy.d.ts.map +1 -0
  84. package/dist/lib/policy.js +49 -0
  85. package/dist/lib/redact.d.ts +8 -0
  86. package/dist/lib/redact.d.ts.map +1 -0
  87. package/dist/lib/redact.js +40 -0
  88. package/dist/mastra.d.ts +2 -1
  89. package/dist/mastra.d.ts.map +1 -1
  90. package/dist/mcp-v1.d.ts.map +1 -1
  91. package/dist/mcp-v1.js +3 -1
  92. package/dist/mcp.d.ts +3 -3
  93. package/dist/mcp.d.ts.map +1 -1
  94. package/dist/mcp.js +3 -3
  95. package/dist/operations.gen.d.ts +194 -194
  96. package/package.json +21 -2
@@ -1 +1 @@
1
- {"version":3,"file":"composed.d.ts","sourceRoot":"","sources":["../../../src/lib/ergonomic/composed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AASzB,OAAO,EAAyB,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAwD1E,eAAO,MAAM,uBAAuB;;;;;;;;;;kBAuBjC,CAAC;AAEJ,eAAO,MAAM,iCAAiC;;;;;;;;;;kBAQ5C,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAEnC,CAAC;AAEH,eAAO,MAAM,kCAAkC;;;;;;;;;;;;;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;;;;;;CAoC7D,CAAC;AAEH,eAAO,MAAM,cAAc,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDvD,CAAC;AAEH,eAAO,MAAM,mBAAmB,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiC5D,CAAC;AAEH,eAAO,MAAM,eAAe,GAAI,SAAS,iBAAiB;;;;;;;;;;;;;;;;CA8BxD,CAAC"}
@@ -2,6 +2,7 @@ import { pathInputDescriptions } from "../../descriptions.gen.js";
2
2
  import { zBackupScheduleItem, zBranchCreateRequest, zBranchRestoreRequest, zComputeUnit, zCreateProjectBody, zCreateProjectBranchPath, zCreateProjectBranchRoleBody, zCreateProjectBranchRolePath, zGetConnectionUriPath, zGetConnectionUriQuery, zGetProjectBranchSchemaComparisonPath, zGetProjectBranchSchemaComparisonQuery, zListProjectBranchesPath, zQueryProjectBranchLogsPath, zRestoreProjectBranchPath, zRestoreSnapshotBody, zRestoreSnapshotPath, zSetSnapshotSchedulePath, zSuspendTimeoutSeconds } from "../../generated/zod.gen.js";
3
3
  import { bindTool, publishedId } from "./bind.js";
4
4
  import { COMPUTE_ID_DESCRIPTION, databaseNameField, resolveConnection, roleNameField } from "../custom/sql/connection.js";
5
+ import { Branch, BranchSchemaCompareResponse, Endpoint, Project, Role } from "../../generated/output.gen.js";
5
6
  import * as z from "zod";
6
7
  // src/lib/ergonomic/composed.ts
7
8
  const writeAnnotations = {
@@ -80,12 +81,24 @@ const lokiQueryRangeInputSchema = z.strictObject({
80
81
  limit: z.number().int().positive().describe("Maximum log lines. The server enforces its own cap.").optional(),
81
82
  direction: z.enum(["forward", "backward"]).describe("backward (default) is newest first.").optional()
82
83
  });
84
+ const lokiQueryRangeOutputSchema = z.looseObject({
85
+ status: z.string().describe("Loki's response status, `success`."),
86
+ data: z.looseObject({
87
+ resultType: z.string(),
88
+ result: z.array(z.looseObject({
89
+ stream: z.record(z.string(), z.string()),
90
+ values: z.array(z.array(z.string()))
91
+ }))
92
+ }).describe("Log streams: each has its labels and `[timestamp_ns, line]` pairs."),
93
+ warnings: z.array(z.string()).nullish().describe("Loki query warnings.")
94
+ });
83
95
  const lokiQueryRangeTool = (options) => bindTool(options, {
84
96
  operationId: "logs.loki.queryRange",
85
97
  id: publishedId("logs.loki.queryRange"),
86
98
  title: "Query branch logs (Loki)",
87
99
  description: "Runs a LogQL range query on a branch's logs and returns Loki's response: data.result groups lines by stream label as [nanosecond timestamp, line]. {{logs.query}} has structured filters; {{logs.fields}} and {{logs.fieldValues}} list labels. No cursor: limit lines, or the silent 10,000 cap, may mean more exist; narrow the window.",
88
100
  inputSchema: lokiQueryRangeInputSchema,
101
+ outputSchema: lokiQueryRangeOutputSchema,
89
102
  annotations: {
90
103
  readOnlyHint: true,
91
104
  destructiveHint: false,
@@ -95,6 +108,7 @@ const lokiQueryRangeTool = (options) => bindTool(options, {
95
108
  requiresApproval: false,
96
109
  metadata: {
97
110
  method: "GET",
111
+ readOnlySafe: true,
98
112
  path: "/telemetry/v1/projects/{project_id}/branches/{branch_id}/loki/api/v1/query_range",
99
113
  stability: "beta",
100
114
  deprecated: false,
@@ -165,10 +179,12 @@ const createBranchTool = (options) => bindTool(options, {
165
179
  title: "Create branch",
166
180
  description: "Creates a branch from its parent's current data, with a read-write compute unless no_compute, and waits until it is ready. Returns no connection string; use {{postgres.connectionString}}.",
167
181
  inputSchema: createBranchInputSchema,
182
+ outputSchema: Branch,
168
183
  annotations: writeAnnotations,
169
184
  requiresApproval: true,
170
185
  metadata: {
171
186
  method: "POST",
187
+ readOnlySafe: false,
172
188
  path: "/projects/{project_id}/branches",
173
189
  stability: "stable",
174
190
  deprecated: false,
@@ -188,16 +204,27 @@ const createBranchTool = (options) => bindTool(options, {
188
204
  compute: mapCompute(input.compute)
189
205
  }, { signal });
190
206
  });
207
+ const branchConnectionOutputSchema = z.looseObject({
208
+ branch: Branch.describe("The created branch."),
209
+ endpoint: Endpoint.describe("The branch's read-write compute."),
210
+ connectionString: z.string().describe("Connection string for the branch's database.")
211
+ });
191
212
  const createBranchAndConnectTool = (options) => bindTool(options, {
192
213
  operationId: "branches.createAndConnect",
193
214
  id: publishedId("branches.createAndConnect"),
194
215
  title: "Create branch and connect",
195
216
  description: "Creates a branch with a read-write compute, waits until it is ready, and returns its connection string.",
196
217
  inputSchema: createBranchAndConnectInputSchema,
218
+ outputSchema: branchConnectionOutputSchema,
197
219
  annotations: writeAnnotations,
198
220
  requiresApproval: true,
199
221
  metadata: {
200
222
  method: "POST",
223
+ readOnlySafe: false,
224
+ secretOutputFields: [{
225
+ path: "$.connectionString",
226
+ kind: "setup"
227
+ }],
201
228
  path: "/projects/{project_id}/branches",
202
229
  stability: "stable",
203
230
  deprecated: false,
@@ -216,26 +243,38 @@ const createProjectTool = (options) => bindTool(options, {
216
243
  title: "Create project",
217
244
  description: "Creates a project with a default branch and read-write compute and waits until it is ready. Returns no connection string; use {{postgres.connectionString}}.",
218
245
  inputSchema: createProjectInputSchema,
246
+ outputSchema: Project,
219
247
  annotations: writeAnnotations,
220
248
  requiresApproval: true,
221
249
  metadata: {
222
250
  method: "POST",
251
+ readOnlySafe: false,
223
252
  path: "/projects",
224
253
  stability: "stable",
225
254
  deprecated: false,
226
255
  tags: ["Project"]
227
256
  }
228
257
  }, (neon, input, signal) => neon.projects.create(input, { signal }));
258
+ const projectConnectionOutputSchema = z.looseObject({
259
+ project: Project.describe("The created project."),
260
+ connectionString: z.string().describe("Connection string for the default branch's database.")
261
+ });
229
262
  const createProjectAndConnectTool = (options) => bindTool(options, {
230
263
  operationId: "projects.createAndConnect",
231
264
  id: publishedId("projects.createAndConnect"),
232
265
  title: "Create project and connect",
233
266
  description: "Creates a project, waits until its default branch is ready, and returns a connection string to it.",
234
267
  inputSchema: createProjectAndConnectInputSchema,
268
+ outputSchema: projectConnectionOutputSchema,
235
269
  annotations: writeAnnotations,
236
270
  requiresApproval: true,
237
271
  metadata: {
238
272
  method: "POST",
273
+ readOnlySafe: false,
274
+ secretOutputFields: [{
275
+ path: "$.connectionString",
276
+ kind: "setup"
277
+ }],
239
278
  path: "/projects",
240
279
  stability: "stable",
241
280
  deprecated: false,
@@ -248,10 +287,12 @@ const getDefaultTool = (options) => bindTool(options, {
248
287
  title: "Get default branch",
249
288
  description: "Gets the project's default branch by its default flag, not its name.",
250
289
  inputSchema: getDefaultInputSchema,
290
+ outputSchema: Branch,
251
291
  annotations: readAnnotations,
252
292
  requiresApproval: false,
253
293
  metadata: {
254
294
  method: "GET",
295
+ readOnlySafe: true,
255
296
  path: "/projects/{project_id}/branches",
256
297
  stability: "stable",
257
298
  deprecated: false,
@@ -264,10 +305,12 @@ const resetFromParentTool = (options) => bindTool(options, {
264
305
  title: "Reset branch from parent",
265
306
  description: "Resets a branch to its parent's current state, discarding the branch's own changes. NEVER run autonomously; always ask the user first. preserve_under_name first saves the current state as a new branch. To restore a snapshot, use {{snapshots.restore}}.",
266
307
  inputSchema: resetFromParentInputSchema,
308
+ outputSchema: Branch,
267
309
  annotations: writeAnnotations,
268
310
  requiresApproval: true,
269
311
  metadata: {
270
312
  method: "POST",
313
+ readOnlySafe: false,
271
314
  path: "/projects/{project_id}/branches/{branch_id}/restore",
272
315
  stability: "stable",
273
316
  deprecated: false,
@@ -284,10 +327,12 @@ const compareSchemaTool = (options) => bindTool(options, {
284
327
  title: "Compare database schema",
285
328
  description: "Diffs one database's SQL schema on a branch against another branch, by default its parent. lsn, timestamp, base_lsn, and base_timestamp are only for point-in-time comparisons.",
286
329
  inputSchema: compareSchemaInputSchema,
330
+ outputSchema: BranchSchemaCompareResponse,
287
331
  annotations: readAnnotations,
288
332
  requiresApproval: false,
289
333
  metadata: {
290
334
  method: "GET",
335
+ readOnlySafe: true,
291
336
  path: "/projects/{project_id}/branches/{branch_id}/compare_schema",
292
337
  stability: "stable",
293
338
  deprecated: false,
@@ -303,16 +348,24 @@ const compareSchemaTool = (options) => bindTool(options, {
303
348
  ...input.base_lsn === void 0 ? {} : { baseLsn: input.base_lsn },
304
349
  ...input.base_timestamp === void 0 ? {} : { baseTimestamp: input.base_timestamp }
305
350
  }, { signal }));
351
+ const connectionStringOutputSchema = z.string().describe("A postgresql:// connection string.");
306
352
  const connectionStringTool = (options) => bindTool(options, {
307
353
  operationId: "postgres.connectionString",
308
354
  id: publishedId("postgres.connectionString"),
309
355
  title: "Get connection string",
310
356
  description: "Returns a Postgres connection string with a role password; the branch needs a compute. Omitted inputs resolve like the SQL tools: default branch, neondb or the first database, and its owner. Call it after {{projects.create}} or {{branches.create}}, which return none.",
311
357
  inputSchema: connectionStringInputSchema,
358
+ outputSchema: connectionStringOutputSchema,
312
359
  annotations: readAnnotations,
313
360
  requiresApproval: true,
314
361
  metadata: {
315
362
  method: "GET",
363
+ readOnlySafe: false,
364
+ secretOutputFields: [{
365
+ path: "$",
366
+ kind: "setup"
367
+ }],
368
+ returnsOnlySecrets: true,
316
369
  path: "/projects/{project_id}/connection_uri",
317
370
  stability: "stable",
318
371
  deprecated: false,
@@ -331,10 +384,16 @@ const createRoleTool = (options) => bindTool(options, {
331
384
  title: "Create role",
332
385
  description: "Creates a Postgres role on a branch and returns its password. The default access, admin, joins neon_superuser: every database, creating databases and roles, bypassing row-level security, and it cannot be narrowed later. For least privilege pass read_only or read_write with database_name and schemas, covering the tables the database owner owns, now and later.",
333
386
  inputSchema: createRoleInputSchema,
387
+ outputSchema: Role,
334
388
  annotations: writeAnnotations,
335
389
  requiresApproval: true,
336
390
  metadata: {
337
391
  method: "POST",
392
+ readOnlySafe: false,
393
+ secretOutputFields: [{
394
+ path: "$.password",
395
+ kind: "setup"
396
+ }],
338
397
  path: "/projects/{project_id}/branches/{branch_id}/roles",
339
398
  stability: "stable",
340
399
  deprecated: false,
@@ -361,10 +420,12 @@ const restoreSnapshotTool = (options) => bindTool(options, {
361
420
  title: "Restore snapshot",
362
421
  description: "Restores a snapshot into a new branch and waits until it is ready. finalize true replaces target_branch_id (default: the snapshot's source branch) with it. NEVER finalize autonomously; ask the user first. Swap in later with {{branches.finalizeRestore}}.",
363
422
  inputSchema: restoreSnapshotInputSchema,
423
+ outputSchema: Branch,
364
424
  annotations: writeAnnotations,
365
425
  requiresApproval: true,
366
426
  metadata: {
367
427
  method: "POST",
428
+ readOnlySafe: false,
368
429
  path: "/projects/{project_id}/snapshots/{snapshot_id}/restore",
369
430
  stability: "stable",
370
431
  deprecated: false,
@@ -383,10 +444,12 @@ const setScheduleTool = (options) => bindTool(options, {
383
444
  title: "Set snapshot schedule",
384
445
  description: "Replaces a branch's automatic snapshot schedule.",
385
446
  inputSchema: setScheduleInputSchema,
447
+ outputSchema: z.null(),
386
448
  annotations: writeAnnotations,
387
449
  requiresApproval: true,
388
450
  metadata: {
389
451
  method: "PUT",
452
+ readOnlySafe: false,
390
453
  path: "/projects/{project_id}/branches/{branch_id}/backup_schedule",
391
454
  stability: "stable",
392
455
  deprecated: false,
@@ -11,5 +11,25 @@ export interface McpStandardSchema {
11
11
  validate: (value: unknown) => unknown;
12
12
  };
13
13
  }
14
+ export interface McpOutputSchemaOptions {
15
+ /**
16
+ * Field names the host removes from results before returning them, such as
17
+ * credentials. They are dropped from the schema at every level, so a result
18
+ * without them still validates.
19
+ */
20
+ omit?: readonly string[];
21
+ }
22
+ /**
23
+ * The JSON Schema MCP publishes for a tool's `structuredContent`:
24
+ * `{ data: <compact output schema> }`. Failed calls return `{ error }` with
25
+ * `isError`, which MCP does not validate.
26
+ */
27
+ export declare const toMcpOutputJsonSchema: (outputSchema: z.ZodType, options?: McpOutputSchemaOptions) => Record<string, unknown>;
28
+ /**
29
+ * Publishes {@link toMcpOutputJsonSchema} and validates `structuredContent`
30
+ * against that same compact schema, so the server rejects exactly what a
31
+ * validating client would. Validation returns the content unchanged.
32
+ */
33
+ export declare const toMcpOutputSchema: (outputSchema: z.ZodType, options?: McpOutputSchemaOptions) => McpStandardSchema;
14
34
  export declare const toMcpInputSchema: (schema: z.ZodType) => McpStandardSchema;
15
35
  //# sourceMappingURL=mcp-json-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-json-schema.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAKzB,eAAO,MAAM,iBAAiB,GAAI,MAAM,OAAO,KAAG,OAOjD,CAAC;AAMF,MAAM,WAAW,iBAAiB;IACjC,WAAW,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE;YACX,KAAK,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACrC,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACtC,CAAC;QACF,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;KACtC,CAAC;CACF;AAED,eAAO,MAAM,gBAAgB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,iBAiCpD,CAAC"}
1
+ {"version":3,"file":"mcp-json-schema.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-json-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAKzB,eAAO,MAAM,iBAAiB,GAAI,MAAM,OAAO,KAAG,OAOjD,CAAC;AAMF,MAAM,WAAW,iBAAiB;IACjC,WAAW,EAAE;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE;YACX,KAAK,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACrC,MAAM,EAAE,MAAM,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACtC,CAAC;QACF,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC;KACtC,CAAC;CACF;AAqHD,MAAM,WAAW,sBAAsB;IACtC;;;;OAIG;IACH,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB;AAED;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GACjC,cAAc,CAAC,CAAC,OAAO,EACvB,UAAS,sBAA2B,KAClC,MAAM,CAAC,MAAM,EAAE,OAAO,CAUvB,CAAC;AAEH;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC7B,cAAc,CAAC,CAAC,OAAO,EACvB,UAAS,sBAA2B,KAClC,iBAoBF,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,CAAC,CAAC,OAAO,KAAG,iBAiCpD,CAAC"}
@@ -8,6 +8,94 @@ const compactJsonSchema = (node) => {
8
8
  return rest;
9
9
  };
10
10
  const isStandardValidate = (value) => typeof value === "function";
11
+ /**
12
+ * Levels of `data` that keep their properties: the fields of `data`, or of each
13
+ * list item, are typed, and objects below them are `{ "type": "object" }`. Every
14
+ * listed level adds to `tools/list` for every tool and to what a validating
15
+ * client can reject.
16
+ */
17
+ const OUTPUT_PROPERTY_DEPTH = 1;
18
+ /** Levels of `data` that keep their descriptions. */
19
+ const OUTPUT_DESCRIPTION_DEPTH = 1;
20
+ const jsonType = (node) => {
21
+ const keys = Object.keys(node);
22
+ if (keys.length !== 1 || keys[0] !== "type") return;
23
+ return Array.isArray(node.type) ? node.type : [node.type];
24
+ };
25
+ const compactUnion = (members) => {
26
+ const unique = members.filter((member, index) => members.findIndex((other) => JSON.stringify(other) === JSON.stringify(member)) === index);
27
+ const types = unique.map((member) => isPlainObject(member) ? jsonType(member) : void 0);
28
+ if (types.every((type) => type !== void 0)) {
29
+ const flat = [...new Set(types.flat())];
30
+ return { type: flat.length === 1 ? flat[0] : flat };
31
+ }
32
+ return unique.length === 1 && isPlainObject(unique[0]) ? unique[0] : { anyOf: unique };
33
+ };
34
+ /**
35
+ * Types, properties, and required keys down to {@link OUTPUT_PROPERTY_DEPTH};
36
+ * descriptions down to {@link OUTPUT_DESCRIPTION_DEPTH}. Array items share their
37
+ * array's depth, so a list's items read like a single result. Formats, patterns,
38
+ * bounds, and `additionalProperties` are dropped: results may carry fields the
39
+ * spec does not list yet.
40
+ */
41
+ const compactOutputNode = (node, depth, omit) => {
42
+ if (!isPlainObject(node)) return node;
43
+ const out = {};
44
+ if (depth <= OUTPUT_DESCRIPTION_DEPTH && typeof node.description === "string") out.description = node.description;
45
+ if (node.type !== void 0) out.type = node.type;
46
+ if (Array.isArray(node.enum)) out.enum = node.enum;
47
+ if (node.const !== void 0) out.const = node.const;
48
+ const union = Array.isArray(node.anyOf) ? node.anyOf : Array.isArray(node.oneOf) ? node.oneOf : void 0;
49
+ if (union !== void 0) {
50
+ const members = union.map((member) => {
51
+ const compact = compactOutputNode(member, depth, omit);
52
+ if (!isPlainObject(compact)) return compact;
53
+ const { description, ...rest } = compact;
54
+ if (out.description === void 0 && typeof description === "string") out.description = description;
55
+ return rest;
56
+ });
57
+ Object.assign(out, compactUnion(members));
58
+ }
59
+ if (node.items !== void 0) out.items = compactOutputNode(node.items, depth, omit);
60
+ if (depth < OUTPUT_PROPERTY_DEPTH && isPlainObject(node.properties)) {
61
+ out.properties = Object.fromEntries(Object.entries(node.properties).filter(([key]) => !omit.has(key)).map(([key, value]) => [key, compactOutputNode(value, depth + 1, omit)]));
62
+ const required = Array.isArray(node.required) ? node.required.filter((key) => typeof key === "string" && !omit.has(key)) : [];
63
+ if (required.length > 0) out.required = required;
64
+ }
65
+ return out;
66
+ };
67
+ /**
68
+ * The JSON Schema MCP publishes for a tool's `structuredContent`:
69
+ * `{ data: <compact output schema> }`. Failed calls return `{ error }` with
70
+ * `isError`, which MCP does not validate.
71
+ */
72
+ const toMcpOutputJsonSchema = (outputSchema, options = {}) => ({
73
+ type: "object",
74
+ properties: { data: compactOutputNode(z.toJSONSchema(outputSchema, { io: "input" }), 0, new Set(options.omit)) },
75
+ required: ["data"]
76
+ });
77
+ /**
78
+ * Publishes {@link toMcpOutputJsonSchema} and validates `structuredContent`
79
+ * against that same compact schema, so the server rejects exactly what a
80
+ * validating client would. Validation returns the content unchanged.
81
+ */
82
+ const toMcpOutputSchema = (outputSchema, options = {}) => {
83
+ const json = toMcpOutputJsonSchema(outputSchema, options);
84
+ let validator;
85
+ return { "~standard": {
86
+ version: 1,
87
+ vendor: "neon",
88
+ jsonSchema: {
89
+ input: () => json,
90
+ output: () => json
91
+ },
92
+ validate: (value) => {
93
+ validator ??= z.fromJSONSchema(json);
94
+ const parsed = validator.safeParse(value);
95
+ return parsed.success ? { value } : { issues: parsed.error.issues };
96
+ }
97
+ } };
98
+ };
11
99
  const toMcpInputSchema = (schema) => {
12
100
  const json = compactJsonSchema(z.toJSONSchema(schema, { io: "input" }));
13
101
  if (!isPlainObject(json)) throw new TypeError("MCP tool input schemas must be JSON Schema objects");
@@ -27,4 +115,4 @@ const toMcpInputSchema = (schema) => {
27
115
  }
28
116
  } };
29
117
  };
30
- export { compactJsonSchema, toMcpInputSchema };
118
+ export { compactJsonSchema, toMcpInputSchema, toMcpOutputJsonSchema, toMcpOutputSchema };
@@ -10,5 +10,5 @@ export interface McpToolResult {
10
10
  export interface McpToolServer {
11
11
  registerTool: object;
12
12
  }
13
- export declare const registerNeonToolsWithSchema: (server: McpToolServer, tools: Readonly<Record<string, NeonTool>>, inputSchema: (tool: NeonTool) => unknown) => void;
13
+ export declare const registerNeonToolsWithSchema: (server: McpToolServer, tools: Readonly<Record<string, NeonTool>>, inputSchema: (tool: NeonTool) => unknown, outputSchema: (schema: NonNullable<NeonTool["outputSchema"]>) => unknown) => void;
14
14
  //# sourceMappingURL=mcp-register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp-register.d.ts","sourceRoot":"","sources":["../../src/lib/mcp-register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,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 @@ const createToolHandler = (tool) => async (input, context) => {
58
58
  };
59
59
  }
60
60
  };
61
- const registerNeonToolsWithSchema = (server, tools, inputSchema) => {
61
+ const registerNeonToolsWithSchema = (server, tools, inputSchema, outputSchema) => {
62
62
  if (typeof server.registerTool !== "function") throw new TypeError("Expected an MCP server with registerTool().");
63
63
  for (const tool of Object.values(tools)) Reflect.apply(server.registerTool, server, [
64
64
  tool.id,
@@ -66,6 +66,7 @@ const registerNeonToolsWithSchema = (server, tools, inputSchema) => {
66
66
  title: tool.title,
67
67
  description: tool.description,
68
68
  inputSchema: inputSchema(tool),
69
+ ...tool.outputSchema === void 0 ? {} : { outputSchema: outputSchema(tool.outputSchema) },
69
70
  annotations: tool.annotations,
70
71
  _meta: { "neon/requiresApproval": tool.requiresApproval }
71
72
  },
@@ -15,20 +15,62 @@ export interface NeonToolCaller {
15
15
  export interface NeonToolExecutionContext {
16
16
  signal?: AbortSignal;
17
17
  apiKey?: NeonBearerCredential;
18
- /** SQL tools run caller SQL in a `READ ONLY` transaction or refuse to run. */
18
+ /**
19
+ * Refuses every tool whose `metadata.readOnlySafe` is false. SQL tools run
20
+ * caller SQL in a `READ ONLY` transaction or refuse to run.
21
+ */
19
22
  readOnly?: boolean;
23
+ /**
24
+ * Which secrets results keep. A hidden secret reads `"***redacted***"`, and
25
+ * a tool whose `metadata.returnsOnlySecrets` result would be hidden refuses.
26
+ */
27
+ secrets?: NeonSecretsMode;
20
28
  /** Every SQL connection logs in as this Postgres role. */
21
29
  postgresRole?: string;
22
30
  /** Attribution sent with `docs.search` requests. */
23
31
  caller?: NeonToolCaller;
24
32
  }
25
- export interface NeonToolMetadata {
33
+ /**
34
+ * `setup`: a credential Neon issues for an app, CI job, or agent to use, such as
35
+ * a connection string, role password, or credential token.
36
+ * `stored`: a secret you gave Neon to call another service, such as an SMTP
37
+ * password or an OAuth provider's client secret.
38
+ */
39
+ export type NeonSecretKind = "setup" | "stored";
40
+ /** `all` keeps every secret, `setup` keeps only `setup` secrets, `none` keeps none. */
41
+ export type NeonSecretsMode = "all" | "setup" | "none";
42
+ export interface NeonSecretField {
43
+ /**
44
+ * `$` for the whole value, `.key` for a field, `[*]` for every array item,
45
+ * as in `$.oauth_providers[*].client_secret`.
46
+ */
47
+ path: string;
48
+ kind: NeonSecretKind;
49
+ }
50
+ export interface NeonOperationMetadata {
26
51
  method: string;
27
52
  path: string;
28
53
  stability: string;
29
54
  deprecated: boolean;
30
55
  tags: readonly string[];
31
56
  }
57
+ export interface NeonToolMetadata extends NeonOperationMetadata {
58
+ /**
59
+ * Changes no Neon resource and returns no connection string or role
60
+ * password. A tool that is not refuses to run when `readOnly` is true.
61
+ */
62
+ readOnlySafe: boolean;
63
+ /** Where the result carries a secret, and what kind it is. */
64
+ secretOutputFields: readonly NeonSecretField[];
65
+ /**
66
+ * The result is the secret itself: a read of an existing secret, or a
67
+ * rotation that returns the replacement. Refused when `secrets` hides it.
68
+ */
69
+ returnsOnlySecrets: boolean;
70
+ }
71
+ /** Literal tool metadata; the secret fields default to none. */
72
+ export type NeonToolMetadataInput = Omit<NeonToolMetadata, "secretOutputFields" | "returnsOnlySecrets"> & Partial<Pick<NeonToolMetadata, "secretOutputFields" | "returnsOnlySecrets">>;
73
+ export declare const toolMetadata: (metadata: NeonToolMetadataInput) => NeonToolMetadata;
32
74
  export interface JsonSafeBlob {
33
75
  base64: string;
34
76
  contentType: string;
@@ -40,12 +82,17 @@ export type JsonSafe<Value> = unknown extends Value ? unknown : Value extends nu
40
82
  export interface NeonToolResult<Data = unknown> {
41
83
  data: Data;
42
84
  }
43
- export interface NeonTool<InputSchema extends z.ZodType = z.ZodType, Id extends string = string, Output = unknown> {
85
+ export interface NeonTool<InputSchema extends z.ZodType = z.ZodType, Id extends string = string, Output = unknown, OutputSchema extends z.ZodType = z.ZodType> {
44
86
  operationId: string;
45
87
  id: Id;
46
88
  title: string;
47
89
  description: string;
48
90
  inputSchema: InputSchema;
91
+ /**
92
+ * The shape of `execute()`'s `data`. It describes results; it does not
93
+ * validate them. Every catalog tool has one; hand-built tools may omit it.
94
+ */
95
+ outputSchema?: OutputSchema;
49
96
  annotations: NeonToolAnnotations;
50
97
  requiresApproval: boolean;
51
98
  metadata: NeonToolMetadata;
@@ -59,9 +106,13 @@ export interface NeonOperation<InputSchema extends z.ZodType, Id extends string
59
106
  inputSchema: InputSchema;
60
107
  annotations: NeonToolAnnotations;
61
108
  requiresApproval: boolean;
62
- metadata: NeonToolMetadata;
109
+ metadata: NeonOperationMetadata;
63
110
  invoke(client: Client, input: z.output<InputSchema>, signal?: AbortSignal): Promise<Output>;
64
111
  }
65
112
  export declare const defineOperation: <const InputSchema extends z.ZodType, const Id extends string, Output>(operation: NeonOperation<InputSchema, Id, Output>) => NeonOperation<InputSchema, Id, Output>;
66
- export declare const bindOperation: <const InputSchema extends z.ZodType, const Id extends string, Output>(operation: NeonOperation<InputSchema, Id, Output>, client: Client) => NeonTool<InputSchema, Id, JsonSafe<Awaited<Output>>>;
113
+ /** A generated operation bound to a client. `fromGenerated` adds the tool policy. */
114
+ export type NeonOperationTool<InputSchema extends z.ZodType = z.ZodType, Id extends string = string, Output = unknown> = Omit<NeonTool<InputSchema, Id, Output>, "metadata"> & {
115
+ metadata: NeonOperationMetadata;
116
+ };
117
+ export declare const bindOperation: <const InputSchema extends z.ZodType, const Id extends string, Output>(operation: NeonOperation<InputSchema, Id, Output>, client: Client) => NeonOperationTool<InputSchema, Id, JsonSafe<Awaited<Output>>>;
67
118
  //# sourceMappingURL=operation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/lib/operation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,eAAe,CAAC;AAC1D,OAAO,KAAK,KAAK,CAAC,MAAM,KAAK,CAAC;AAC9B,OAAO,EAAE,KAAK,oBAAoB,EAA2B,MAAM,WAAW,CAAC;AAG/E,MAAM,WAAW,mBAAmB;IACnC,YAAY,EAA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AE,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAsB7D,CAAC"}
@@ -2,6 +2,11 @@ import { requireBearerCredential } from "./auth.js";
2
2
  import { toToolResult } from "./result.js";
3
3
  import { createClient } from "@neon/sdk/raw";
4
4
  // src/lib/operation.ts
5
+ const toolMetadata = (metadata) => ({
6
+ ...metadata,
7
+ secretOutputFields: metadata.secretOutputFields ?? [],
8
+ returnsOnlySecrets: metadata.returnsOnlySecrets ?? false
9
+ });
5
10
  const defineOperation = (operation) => operation;
6
11
  const bindOperation = (operation, client) => ({
7
12
  operationId: operation.operationId,
@@ -26,4 +31,4 @@ const clientWithCredential = (client, apiKey) => {
26
31
  auth: requireBearerCredential(apiKey)
27
32
  });
28
33
  };
29
- export { bindOperation, defineOperation };
34
+ export { bindOperation, defineOperation, toolMetadata };
@@ -0,0 +1,24 @@
1
+ import type { NeonSecretField, NeonSecretsMode, NeonTool, NeonToolExecutionContext, NeonToolMetadata } from "./operation.js";
2
+ export interface NeonToolPolicyOptions {
3
+ /** The default for `readOnly` in every execution context. */
4
+ readOnly?: boolean;
5
+ /** The default for `secrets` in every execution context; `"all"` when unset. */
6
+ secrets?: NeonSecretsMode;
7
+ }
8
+ /** What a `tools` predicate sees: a tool without its `execute`. */
9
+ export type NeonToolDescriptor = Pick<NeonTool, "operationId" | "id" | "title" | "description" | "annotations" | "requiresApproval" | "metadata">;
10
+ export type NeonToolPredicate = (tool: NeonToolDescriptor) => boolean;
11
+ export declare const toolDescriptor: (tool: NeonTool) => NeonToolDescriptor;
12
+ export type NeonToolCallGuard = (context?: NeonToolExecutionContext) => void;
13
+ /** The secret fields `mode` replaces with `REDACTED_SECRET`. */
14
+ export declare const hiddenSecretFields: (metadata: Pick<NeonToolMetadata, "secretOutputFields">, mode: NeonSecretsMode) => NeonSecretField[];
15
+ /** The tool refuses under `mode` because its whole result would be hidden. */
16
+ export declare const withheldUnderSecrets: (metadata: Pick<NeonToolMetadata, "secretOutputFields" | "returnsOnlySecrets">, mode: NeonSecretsMode) => boolean;
17
+ /** Throws for a call the effective policy forbids. */
18
+ export declare const toolCallGuard: (tool: NeonTool, options: NeonToolPolicyOptions, publishedId: string) => NeonToolCallGuard;
19
+ /**
20
+ * SQL tools read the effective `readOnly` to open a `READ ONLY` transaction.
21
+ * Redaction runs inside `onExecute`, so a tracking hook sees the redacted result.
22
+ */
23
+ export declare const applyToolPolicy: <Tool extends NeonTool>(tool: Tool, options: NeonToolPolicyOptions, guard: NeonToolCallGuard) => Tool;
24
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/lib/policy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACX,eAAe,EACf,eAAe,EACf,QAAQ,EACR,wBAAwB,EACxB,gBAAgB,EAChB,MAAM,gBAAgB,CAAC;AAGxB,MAAM,WAAW,qBAAqB;IACrC,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gFAAgF;IAChF,OAAO,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,mEAAmE;AACnE,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACpC,QAAQ,EACN,aAAa,GACb,IAAI,GACJ,OAAO,GACP,aAAa,GACb,aAAa,GACb,kBAAkB,GAClB,UAAU,CACZ,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,kBAAkB,KAAK,OAAO,CAAC;AAEtE,eAAO,MAAM,cAAc,GAAI,MAAM,QAAQ,KAAG,kBAQ9C,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,CAAC,EAAE,wBAAwB,KAAK,IAAI,CAAC;AAU7E,gEAAgE;AAChE,eAAO,MAAM,kBAAkB,GAC9B,UAAU,IAAI,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,EACtD,MAAM,eAAe,KACnB,eAAe,EACgD,CAAC;AAEnE,8EAA8E;AAC9E,eAAO,MAAM,oBAAoB,GAChC,UAAU,IAAI,CACb,gBAAgB,EAChB,oBAAoB,GAAG,oBAAoB,CAC3C,EACD,MAAM,eAAe,KACnB,OAE2C,CAAC;AAE/C,sDAAsD;AACtD,eAAO,MAAM,aAAa,GAExB,MAAM,QAAQ,EACd,SAAS,qBAAqB,EAC9B,aAAa,MAAM,KACjB,iBAcF,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,eAAe,GAAI,IAAI,SAAS,QAAQ,EACpD,MAAM,IAAI,EACV,SAAS,qBAAqB,EAC9B,OAAO,iBAAiB,KACtB,IA2BF,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { redactSecretFields } from "./redact.js";
2
+ import { NeonClientError } from "@neon/sdk";
3
+ // src/lib/policy.ts
4
+ const toolDescriptor = (tool) => ({
5
+ operationId: tool.operationId,
6
+ id: tool.id,
7
+ title: tool.title,
8
+ description: tool.description,
9
+ annotations: tool.annotations,
10
+ requiresApproval: tool.requiresApproval,
11
+ metadata: tool.metadata
12
+ });
13
+ const secretsMode = (options, context) => context?.secrets ?? options.secrets ?? "all";
14
+ const hides = (mode, field) => mode === "none" || mode === "setup" && field.kind !== "setup";
15
+ /** The secret fields `mode` replaces with `REDACTED_SECRET`. */
16
+ const hiddenSecretFields = (metadata, mode) => metadata.secretOutputFields.filter((field) => hides(mode, field));
17
+ /** The tool refuses under `mode` because its whole result would be hidden. */
18
+ const withheldUnderSecrets = (metadata, mode) => metadata.returnsOnlySecrets && hiddenSecretFields(metadata, mode).length > 0;
19
+ /** Throws for a call the effective policy forbids. */
20
+ const toolCallGuard = (tool, options, publishedId) => (context) => {
21
+ if ((context?.readOnly ?? options.readOnly) === true && !tool.metadata.readOnlySafe) throw new NeonClientError(`${publishedId} is unavailable in read-only mode because it can change Neon resources or returns a connection string or role password.`);
22
+ const secrets = secretsMode(options, context);
23
+ if (withheldUnderSecrets(tool.metadata, secrets)) throw new NeonClientError(`${publishedId} is unavailable with secrets: "${secrets}" because its result is a secret.`);
24
+ };
25
+ /**
26
+ * SQL tools read the effective `readOnly` to open a `READ ONLY` transaction.
27
+ * Redaction runs inside `onExecute`, so a tracking hook sees the redacted result.
28
+ */
29
+ const applyToolPolicy = (tool, options, guard) => {
30
+ const execute = tool.execute.bind(tool);
31
+ return {
32
+ ...tool,
33
+ execute: async (input, context) => {
34
+ guard(context);
35
+ const readOnly = context?.readOnly ?? options.readOnly;
36
+ const result = await execute(input, readOnly === void 0 ? context : {
37
+ ...context,
38
+ readOnly
39
+ });
40
+ const hidden = hiddenSecretFields(tool.metadata, secretsMode(options, context));
41
+ if (hidden.length === 0) return result;
42
+ return {
43
+ ...result,
44
+ data: redactSecretFields(result.data, hidden.map((field) => field.path))
45
+ };
46
+ }
47
+ };
48
+ };
49
+ export { applyToolPolicy, hiddenSecretFields, toolCallGuard, toolDescriptor, withheldUnderSecrets };
@@ -0,0 +1,8 @@
1
+ export declare const REDACTED_SECRET = "***redacted***";
2
+ /**
3
+ * Replaces every non-empty string at `paths` with `REDACTED_SECRET`. An absent,
4
+ * null, or empty value is left as is, so "no secret" stays distinguishable
5
+ * from "redacted". A path that meets a different shape throws.
6
+ */
7
+ export declare const redactSecretFields: (data: unknown, paths: readonly string[]) => unknown;
8
+ //# sourceMappingURL=redact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redact.d.ts","sourceRoot":"","sources":["../../src/lib/redact.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,mBAAmB,CAAC;AAwDhD;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC9B,MAAM,OAAO,EACb,OAAO,SAAS,MAAM,EAAE,KACtB,OAID,CAAC"}