@onlyflows/servicenow-mcp 2.3.0-dev.1 → 2.3.0-dev.3

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/CHANGELOG.md +447 -3
  2. package/README.md +241 -11
  3. package/dist/call-metrics.d.ts +42 -0
  4. package/dist/call-metrics.d.ts.map +1 -0
  5. package/dist/call-metrics.js +89 -0
  6. package/dist/call-metrics.js.map +1 -0
  7. package/dist/client.d.ts +18 -14
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +51 -36
  10. package/dist/client.js.map +1 -1
  11. package/dist/code-search-snippet.d.ts +25 -0
  12. package/dist/code-search-snippet.d.ts.map +1 -0
  13. package/dist/code-search-snippet.js +67 -0
  14. package/dist/code-search-snippet.js.map +1 -0
  15. package/dist/code-search-targets.d.ts +66 -0
  16. package/dist/code-search-targets.d.ts.map +1 -0
  17. package/dist/code-search-targets.js +82 -0
  18. package/dist/code-search-targets.js.map +1 -0
  19. package/dist/encoded-query-policy.d.ts +9 -0
  20. package/dist/encoded-query-policy.d.ts.map +1 -1
  21. package/dist/encoded-query-policy.js +19 -1
  22. package/dist/encoded-query-policy.js.map +1 -1
  23. package/dist/field-policy.d.ts.map +1 -1
  24. package/dist/field-policy.js +17 -5
  25. package/dist/field-policy.js.map +1 -1
  26. package/dist/http-observability.js +1 -0
  27. package/dist/http-observability.js.map +1 -1
  28. package/dist/http-runtime.js +16 -0
  29. package/dist/http-runtime.js.map +1 -1
  30. package/dist/metadata-cache.d.ts +97 -7
  31. package/dist/metadata-cache.d.ts.map +1 -1
  32. package/dist/metadata-cache.js +284 -21
  33. package/dist/metadata-cache.js.map +1 -1
  34. package/dist/policy-card.js +1 -1
  35. package/dist/policy-card.js.map +1 -1
  36. package/dist/response-too-large.d.ts +23 -0
  37. package/dist/response-too-large.d.ts.map +1 -0
  38. package/dist/response-too-large.js +42 -0
  39. package/dist/response-too-large.js.map +1 -0
  40. package/dist/risky-grants.d.ts.map +1 -1
  41. package/dist/risky-grants.js +1 -0
  42. package/dist/risky-grants.js.map +1 -1
  43. package/dist/setup-prompts.js +1 -1
  44. package/dist/setup-prompts.js.map +1 -1
  45. package/dist/setup.d.ts.map +1 -1
  46. package/dist/setup.js +28 -4
  47. package/dist/setup.js.map +1 -1
  48. package/dist/structured-query.d.ts +61 -2
  49. package/dist/structured-query.d.ts.map +1 -1
  50. package/dist/structured-query.js +376 -35
  51. package/dist/structured-query.js.map +1 -1
  52. package/dist/table-policy.d.ts +42 -2
  53. package/dist/table-policy.d.ts.map +1 -1
  54. package/dist/table-policy.js +90 -6
  55. package/dist/table-policy.js.map +1 -1
  56. package/dist/tool-error.d.ts +40 -4
  57. package/dist/tool-error.d.ts.map +1 -1
  58. package/dist/tool-error.js +81 -4
  59. package/dist/tool-error.js.map +1 -1
  60. package/dist/tool-table-access.d.ts +9 -2
  61. package/dist/tool-table-access.d.ts.map +1 -1
  62. package/dist/tool-table-access.js +93 -30
  63. package/dist/tool-table-access.js.map +1 -1
  64. package/dist/tools/batch.d.ts.map +1 -1
  65. package/dist/tools/batch.js +21 -5
  66. package/dist/tools/batch.js.map +1 -1
  67. package/dist/tools/catalog.d.ts.map +1 -1
  68. package/dist/tools/catalog.js +2 -1
  69. package/dist/tools/catalog.js.map +1 -1
  70. package/dist/tools/codesearch.d.ts +2 -2
  71. package/dist/tools/codesearch.d.ts.map +1 -1
  72. package/dist/tools/codesearch.js +536 -67
  73. package/dist/tools/codesearch.js.map +1 -1
  74. package/dist/tools/flow-view-contracts.d.ts +2 -2
  75. package/dist/tools/flow-view-module.js +1 -1
  76. package/dist/tools/flow-view-module.js.map +1 -1
  77. package/dist/tools/get-module.js +1 -1
  78. package/dist/tools/get-module.js.map +1 -1
  79. package/dist/tools/index.d.ts.map +1 -1
  80. package/dist/tools/index.js +37 -13
  81. package/dist/tools/index.js.map +1 -1
  82. package/dist/tools/query-module.d.ts.map +1 -1
  83. package/dist/tools/query-module.js +230 -63
  84. package/dist/tools/query-module.js.map +1 -1
  85. package/dist/tools/result-envelope.d.ts +313 -2
  86. package/dist/tools/result-envelope.d.ts.map +1 -1
  87. package/dist/tools/result-envelope.js +334 -33
  88. package/dist/tools/result-envelope.js.map +1 -1
  89. package/dist/tools/schema-module.d.ts.map +1 -1
  90. package/dist/tools/schema-module.js +1 -1
  91. package/dist/tools/schema-module.js.map +1 -1
  92. package/dist/tools/truncation-hint.d.ts +125 -0
  93. package/dist/tools/truncation-hint.d.ts.map +1 -0
  94. package/dist/tools/truncation-hint.js +298 -0
  95. package/dist/tools/truncation-hint.js.map +1 -0
  96. package/dist/unknown-filter-fields.d.ts +52 -0
  97. package/dist/unknown-filter-fields.d.ts.map +1 -0
  98. package/dist/unknown-filter-fields.js +87 -0
  99. package/dist/unknown-filter-fields.js.map +1 -0
  100. package/dist/version.d.ts +1 -1
  101. package/dist/version.js +1 -1
  102. package/docs/CLIENT-SETUP.md +22 -1
  103. package/docs/PRODUCTION-SECURITY.md +21 -1
  104. package/docs/V2-MIGRATION.md +1 -1
  105. package/package.json +1 -1
  106. package/server.json +2 -2
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ /**
3
+ * The recovery hint on a byte-truncated record list.
4
+ *
5
+ * Two stages can drop rows from one response: the tool's own budget check and,
6
+ * after the shared envelope adds its metadata, the envelope's fit. The first
7
+ * writes the hint; the second changes how many rows were dropped and knows
8
+ * what the envelope itself costs. The text is therefore built and parsed here,
9
+ * in one place, so the envelope can rewrite the counts, the continuation (the
10
+ * offset of the first row not returned, which is `next_offset`) and the byte
11
+ * budget that would hold the next row from its final state, and the hint and
12
+ * the fields beside it never disagree. Rendering and parsing are covered by
13
+ * one round-trip test.
14
+ *
15
+ * The hint is a list of fixed clauses joined by "; ", each matched on its own
16
+ * by an anchored pattern, so only text this module wrote is ever rewritten:
17
+ *
18
+ * Dropped 14/22; continue offset=8 limit=8; retry offset=0 with
19
+ * fields="sys_id,name" or max_response_bytes=1500 (fits the next row) or
20
+ * max_response_bytes=31500 (fits all 22).
21
+ *
22
+ * The two budgets are different numbers and the text says which is which:
23
+ * the first holds one more row than this response did (each retry with it
24
+ * buys a row), the second the whole window. The second is left out when it is
25
+ * the first (one row dropped) or when it is more than the maximum.
26
+ *
27
+ * @module truncation-hint
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.neededResponseBytes = neededResponseBytes;
31
+ exports.renderTruncationHint = renderTruncationHint;
32
+ exports.parseTruncationHint = parseTruncationHint;
33
+ exports.refreshTruncationHint = refreshTruncationHint;
34
+ exports.restateContinuationHint = restateContinuationHint;
35
+ const utils_js_1 = require("../utils.js");
36
+ const HINT_MAX_LENGTH = 600;
37
+ /**
38
+ * Bytes added to the measured size of the next row's response before it is
39
+ * offered as `max_response_bytes`, so that a budget with a longer digit count
40
+ * or a slightly longer hint still holds it.
41
+ */
42
+ const NEEDED_BYTES_SLACK = 64;
43
+ const NEEDED_BYTES_STEP = 100;
44
+ /**
45
+ * `max_response_bytes` that would hold the next row: the measured size of the
46
+ * response with that row (`measured`) plus a small margin, rounded up to a
47
+ * whole {@link NEEDED_BYTES_STEP} (but never past `cap`), and always above the
48
+ * budget just used (`current`). Infinity when that is more than `cap`: no
49
+ * value the caller may use would hold the row. `cap` is the largest budget the
50
+ * schema accepts, or less when a raw-read rule holds the call to a smaller one.
51
+ */
52
+ function neededResponseBytes(measured, current, cap = utils_js_1.MAX_RESPONSE_BYTES_MAX) {
53
+ const padded = Math.max(measured + NEEDED_BYTES_SLACK, current + 1, utils_js_1.MAX_RESPONSE_BYTES_MIN);
54
+ if (padded > cap)
55
+ return Number.POSITIVE_INFINITY;
56
+ return Math.min(Math.ceil(padded / NEEDED_BYTES_STEP) * NEEDED_BYTES_STEP, cap);
57
+ }
58
+ /** What a hint names for the rows that fit: the continuation and the `limit` to use. */
59
+ function returnedRows(parts) {
60
+ return parts.total - parts.dropped;
61
+ }
62
+ const EMPTY_CLAUSE = "row too large";
63
+ const NEXT_ROW_NOTE = " (fits the next row)";
64
+ function allRowsNote(total) {
65
+ return ` (fits all ${total})`;
66
+ }
67
+ const SN_GET_OPTION = "sn_get";
68
+ function overMaximumClause(cap) {
69
+ return `the next row exceeds the maximum max_response_bytes (${cap})`;
70
+ }
71
+ function renderHint(parts, withAdvice) {
72
+ const returned = returnedRows(parts);
73
+ const empty = returned <= 0;
74
+ const over = !Number.isFinite(parts.neededBytes) || parts.widest === true;
75
+ // With one row dropped the next row is the whole remainder: one figure.
76
+ const nextRow = parts.widest === true
77
+ ? `max_response_bytes=${utils_js_1.MAX_RESPONSE_BYTES_MAX}${NEXT_ROW_NOTE}`
78
+ : Number.isFinite(parts.neededBytes)
79
+ ? `max_response_bytes=${parts.neededBytes}${NEXT_ROW_NOTE}`
80
+ : undefined;
81
+ const allBytes = parts.dropped > 1 ? parts.allBytes : undefined;
82
+ const options = [
83
+ withAdvice ? parts.advice : undefined,
84
+ nextRow,
85
+ allBytes === undefined
86
+ ? undefined
87
+ // Infinity is the widest form, used while fitting (see finalizeSummaryResult).
88
+ : `max_response_bytes=${Number.isFinite(allBytes) ? allBytes : utils_js_1.MAX_RESPONSE_BYTES_MAX}${allRowsNote(parts.total)}`,
89
+ // When no row fits, a narrower page cannot help; the single-record read can.
90
+ empty ? SN_GET_OPTION : undefined,
91
+ ].filter((option) => option !== undefined);
92
+ const clauses = [`Dropped ${parts.dropped}/${parts.total}`];
93
+ if (empty)
94
+ clauses.push(EMPTY_CLAUSE);
95
+ else
96
+ clauses.push(`continue offset=${parts.offset + returned} limit=${returned}`);
97
+ if (over)
98
+ clauses.push(overMaximumClause(parts.capBytes ?? utils_js_1.MAX_RESPONSE_BYTES_MAX));
99
+ if (options.length > 0) {
100
+ clauses.push(`retry offset=${parts.offset} with ${options.join(" or ")}`);
101
+ }
102
+ return `${clauses.join("; ")}.`;
103
+ }
104
+ /**
105
+ * Render the hint. When no row is left, the row itself exceeds the budget, so
106
+ * a lower limit cannot help and the single-record read is offered instead.
107
+ * Field advice that would push the hint past its length limit, in its widest
108
+ * form, is left out, so the hint always parses back and a longer real text
109
+ * never replaces a shorter one that was used to size the rows.
110
+ */
111
+ function renderTruncationHint(parts) {
112
+ // Whether the advice fits is decided once, from the widest rendering of
113
+ // these parts (the "exceeds the maximum" clause with a 7-digit next-row
114
+ // figure, and a 7-digit page figure: no real figures make a longer text). A
115
+ // fit sizes rows with that widest text and then swaps in the real one, so the
116
+ // two must make the same choice: if the widest dropped the advice and the
117
+ // real text kept it, the real text could be hundreds of characters longer
118
+ // than the one the rows were sized for. The page figure is always in this
119
+ // text, whether or not the real text has one (it has none when the page is
120
+ // over the cap, and a form without it is sized with the same decision), so
121
+ // the choice depends only on what the probe and the real text share.
122
+ const widest = renderHint({
123
+ ...parts,
124
+ widest: true,
125
+ neededBytes: Number.POSITIVE_INFINITY,
126
+ allBytes: Number.POSITIVE_INFINITY,
127
+ }, true);
128
+ return renderHint(parts, widest.length <= HINT_MAX_LENGTH);
129
+ }
130
+ const DROPPED_CLAUSE = /^Dropped (\d+)\/(\d+)$/u;
131
+ const CONTINUE_CLAUSE = /^continue offset=(\d+) limit=(\d+)$/u;
132
+ const RETRY_CLAUSE = /^retry offset=(\d+) with (.+)$/u;
133
+ const ADVICE_OPTION = /^(?:fields="[a-z][a-z0-9_]*(?:,[a-z][a-z0-9_]*)*"|response_format="concise")$/u;
134
+ const NEXT_ROW_OPTION = /^max_response_bytes=([1-9]\d{3,6}) \(fits the next row\)$/u;
135
+ const ALL_ROWS_OPTION = /^max_response_bytes=([1-9]\d{3,6}) \(fits all ([1-9]\d{0,15})\)$/u;
136
+ const OVER_MAXIMUM = /^the next row exceeds the maximum max_response_bytes \(([1-9]\d{3,6})\)$/u;
137
+ /** A byte value the schema could accept: 1000 to 1,000,000. */
138
+ function budgetValue(digits) {
139
+ const value = Number(digits);
140
+ return Number.isSafeInteger(value) && value >= utils_js_1.MAX_RESPONSE_BYTES_MIN && value <= utils_js_1.MAX_RESPONSE_BYTES_MAX
141
+ ? value
142
+ : undefined;
143
+ }
144
+ /** Read back a hint {@link renderTruncationHint} wrote; anything else is undefined. */
145
+ function parseTruncationHint(hint) {
146
+ if (hint.length > HINT_MAX_LENGTH || !hint.endsWith("."))
147
+ return undefined;
148
+ const clauses = hint.slice(0, -1).split("; ");
149
+ let index = 0;
150
+ const dropped = DROPPED_CLAUSE.exec(clauses[index++] ?? "");
151
+ if (dropped === null)
152
+ return undefined;
153
+ const droppedCount = Number(dropped[1]);
154
+ const total = Number(dropped[2]);
155
+ if (!Number.isSafeInteger(droppedCount) || !Number.isSafeInteger(total) || droppedCount > total) {
156
+ return undefined;
157
+ }
158
+ const returned = total - droppedCount;
159
+ const empty = returned === 0;
160
+ let offset;
161
+ if (empty) {
162
+ if (clauses[index++] !== EMPTY_CLAUSE)
163
+ return undefined;
164
+ }
165
+ else {
166
+ const next = CONTINUE_CLAUSE.exec(clauses[index++] ?? "");
167
+ // The clause restates numbers the counts already fix; a hint that
168
+ // disagrees with itself was not written here.
169
+ if (next === null || Number(next[2]) !== returned)
170
+ return undefined;
171
+ offset = Number(next[1]) - returned;
172
+ }
173
+ let neededBytes;
174
+ let allBytes;
175
+ let capBytes;
176
+ const over = OVER_MAXIMUM.exec(clauses[index] ?? "");
177
+ if (over !== null) {
178
+ capBytes = budgetValue(over[1]);
179
+ if (capBytes === undefined)
180
+ return undefined;
181
+ neededBytes = Number.POSITIVE_INFINITY;
182
+ index += 1;
183
+ }
184
+ let advice;
185
+ let sawSnGet = false;
186
+ const retry = clauses[index] === undefined ? null : RETRY_CLAUSE.exec(clauses[index] ?? "");
187
+ if (retry !== null) {
188
+ index += 1;
189
+ const retryOffset = Number(retry[1]);
190
+ if (offset !== undefined && offset !== retryOffset)
191
+ return undefined;
192
+ offset = retryOffset;
193
+ for (const option of (retry[2] ?? "").split(" or ")) {
194
+ const next = NEXT_ROW_OPTION.exec(option);
195
+ const all = next === null ? ALL_ROWS_OPTION.exec(option) : null;
196
+ if (next !== null) {
197
+ const value = budgetValue(next[1]);
198
+ if (neededBytes !== undefined || value === undefined)
199
+ return undefined;
200
+ neededBytes = value;
201
+ }
202
+ else if (all !== null) {
203
+ const value = budgetValue(all[1]);
204
+ // The count restates the window; the figure must follow the next-row
205
+ // one, be no smaller, and exist only when more than one row is left.
206
+ if (allBytes !== undefined ||
207
+ value === undefined ||
208
+ Number(all[2]) !== total ||
209
+ droppedCount < 2 ||
210
+ neededBytes === undefined ||
211
+ !Number.isFinite(neededBytes) ||
212
+ value < neededBytes) {
213
+ return undefined;
214
+ }
215
+ allBytes = value;
216
+ }
217
+ else if (ADVICE_OPTION.test(option) && advice === undefined) {
218
+ advice = option;
219
+ }
220
+ else if (option === SN_GET_OPTION && !sawSnGet) {
221
+ sawSnGet = true;
222
+ }
223
+ else {
224
+ return undefined;
225
+ }
226
+ }
227
+ }
228
+ if (index !== clauses.length ||
229
+ offset === undefined ||
230
+ neededBytes === undefined ||
231
+ sawSnGet !== empty ||
232
+ !Number.isSafeInteger(offset) ||
233
+ offset < 0) {
234
+ return undefined;
235
+ }
236
+ // One row dropped: the next row is the whole remainder, written once.
237
+ if (droppedCount === 1 && Number.isFinite(neededBytes))
238
+ allBytes = neededBytes;
239
+ return {
240
+ dropped: droppedCount,
241
+ total,
242
+ offset,
243
+ ...(advice === undefined ? {} : { advice }),
244
+ neededBytes,
245
+ ...(allBytes === undefined ? {} : { allBytes }),
246
+ ...(capBytes === undefined ? {} : { capBytes }),
247
+ };
248
+ }
249
+ /**
250
+ * Restate a hint for the response's final state: how many rows were dropped
251
+ * from the window, so where to continue and which `limit` fits, and, when the
252
+ * caller supplies it, the byte budget that would hold the next row. Only hints
253
+ * this module wrote are touched; any other text is returned as it came.
254
+ */
255
+ function refreshTruncationHint(hint, final) {
256
+ const parts = parseTruncationHint(hint);
257
+ if (parts === undefined)
258
+ return hint;
259
+ return renderTruncationHint({
260
+ dropped: final.dropped,
261
+ total: final.dropped + final.returned,
262
+ offset: parts.offset,
263
+ ...(parts.advice === undefined || final.withoutAdvice === true ? {} : { advice: parts.advice }),
264
+ neededBytes: final.neededBytes ?? parts.neededBytes,
265
+ ...(final.widest === true ? { widest: true } : {}),
266
+ ...(final.allBytes === null || (final.allBytes ?? parts.allBytes) === undefined
267
+ ? {}
268
+ : { allBytes: (final.allBytes ?? parts.allBytes) }),
269
+ ...(final.capBytes ?? parts.capBytes) === undefined
270
+ ? {}
271
+ : { capBytes: (final.capBytes ?? parts.capBytes) },
272
+ });
273
+ }
274
+ /**
275
+ * The continuation hint a paging tool writes when nothing was dropped:
276
+ * "More records available. Call sn_query again with offset=22." (an
277
+ * all-fields notice may follow). A tool writes it from the page it fetched, so
278
+ * when the shared envelope later drops rows for size, its offset is stale.
279
+ */
280
+ const CONTINUATION_HINT = /^(More records available\. Call sn_[a-z_]+ again with offset=)\d+(\.)((?: .*)?)$/su;
281
+ /**
282
+ * Restate a continuation hint for the final paging state: the offset of the
283
+ * first row not returned, or, when no row fit and there is none, the plain
284
+ * instruction that the request must change. Text that is not a continuation
285
+ * hint comes back as it was.
286
+ */
287
+ function restateContinuationHint(hint, final) {
288
+ const match = CONTINUATION_HINT.exec(hint);
289
+ if (match === null)
290
+ return hint;
291
+ const notice = match[3] ?? "";
292
+ if (final.nextOffset === undefined) {
293
+ return ("More records available, but no row fit; adjust the request (fewer fields, " +
294
+ `a lower limit or a higher max_response_bytes) and retry offset=${final.offset}.${notice}`);
295
+ }
296
+ return `${match[1]}${final.nextOffset}.${notice}`;
297
+ }
298
+ //# sourceMappingURL=truncation-hint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"truncation-hint.js","sourceRoot":"","sources":["../../src/tools/truncation-hint.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAsBH,kDAQC;AAuGD,oDAqBC;AAoBD,kDA8FC;AAQD,sDAmCC;AAiBD,0DAcC;AApVD,0CAA6E;AAE7E,MAAM,eAAe,GAAG,GAAG,CAAC;AAE5B;;;;GAIG;AACH,MAA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pD,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Refuse a filter or order on a field the table does not have.
3
+ *
4
+ * ServiceNow drops a condition on a column it does not know, unless the
5
+ * instance sets glide.invalid_query.returns_no_rows (off by default and not a
6
+ * setting this server can rely on). A misspelt field therefore does not match
7
+ * nothing: the rest of the query runs and unrelated rows come back.
8
+ *
9
+ * The check costs no request. A column named in sysparm_fields that the table
10
+ * does not have, or that the integration user may not read, is left out of
11
+ * every row, so the filter's own fields are asked for on the read that is
12
+ * made anyway and the rows that come back show which of them exist.
13
+ *
14
+ * - A field counts as present when any returned row carries the key, not only
15
+ * the first: a field-level rule that depends on the record can hide a real
16
+ * column on some rows, never on a column that is absent from the table.
17
+ * - An existing column with no value is still returned (as an empty string),
18
+ * so an empty field is never mistaken for a missing one.
19
+ * - With no rows there is nothing to check. That is harmless: a read returns
20
+ * nothing, and a step that acts on the rows has nothing to act on.
21
+ * - Raw encoded queries are not parsed. They are only accepted through an
22
+ * owner-written policy rule that pins the query and its field names, so
23
+ * there is no caller-typed field to verify.
24
+ *
25
+ * The extra columns are asked for only when the caller's own field list does
26
+ * not already hold them, and callers drop them from the result.
27
+ */
28
+ export interface FilterFieldEcho {
29
+ /** The sysparm_fields value to send; undefined keeps "every column". */
30
+ readonly sysparmFields: string | undefined;
31
+ /** The fields whose presence in the returned rows is checked. */
32
+ readonly probe: readonly string[];
33
+ /** True when the request asks for columns the caller did not select. */
34
+ readonly extended: boolean;
35
+ }
36
+ /**
37
+ * The sysparm_fields to send, and the fields to look for in the rows.
38
+ *
39
+ * `requested` is the caller's own selection, comma separated, or undefined
40
+ * when the read asks for every column. A read for every column already
41
+ * returns each column of the table, so nothing is added; a dot-walked name is
42
+ * not returned by such a read, so it cannot be checked there and is skipped.
43
+ */
44
+ export declare function echoFilterFields(requested: string | undefined, referenced: readonly string[]): FilterFieldEcho;
45
+ /**
46
+ * The first probed field that no returned row carries, or undefined when
47
+ * every field is present or there is no row to look at.
48
+ */
49
+ export declare function firstMissingFilterField(rows: unknown, probe: readonly string[]): string | undefined;
50
+ /** True when the request was extended for the check and then came back too large. */
51
+ export declare function isFilterEchoTooLarge(error: unknown, echo: FilterFieldEcho): boolean;
52
+ //# sourceMappingURL=unknown-filter-fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-filter-fields.d.ts","sourceRoot":"","sources":["../src/unknown-filter-fields.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAOH,MAAM,WAAW,eAAe;IAC9B,wEAAwE;IACxE,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3C,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,UAAU,EAAE,SAAS,MAAM,EAAE,GAC5B,eAAe,CAkBjB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,SAAS,MAAM,EAAE,GACvB,MAAM,GAAG,SAAS,CAcpB;AAED,qFAAqF;AACrF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,GAAG,OAAO,CAEnF"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ /**
3
+ * Refuse a filter or order on a field the table does not have.
4
+ *
5
+ * ServiceNow drops a condition on a column it does not know, unless the
6
+ * instance sets glide.invalid_query.returns_no_rows (off by default and not a
7
+ * setting this server can rely on). A misspelt field therefore does not match
8
+ * nothing: the rest of the query runs and unrelated rows come back.
9
+ *
10
+ * The check costs no request. A column named in sysparm_fields that the table
11
+ * does not have, or that the integration user may not read, is left out of
12
+ * every row, so the filter's own fields are asked for on the read that is
13
+ * made anyway and the rows that come back show which of them exist.
14
+ *
15
+ * - A field counts as present when any returned row carries the key, not only
16
+ * the first: a field-level rule that depends on the record can hide a real
17
+ * column on some rows, never on a column that is absent from the table.
18
+ * - An existing column with no value is still returned (as an empty string),
19
+ * so an empty field is never mistaken for a missing one.
20
+ * - With no rows there is nothing to check. That is harmless: a read returns
21
+ * nothing, and a step that acts on the rows has nothing to act on.
22
+ * - Raw encoded queries are not parsed. They are only accepted through an
23
+ * owner-written policy rule that pins the query and its field names, so
24
+ * there is no caller-typed field to verify.
25
+ *
26
+ * The extra columns are asked for only when the caller's own field list does
27
+ * not already hold them, and callers drop them from the result.
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.echoFilterFields = echoFilterFields;
31
+ exports.firstMissingFilterField = firstMissingFilterField;
32
+ exports.isFilterEchoTooLarge = isFilterEchoTooLarge;
33
+ const client_js_1 = require("./client.js");
34
+ const tool_error_js_1 = require("./tool-error.js");
35
+ const CANONICAL_FIELD = tool_error_js_1.CANONICAL_FIELD_PATTERN;
36
+ /**
37
+ * The sysparm_fields to send, and the fields to look for in the rows.
38
+ *
39
+ * `requested` is the caller's own selection, comma separated, or undefined
40
+ * when the read asks for every column. A read for every column already
41
+ * returns each column of the table, so nothing is added; a dot-walked name is
42
+ * not returned by such a read, so it cannot be checked there and is skipped.
43
+ */
44
+ function echoFilterFields(requested, referenced) {
45
+ const names = [...new Set(referenced)].filter((field) => CANONICAL_FIELD.test(field));
46
+ if (requested === undefined) {
47
+ return {
48
+ sysparmFields: undefined,
49
+ probe: Object.freeze(names.filter((field) => !field.includes("."))),
50
+ extended: false,
51
+ };
52
+ }
53
+ const listed = new Set(requested.split(","));
54
+ const extra = names.filter((field) => !listed.has(field));
55
+ return {
56
+ sysparmFields: extra.length === 0 ? requested : `${requested},${extra.join(",")}`,
57
+ probe: Object.freeze(names),
58
+ extended: extra.length > 0,
59
+ };
60
+ }
61
+ /**
62
+ * The first probed field that no returned row carries, or undefined when
63
+ * every field is present or there is no row to look at.
64
+ */
65
+ function firstMissingFilterField(rows, probe) {
66
+ if (!Array.isArray(rows) || rows.length === 0 || probe.length === 0) {
67
+ return undefined;
68
+ }
69
+ const pending = new Set(probe);
70
+ for (const row of rows) {
71
+ if (typeof row !== "object" || row === null)
72
+ continue;
73
+ for (const field of pending) {
74
+ if (Object.hasOwn(row, field))
75
+ pending.delete(field);
76
+ }
77
+ if (pending.size === 0)
78
+ return undefined;
79
+ }
80
+ // Set order is insertion order, so this is the first field in probe order.
81
+ return pending.values().next().value;
82
+ }
83
+ /** True when the request was extended for the check and then came back too large. */
84
+ function isFilterEchoTooLarge(error, echo) {
85
+ return echo.extended && (0, client_js_1.isServiceNowResponseTooLarge)(error);
86
+ }
87
+ //# sourceMappingURL=unknown-filter-fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unknown-filter-fields.js","sourceRoot":"","sources":["../src/unknown-filter-fields.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;AAwBH,4CAqBC;AAMD,0DAiBC;AAGD,oDAEC;AAvED,2CAA2D;AAC3D,mDAA0D;AAE1D,MAAM,eAAe,GAAG,uCAAuB,CAAC;AAWhD;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,SAA6B,EAC7B,UAA6B;IAE7B,MAAM,KAAK,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CACtD,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAC5B,CAAC;IACF,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC5B,OAAO;YACL,aAAa,EAAE,SAAS;YACxB,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;YACnE,QAAQ,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E,OAAO,OAAO,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;AACvC,CAAC;AAED,qFAAqF;AACrF,SAAgB,oBAAoB,CAAC,KAAc,EAAE,IAAqB;IACxE,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAA,wCAA4B,EAAC,KAAK,CAAC,CAAC;AAC9D,CAAC"}
package/dist/version.d.ts CHANGED
@@ -6,5 +6,5 @@
6
6
  *
7
7
  * @module version
8
8
  */
9
- export declare const VERSION = "2.3.0-dev.1";
9
+ export declare const VERSION = "2.3.0-dev.3";
10
10
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -9,5 +9,5 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.VERSION = void 0;
12
- exports.VERSION = "2.3.0-dev.1";
12
+ exports.VERSION = "2.3.0-dev.3";
13
13
  //# sourceMappingURL=version.js.map
@@ -198,7 +198,7 @@ grant is validated with the same loader the server uses at request time, so a
198
198
  rejected policy fails at the CLI rather than at the first tool call.
199
199
 
200
200
  Without `--tools`, each table named with `--read` gets
201
- `sn_query,sn_get,sn_aggregate,sn_schema`, and each table named with `--write`
201
+ `sn_query,sn_get,sn_aggregate,sn_schema,sn_codesearch`, and each table named with `--write`
202
202
  gets `sn_create,sn_update`. A write grant on `incident` also binds
203
203
  `sn_incident_add_comment` and `sn_incident_add_work_note`. Comments are
204
204
  customer-visible, so a comment the agent appends can notify the incident's
@@ -215,6 +215,27 @@ with `--tools`; `--replace` discards every rule on the profile, so grant its
215
215
  other tables again afterwards. `sn_delete`, `sn_batch`, and `sn_atf` are never
216
216
  granted implicitly and must be named with `--tools`.
217
217
 
218
+ `sn_codesearch` is checked against each code table it searches
219
+ (`sys_script`, `sys_script_include`, `sys_ui_script`, `sys_script_client`,
220
+ `sys_ws_operation`, `sys_module`), so a plain `--read sys_script_include` is enough to search
221
+ script includes. A search with no `table` searches the code tables the profile
222
+ may read and names the others in a warning; it fails only when it may read none
223
+ of them. It does nothing on other tables. A profile saved before this default keeps its stored tool list:
224
+ re-run `grant --profile <name> --read <code table>` or add
225
+ `--tools sn_codesearch` to give it the tool. The profile's field policy still
226
+ applies: a code table whose script field is not readable denies `sn_codesearch`
227
+ as it denies `sn_query` for that field (a search with no `table` leaves that
228
+ table out and names it in the warning).
229
+
230
+ Searching ATF step scripts (`sn_codesearch` with `table: "sys_atf_step"`) reads
231
+ three tables, so it needs read on `sys_variable_value`, `sys_atf_step` and
232
+ `sys_atf_test`, each bound to `sn_codesearch`:
233
+ `servicenow-mcp-setup grant --profile <name> --read sys_variable_value,sys_atf_step,sys_atf_test`.
234
+ `--atf` binds those tables to `sn_atf_author` only, so it is added on top. The
235
+ search is limited in the server to the script inputs of ATF steps; the grant on
236
+ `sys_variable_value` does not let `sn_codesearch` search any other table's
237
+ variables.
238
+
218
239
  A grant decides which tools reach a table; the profile's field policy still
219
240
  decides which fields they may write. The journal tools follow it like
220
241
  `sn_update` does: if the incident's effective `writable` list, from
@@ -287,7 +287,7 @@ SN_ALLOWED_READ_TABLES=incident,problem,change_request
287
287
  SN_ALLOWED_WRITE_TABLES=incident,change_request
288
288
  SN_TABLE_ACCESS_TARGETS=<runtime-config:reviewed-target-catalog>
289
289
  SN_METADATA_CACHE_TTL_MS=86400000
290
- SN_METADATA_CACHE_TABLES=sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*
290
+ SN_METADATA_CACHE_TABLES=sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*,sys_script,sys_script_include,sys_ui_script,sys_script_client,sys_ws_operation,sys_module
291
291
  ```
292
292
 
293
293
  Metadata caching works in every auth mode, including the client_credentials
@@ -326,6 +326,26 @@ ACLs on the cached rows are not evaluated on the hit. Do not add it, and review
326
326
  table you do add against the same two questions: are its rows ACL-restricted
327
327
  per user, and would a stale or cross-identity answer be a disclosure?
328
328
 
329
+ The six code tables in the default list (`sys_script`, `sys_script_include`,
330
+ `sys_ui_script`, `sys_script_client`, `sys_ws_operation`, `sys_module`) hold
331
+ script bodies, and scripts can contain hard-coded credentials. A cached entry
332
+ keeps the whole response of a read, so it holds the full `script`,
333
+ `operation_script` or `content` of every row read, not the 200-character snippet
334
+ `sn_codesearch` shows. `sys_variable_value`, which holds ATF step inputs among
335
+ every other table's variable values, is not in the default list: an ATF step
336
+ script search reads it straight through, and an operator who adds it to the list
337
+ caches those values for the TTL, so add it only after the same review. Entries
338
+ live only in process memory, partitioned by instance and credential identity,
339
+ and are never written to disk or to logs. They are kept for up to the cache TTL
340
+ (24 hours by default), within 32 MiB per credential and 128 MiB overall. They
341
+ differ from `sys_properties` in that no cross-identity hit is possible, since
342
+ the partition is the credential, and the payloads are large enough to be worth
343
+ keeping. A script edit moves the table's watermark and refreshes the entry, but
344
+ a tightened ServiceNow ACL does not, so it follows the restart-or-rotate rule
345
+ above. To keep script bodies out of the cache, set `SN_METADATA_CACHE_TABLES`
346
+ (or `metadataCache.tables` on a file-backed profile) to the list without them:
347
+ `sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*`.
348
+
329
349
  For a named profile, keep the secret out of JSON and reference the same
330
350
  canonical runtime secret:
331
351
 
@@ -764,7 +764,7 @@ then the `"*"` entry, then every field, on:
764
764
  `cmdb_ci_computer`, `kb_knowledge`;
765
765
  - every table without a built-in entry, named in the policy or not.
766
766
 
767
- The other 23 built-in tables are system tables, listed in the
767
+ The other 24 built-in tables are system tables, listed in the
768
768
  [field policy reference](../README.md#field-policy). A `"*"` entry never
769
769
  reaches them, named or not.
770
770
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onlyflows/servicenow-mcp",
3
3
  "mcpName": "io.github.onlyflowstech/servicenow-mcp",
4
- "version": "2.3.0-dev.1",
4
+ "version": "2.3.0-dev.3",
5
5
  "description": "Governed stdio ServiceNow MCP server for production: 24 tools with per-profile table and field policy, dry-run bulk changes, activity events, multi-instance profiles, CMDB traversal, ATF testing and read-only Flow Designer flow views.",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
package/server.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "url": "https://github.com/onlyflowstech/servicenow-mcp",
8
8
  "source": "github"
9
9
  },
10
- "version": "2.3.0-dev.1",
10
+ "version": "2.3.0-dev.3",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "@onlyflows/servicenow-mcp",
15
- "version": "2.3.0-dev.1",
15
+ "version": "2.3.0-dev.3",
16
16
  "runtimeHint": "npx",
17
17
  "transport": {
18
18
  "type": "stdio"