@onlyflows/servicenow-mcp 2.3.0-dev.2 → 2.3.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +0 -253
  2. package/README.md +7 -141
  3. package/dist/client.d.ts +2 -14
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +10 -40
  6. package/dist/client.js.map +1 -1
  7. package/dist/encoded-query-policy.d.ts +0 -9
  8. package/dist/encoded-query-policy.d.ts.map +1 -1
  9. package/dist/encoded-query-policy.js +1 -19
  10. package/dist/encoded-query-policy.js.map +1 -1
  11. package/dist/http-runtime.js +0 -16
  12. package/dist/http-runtime.js.map +1 -1
  13. package/dist/metadata-cache.d.ts +7 -97
  14. package/dist/metadata-cache.d.ts.map +1 -1
  15. package/dist/metadata-cache.js +21 -283
  16. package/dist/metadata-cache.js.map +1 -1
  17. package/dist/setup-prompts.js +1 -1
  18. package/dist/setup-prompts.js.map +1 -1
  19. package/dist/setup.d.ts.map +1 -1
  20. package/dist/setup.js +1 -10
  21. package/dist/setup.js.map +1 -1
  22. package/dist/structured-query.d.ts +2 -61
  23. package/dist/structured-query.d.ts.map +1 -1
  24. package/dist/structured-query.js +35 -376
  25. package/dist/structured-query.js.map +1 -1
  26. package/dist/tools/codesearch.d.ts.map +1 -1
  27. package/dist/tools/codesearch.js +4 -24
  28. package/dist/tools/codesearch.js.map +1 -1
  29. package/dist/tools/flow-view-module.js +1 -1
  30. package/dist/tools/flow-view-module.js.map +1 -1
  31. package/dist/tools/get-module.js +1 -1
  32. package/dist/tools/get-module.js.map +1 -1
  33. package/dist/tools/index.d.ts.map +1 -1
  34. package/dist/tools/index.js +11 -24
  35. package/dist/tools/index.js.map +1 -1
  36. package/dist/tools/query-module.d.ts.map +1 -1
  37. package/dist/tools/query-module.js +59 -205
  38. package/dist/tools/query-module.js.map +1 -1
  39. package/dist/tools/result-envelope.d.ts +0 -311
  40. package/dist/tools/result-envelope.d.ts.map +1 -1
  41. package/dist/tools/result-envelope.js +31 -314
  42. package/dist/tools/result-envelope.js.map +1 -1
  43. package/dist/tools/schema-module.d.ts.map +1 -1
  44. package/dist/tools/schema-module.js +1 -1
  45. package/dist/tools/schema-module.js.map +1 -1
  46. package/dist/version.d.ts +1 -1
  47. package/dist/version.d.ts.map +1 -1
  48. package/dist/version.js +1 -1
  49. package/dist/version.js.map +1 -1
  50. package/docs/CLIENT-SETUP.md +1 -11
  51. package/docs/PRODUCTION-SECURITY.md +1 -17
  52. package/package.json +1 -1
  53. package/server.json +2 -2
  54. package/dist/call-metrics.d.ts +0 -42
  55. package/dist/call-metrics.d.ts.map +0 -1
  56. package/dist/call-metrics.js +0 -89
  57. package/dist/call-metrics.js.map +0 -1
  58. package/dist/tools/truncation-hint.d.ts +0 -125
  59. package/dist/tools/truncation-hint.d.ts.map +0 -1
  60. package/dist/tools/truncation-hint.js +0 -298
  61. package/dist/tools/truncation-hint.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,259 +5,6 @@ All notable changes to this project are documented here.
5
5
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [2.3.0-dev.2] — 2026-11-15
9
-
10
- ### Added
11
-
12
- - **`sn_query` reads `structured_query.filter` given as a list as an implicit
13
- AND (#17).** `filter: [c1, c2]` means `{type: "group", operator: "and",
14
- conditions: [c1, c2]}`, and a one-element list means that element. The
15
- existing limit of 3 nested group levels is unchanged: a list of two or more
16
- takes one level, so a list that holds a 3-level group is rejected, and the
17
- error says so. An empty list is rejected with its own message. A list is read
18
- this way only as the top-level `filter` and only by `sn_query`: `sn_batch`
19
- write filters stay one object, so a mutation never selects records through a
20
- list. The list is part of the published `tools/list` schema (#33, below).
21
- - **`structured_query.filter` shows a working example in `tools/list` (#19).**
22
- `sn_query`'s `filter` says a list is read as AND and shows one, and the
23
- `sn_query` description gains a one-line example with the OR group form.
24
- `sn_batch`'s `filter` has its own text: one condition or group, and a list is
25
- not accepted, because a mutation never selects records through a list. Its
26
- example filters on `sys_id`, a field every table has: an example on a field
27
- such as `name` would match every row of a table without that column, since
28
- ServiceNow drops a condition on a field the table lacks. Costs 605 characters
29
- in `tools/list` (`sn_query` +459, `sn_batch` +146).
30
- - **Responses say whether the metadata cache was used and where the time went
31
- (#21).** `structuredContent.metadata` gains two optional fields. `cache` is
32
- `hit`, `miss`, `bypass` (a `force_recache` refresh) or `mixed` (several
33
- cacheable reads with different outcomes, such as an `sn_codesearch` with no
34
- `table`), and is absent when the call read no cacheable table. `timing` is
35
- `{ total_ms, upstream_ms, watermark_ms }` in whole milliseconds, wall-clock:
36
- `upstream_ms` and `watermark_ms` are the time at least one request of that
37
- kind was in flight, so overlapping requests count once. Only the server sets
38
- them (a value a tool supplies is discarded), and they are not counted
39
- against the result's byte limit, so they never cost a record and are never
40
- dropped (#34, below). Every tool's
41
- `outputSchema` grows by 322 characters (7,728 in `tools/list`). Cache
42
- behaviour is unchanged.
43
-
44
- ### Fixed
45
-
46
- - **`sn_query` no longer fails with an internal error at the smallest byte
47
- budgets (#39, a regression from the labelled hint, #37).** A truncated read
48
- at `max_response_bytes` 1000 with a wide row (eight fields including a long
49
- `description`, limit 50) returned `The operation failed unexpectedly` every
50
- time: the envelope's metadata leaves room for little beside the counts at
51
- that budget, and the fuller labelled hint no longer fitted even with no row.
52
- When no row fits beside the whole hint, the fit now leaves out the
53
- whole-page figure and then the field advice, keeping the next-row figure, so
54
- the result is a normal truncated one (`has_more: true`, no `next_offset`,
55
- `recovery` set, a hint that parses and equals `dropped_records`). The hint
56
- never names a value above the effective maximum.
57
- - **A truncation hint says which `max_response_bytes` is for the next row and
58
- which for the whole page (#37).** The hint's budget was measured for the
59
- next row only, but a bare `max_response_bytes=1500` read as a value for the
60
- page: live, a 50-row read at 1000 bytes said 1500 and following it returned
61
- one row. The hint now reads `... or max_response_bytes=1500 (fits the next
62
- row) or max_response_bytes=15400 (fits all 50)`. The page figure is measured
63
- the same way as the next-row one, is never smaller than it, and is left out
64
- when the page would exceed the effective maximum (1,000,000, or a raw-read
65
- rule's `maxResponseBytes`) and when one row was dropped (the next row is then
66
- the rest of the page). The bare figure is gone, so a client that matched
67
- `max_response_bytes=<n>.` at the end of the hint must match the labelled
68
- form; the count still equals `dropped_records`, and the hint stays within its
69
- 600 characters. `sn_schema`'s `fields_only` text now says it lists the
70
- table's own fields only, and that inherited fields need the full schema; it
71
- costs 68 characters in `tools/list` (`sn_schema` 3518 to 3586, total 128190
72
- to 128258).
73
- - **The list form of `structured_query.filter` is in the published `tools/list`
74
- schema, and `tools/list` is smaller (#33).** `sn_query` read a list filter,
75
- and its descriptions tell clients to send one, but the schema it published
76
- had no array option, so a client that validates arguments against it (ajv)
77
- rejected the documented example. The list is now an explicit branch of the
78
- schema, 1 to 32 conditions. The filter union and the leaf-condition union
79
- are published once per tool, under `definitions`, and referred to with
80
- `$ref`, where each use used to be written out again; every `$ref` resolves
81
- inside the same tool's `inputSchema`; the definitions are named
82
- `StructuredQueryFilter` and `StructuredQueryCondition`, so clients that merge
83
- `definitions` across tools or servers do not collide. `sn_batch` shares them
84
- and still publishes no array option, and a list is still rejected there.
85
- Behaviour is unchanged: the error messages (#27, including the specific one
86
- for a bad field name, a control character or an over-long value inside a
87
- list element, which now names the caller's own position, `filter[1].field`,
88
- and not a position inside the wrapper group) and the nesting rule (a list of
89
- two or more takes one group level) are as before. One difference stays between the
90
- schema and the server: the schema cannot say that a list of two or more
91
- takes a level, so it accepts a list that holds a 3-level group, which the
92
- server rejects. `tools/list`: `sn_query` 16,574 to 10,183 characters,
93
- `sn_batch` 14,818 to 8,328, the whole list 140,887 to 128,006 (the part a
94
- model reads, without output schemas, 52,641 to 39,760). This delivers most of
95
- the filter dedupe asked for in #9; stripping the bounds the server enforces
96
- anyway, and sharing the scalar value union, are not done. Clients that do not
97
- resolve `$ref` to `definitions` are not served by this form, and a client that
98
- dereferences `$ref` before it validates or shows the schema sees `sn_query` at
99
- about 22.8k characters (the list option written out), against about 13.7k
100
- before this change.
101
- - **Truncated responses keep `metadata.cache` and `metadata.timing` (#34).**
102
- The two fields were added only when the finished response still fit
103
- `max_response_bytes`, so a response fitted to within about 90 bytes of its
104
- limit lost them, on exactly the calls where the timing helps most. They are
105
- no longer counted against the limit: the fit and the truncation hint's numbers
106
- (#28, #29) are unchanged, and a successful response always carries both. It
107
- can exceed `max_response_bytes` by their size, under 100 bytes. The
108
- `max_response_bytes` description of `sn_query`, `sn_get` and `sn_flow_view`
109
- says so (about 61 characters each in `tools/list`).
110
- - **A rejected `structured_query.filter` names the mistake (#27).** A bad
111
- operator, an unknown or missing `type`, a bad group, a missing key, a value of
112
- the wrong kind or a group nested too deep used to get the same shape message,
113
- even when the condition sat inside a group. The message now says the first
114
- thing wrong, in fixed words, with an index path, for example `filter.conditions[1]:
115
- a "text" condition needs operator one of contains, not_contains, starts_with,
116
- ends_with`, `type must be one of equality, set, range, text, null, group` and
117
- `a group needs operator and or or, and a non-empty conditions list`, followed
118
- by the working example. A list filter on `sn_query` is reported at the
119
- caller's own position (`filter[1]`); `sn_batch` gives the same text and still
120
- says a list is not accepted. Nothing the caller sent is repeated, and a
121
- condition type is quoted only when it is one of the known type names. The
122
- shape message remains for anything the walk cannot name. `tools/list` is
123
- byte-identical.
124
- - **The `sn_query` truncation hint gives values to use (#29).** The
125
- `max_response_bytes` description promised exact follow-up arguments, but the
126
- hint said "a lower limit" and "a higher max_response_bytes" with no numbers,
127
- and a caller who chose their own `fields` got no field advice. The hint now
128
- reads like `Dropped 14/22; continue offset=8 limit=8; retry offset=0 with
129
- fields="sys_id,name" or max_response_bytes=31500.` The `limit` is the number
130
- of rows that fit. The `max_response_bytes` is measured where the envelope
131
- refits the result, with its own cost in it, and holds at least the next row;
132
- if no budget up to 1,000,000 (or up to the `maxResponseBytes` of the raw-read
133
- rule that approved a raw `query`, when that is lower) could, the hint says
134
- the next row exceeds that maximum, names it, and offers fields and `sn_get`. A caller's own `fields` list is offered back without its large
135
- fields (such as `script`); a list with none gets the `limit` and the budget,
136
- and a read of `fields=all` gets the table's short default list. Only fields
137
- the profile may read are named, never a sensitive one. The count still equals
138
- `dropped_records` and the hint stays within 600 characters. The
139
- `max_response_bytes` description now names what the hint carries (5
140
- characters shorter; `tools/list` `sn_query` 16,579 to 16,574).
141
- - **`sn_query` no longer stops paging after page 2 (#1).** The tool sends
142
- `sysparm_no_count`, so ServiceNow's `X-Total-Count` header holds the size of
143
- the response (the page plus the one sentinel row), not the table. The handler
144
- trusted it: `total` echoed the rows fetched, and `has_more` turned false from
145
- page 2 on, with thousands of rows unread. `has_more` and `next_offset` now
146
- come from the sentinel row alone, so they stay true until the last page.
147
- **`total` is no longer returned by `sn_query`** (the output schema already
148
- made it optional); counting would need a COUNT query on every call, which
149
- `sysparm_no_count` exists to avoid. Page on `has_more` and `next_offset`, or
150
- call `sn_aggregate` with `COUNT` when the table size matters. If ServiceNow
151
- ACLs strip rows from a page, `has_more` can read false early; cross-check
152
- with `sn_aggregate` `COUNT`.
153
- - **A read grant now allows code search (#2).** `servicenow-mcp-setup grant
154
- --read <table>` binds `sn_codesearch` along with `sn_query`, `sn_get`,
155
- `sn_aggregate` and `sn_schema`, so `--read sys_script_include` is enough to
156
- search script includes; before, every code search on such a profile was
157
- denied unless `--tools sn_codesearch` was passed. It is checked per code
158
- table (`sys_script`, `sys_script_include`, `sys_ui_script`,
159
- `sys_script_client`, `sys_ws_operation`), does nothing on other tables, and
160
- field policy still decides the script field exactly as it does for
161
- `sn_query`. **Profiles saved before this change are not rewritten:** a target
162
- keeps the tool list it was saved with, so run `servicenow-mcp-setup grant
163
- --profile <name> --read <code table>` again to add the default tools, or add
164
- just this one with `--tools sn_codesearch`. Neither removes a tool.
165
- - **A truncation hint on `sn_query` no longer disagrees with `dropped_records`,
166
- and suggests fields the table has (#20).** A read cut to fit
167
- `max_response_bytes` is trimmed in two steps, and the second could drop more
168
- rows than the hint's "Dropped n/m" said. The hint is now restated from the
169
- final result, so its count, its empty-result advice and its continuation
170
- match `dropped_records`, `has_more` and `next_offset`. The suggested
171
- projection was always `fields="sys_id,number"`, wrong for any table without
172
- a `number` column. It is now the table's default fields without large ones
173
- such as `script`, at most three; if that leaves only `sys_id`, `sys_id` and a
174
- display field the profile's field policy names, else `sys_id` alone. A call
175
- that passed its own `fields` is told to lower `limit` or raise
176
- `max_response_bytes` instead of being given a field list.
177
- - **A rejected `structured_query.filter` now says what is accepted (#18).**
178
- Every mistake used to read "Invalid input at structured_query.filter". The
179
- message now says the filter is one condition or group object, gives a working
180
- example, shows how to combine conditions with a group, and states the limit
181
- of 3 nested group levels. It adds nothing to `tools/list`.
182
-
183
- ### Changed
184
-
185
- - **A repeated read of a small cached-table response is one request, not a
186
- watermark and a read (#36).** A cache hit costs one watermark round trip, so
187
- for a small response a hit cost about what a plain read did and a miss cost
188
- two requests. A read of a cacheable table whose response is under 32 KiB is
189
- no longer kept: the selector is remembered as small, per credential scope,
190
- for one cache TTL (at most 512 selectors, least recently used out), and its
191
- later reads go straight to ServiceNow with no watermark. `metadata.cache`
192
- says `miss` for them; `bypass` stays for `force_recache`. A direct read that
193
- comes back at 32 KiB or more forgets the mark, so the selector is cached
194
- from the next read. Responses of 32 KiB and up are cached, checked and
195
- bounded as before. Measured on a dev instance: a 6 KB read 490 ms before (a
196
- hit), 81 ms after; a 17 KB read 489 ms before, 98 ms. The threshold is a
197
- size, not a time: `sys_dictionary` there has a watermark of about 0.5 s, and
198
- even a 66 KB read was faster uncached. `metadataCache.smallReadBytes` sets
199
- the threshold per profile (0 keeps every response).
200
- - **`has_more` and `next_offset` count rows dropped for size (#28). Contract
201
- change for truncated pages.** A page cut to fit `max_response_bytes` kept
202
- `has_more` and `next_offset` for the rows beyond the page, so a client that
203
- followed `next_offset` skipped every dropped row, and a cut last page said
204
- `has_more: false` with `record_count: 0`. Now `record_count`, `truncated` and
205
- `dropped_records` keep their meaning, and:
206
- - `has_more` is true when rows were dropped for size **or** rows exist past
207
- the page: rows exist that the response did not contain.
208
- - `next_offset` is `offset + record_count` when at least one row came back:
209
- the first row not returned. A client that only follows it re-reads the
210
- dropped rows and loses nothing.
211
- - When no row fit, `next_offset` is omitted and `metadata.pagination.recovery`
212
- is `adjust_request_and_retry_same_offset`: `has_more: true` with no
213
- `next_offset` means the request must change (fewer `fields`, a lower
214
- `limit`, or a higher `max_response_bytes`). The pagination output schema
215
- accepts `has_more` without `next_offset` only with `recovery`.
216
- - The old post-page continuation is gone from the hint; `next_offset` covers
217
- it. A page that lost no rows to size is unchanged.
218
-
219
- Applies to every list tool that fits through the shared envelope:
220
- `sn_query`, `sn_syslog`, `sn_schema`, `sn_relationships`, `sn_codesearch`,
221
- `sn_discover`, `sn_attach` (list) and `sn_atf` continue at `offset + rows
222
- returned`; any other cut collection (for example `sn_aggregate`) reports
223
- `has_more: true` with no `next_offset`. This also stops a byte drop made only
224
- by the envelope (#23) from skipping the dropped row when `next_offset` is
225
- followed, and the tool's "More records available. Call sn_query again with
226
- offset=N." hint is restated at `next_offset` (or says no row fit), so it never
227
- contradicts it; #23's `truncated`/`dropped_records` flags in `data` are not
228
- added here. See the README, "Paging when a response is cut to size".
229
- - **Code tables are in the default metadata cache.** `sys_script`,
230
- `sys_script_include`, `sys_ui_script`, `sys_script_client` and
231
- `sys_ws_operation` now cache like the other system-level metadata tables,
232
- under the same per-credential scope and watermark freshness, so a repeated
233
- `sn_codesearch` or `sn_query` of them skips the payload while the table is
234
- unchanged (one watermark read still runs per call). A profile that sets its
235
- own `metadataCache.tables` or `SN_METADATA_CACHE_TABLES` replaces the default
236
- list and must name these tables to cache them. `sn_codesearch` has no
237
- `force_recache` flag. `sn_get` of a record in these tables is cached too, and
238
- a cold one costs 2 requests (a watermark read, then the record); `sn_batch`
239
- and `sn_aggregate` reads are not cached. The cache is also bounded by bytes
240
- now: a response over 512 KiB is not kept, each credential scope holds at most
241
- 32 MiB and the whole cache 128 MiB (least recently used out first), and
242
- expired entries are dropped as new ones are stored. A no-table
243
- `sn_codesearch` reads its five tables concurrently, within the client's
244
- existing request limit. Cached code-table entries hold full script bodies,
245
- which can contain hard-coded credentials, in process memory (never on disk)
246
- for up to the TTL; to keep them out, set `metadataCache.tables` or
247
- `SN_METADATA_CACHE_TABLES` to
248
- `sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*`.
249
-
250
- ### Security
251
-
252
- - **HTTP transport rejects a backslash in the request path.** A request whose
253
- raw path (the part before `?` or `#`) contains a literal `\` now gets
254
- `400 Bad Request`, on every route including the health paths. The WHATWG URL
255
- parser reads `\` as `/` and resolves `..`, so `/x/..\mcp` or `//h\mcp` would
256
- otherwise pass our path check as `/mcp`; until now only the
257
- `@hono/node-server` dependency inside the MCP SDK transport refused the ones
258
- that reached `/mcp`, and the health paths answered them. Backslashes in the
259
- query string and a percent-encoded `%5C` behave as before.
260
-
261
8
  ## [2.3.0-rc.1] — 2026-11-14
262
9
 
263
10
  Release candidate for 2.3.0, published to the `next` dist-tag. It contains the
package/README.md CHANGED
@@ -406,7 +406,7 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
406
406
  "table": "incident",
407
407
  "kind": "canonical",
408
408
  "tools": [
409
- "sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch",
409
+ "sn_query", "sn_get", "sn_aggregate", "sn_schema",
410
410
  "sn_create", "sn_update",
411
411
  "sn_incident_add_comment", "sn_incident_add_work_note"
412
412
  ],
@@ -416,7 +416,7 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
416
416
  {
417
417
  "table": "problem",
418
418
  "kind": "canonical",
419
- "tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch"],
419
+ "tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema"],
420
420
  "closureComplete": true,
421
421
  "relatedTables": ["problem"]
422
422
  }
@@ -692,7 +692,7 @@ in this section is needed to use this server.
692
692
 
693
693
  | Tool | Description |
694
694
  |------|-------------|
695
- | `sn_query` | Query an approved table with structured filters, field selection, pagination, and sorting; bounded raw reads require an explicit policy rule. Paging runs on `has_more` and `next_offset`, which can end early if ServiceNow ACLs strip rows from a page; cross-check with `sn_aggregate` `COUNT`. A page cut to fit `max_response_bytes` keeps the same contract: see [Paging when a response is cut to size](#paging-when-a-response-is-cut-to-size) |
695
+ | `sn_query` | Query an approved table with structured filters, field selection, pagination, and sorting; bounded raw reads require an explicit policy rule |
696
696
  | `sn_get` | Get a single record by sys_id from an approved table |
697
697
  | `sn_create` | Create a record on any table granted for writes, using only field-policy-approved writable fields, including the journal fields `comments` and `work_notes`; `incident` additionally requires a bounded `short_description` |
698
698
  | `sn_update` | Update one record selected by exact `sys_id` on any table granted for writes, using only field-policy-approved writable fields; `comments` and `work_notes` append a journal entry |
@@ -716,7 +716,7 @@ in this section is needed to use this server.
716
716
  | `sn_relationships` | CMDB CI graph traversal — upstream/downstream/both, configurable depth |
717
717
  | `sn_attach` | List attachments, return downloads as inline base64, and upload inline base64 content; never touches a host filesystem path |
718
718
  | `sn_syslog` | Query system logs with severity/source/time filters |
719
- | `sn_codesearch` | Search business rules, script includes, client scripts, etc. Part of the default read grant, so a plain read grant on a code table allows it |
719
+ | `sn_codesearch` | Search business rules, script includes, client scripts, etc. |
720
720
  | `sn_discover` | Discover tables, scoped apps, store apps, plugins |
721
721
 
722
722
  ### Testing & Automation
@@ -848,25 +848,10 @@ limit is always 1 MiB and no environment variable changes it.
848
848
  Stable ServiceNow metadata reads are cached per instance and credential identity
849
849
  for 24 hours by default. The default cached table patterns are
850
850
  `sys_glide_object`, `sys_dictionary`, `sys_db_object`, `sys_app`, `sys_plugins`,
851
- `sys_metadata*`, `sys_flow*`, and the five code tables `sn_codesearch`
852
- searches: `sys_script`, `sys_script_include`, `sys_ui_script`,
853
- `sys_script_client`, and `sys_ws_operation`. A repeated code search or
854
- `sn_query` page on those tables is served from the cache while the table's
855
- watermark is unchanged. Set `metadataCache.ttlMs` and
851
+ `sys_metadata*`, and `sys_flow*`. Set `metadataCache.ttlMs` and
856
852
  `metadataCache.tables` on a file-backed profile, or `SN_METADATA_CACHE_TTL_MS`
857
- / `SN_METADATA_CACHE_TABLES` for the explicit environment profile; a table
858
- list you set replaces the default list, so name the code tables in it to keep
859
- caching them. `sn_query`, `sn_get`, and `sn_schema` accept `force_recache: true`
860
- to refresh metadata; `sn_codesearch` has no such flag, so a change the
861
- watermark cannot see shows there after at most one TTL. A cold `sn_get` of a
862
- code-table record costs two requests (the watermark, then the record), and
863
- `sn_batch` and `sn_aggregate` reads are never cached. Memory is bounded: a
864
- response over 512 KiB is not cached, one credential scope keeps at most 32 MiB
865
- and the whole cache 128 MiB, evicting the least recently used first. Cached
866
- code-table entries hold full script bodies, which can contain hard-coded
867
- credentials, in process memory (never on disk) for up to the TTL; to keep them
868
- out, set `metadataCache.tables` or `SN_METADATA_CACHE_TABLES` to
869
- `sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*`.
853
+ / `SN_METADATA_CACHE_TABLES` for the explicit environment profile. `sn_query`,
854
+ `sn_get`, and `sn_schema` accept `force_recache: true` to refresh metadata.
870
855
 
871
856
  **Freshness is checked against the instance, in every auth mode.** Before each
872
857
  fetch the cache reads a watermark in one small request: the table's row count
@@ -886,45 +871,6 @@ A tool call reads each table's watermark once, however many times it reads the
886
871
  table, until the call writes. A hierarchy walk reads `sys_db_object` once for
887
872
  the whole chain. An empty table caches like any other.
888
873
 
889
- **Small responses are not cached.** A hit costs a round trip about the size of
890
- a plain read, so a response under 32 KiB (serialized body) saves nothing and is
891
- not kept. The first read of such a selector costs the watermark and the read,
892
- as before; the server then remembers that selector as small, for one TTL, and
893
- reads it again in a single request with no watermark. If a later read of it
894
- comes back at 32 KiB or more, it is cached from the next read on. Large reads,
895
- such as script bodies, are cached and checked exactly as above, and
896
- `force_recache: true` still reads the watermark and refreshes. The memory is
897
- per credential scope, holds at most 512 selectors (least recently used out),
898
- and costs no cached bytes. A call that read a small selector this way reports
899
- `miss`. On a table whose watermark is slow (`sys_dictionary` on a large
900
- instance: about 0.5 s against a 0.1 to 0.2 s read in one measurement) even a
901
- large read may be faster uncached; the threshold is a size, not a time. A
902
- profile's `metadataCache.smallReadBytes` sets the threshold (0 caches every
903
- response; at most 512 KiB).
904
-
905
- **Seeing what the cache did.** Every successful response carries two optional
906
- fields in `structuredContent.metadata`. `cache` says how the call's cacheable
907
- reads were served: `hit` (all from the cache), `miss` (from ServiceNow: nothing
908
- cached yet, the watermark moved, the entry expired, the table could not be
909
- cached just then, or the response is small and not kept), `bypass` (a `force_recache: true` refresh), or `mixed` (the
910
- call made several cacheable reads with different outcomes, such as an
911
- `sn_codesearch` with no `table` over the five code tables). It is absent when
912
- the call read no cache-eligible table. `timing` is `{ total_ms, upstream_ms,
913
- watermark_ms }` in whole milliseconds, measured wall-clock: `total_ms` is the
914
- whole tool call; `upstream_ms` is the time during which at least one request to
915
- ServiceNow other than a watermark read was in flight (retry waits included);
916
- `watermark_ms` is the same for the cache's watermark reads. Overlapping
917
- requests are counted once, not summed, so each figure is at most `total_ms`,
918
- though the two can overlap each other and add up to more than it. A hit reports
919
- `upstream_ms: 0` and the watermark round trip it still costs. Callers that
920
- share a credential share cache warmth (several profiles on one credential, or
921
- several HTTP clients on one profile), so `cache: "hit"` can reflect another
922
- caller's earlier read made with the same credential. Both fields hold only
923
- numbers and those four words, and appear whether or not the cache is on
924
- (`timing` always, `cache` only when a cacheable read happened). Only the server
925
- sets them; a tool cannot supply its own. Each tool's `outputSchema` grows by
926
- about 320 characters for them.
927
-
928
874
  If a table's watermark cannot be used, its reads go straight upstream, without
929
875
  a watermark request, for a while: 15 minutes when the cause persists (an
930
876
  incomplete or future-dated watermark, a 403 or 404), 30 seconds when it may not
@@ -947,72 +893,6 @@ identity, and effective policy, so a repeat call costs no request at all. They
947
893
  are not revalidated in that window; `force_recache: true` refreshes them, and
948
894
  `schemaCacheTtlMs` / `SN_SCHEMA_CACHE_TTL_MS` (up to 1 hour) changes the window.
949
895
 
950
- ### Paging when a response is cut to size
951
-
952
- A read that does not fit `max_response_bytes` (or, for a result with more than
953
- 1,000 rows, the record limit) is cut by dropping whole rows from the tail, so
954
- the rows that come back are always a prefix of the page you asked for. For the
955
- list tools, `has_more` and `next_offset` count the rows that were dropped:
956
-
957
- | Field | Meaning |
958
- |-------|---------|
959
- | `record_count` | Rows in `results`. |
960
- | `truncated`, `dropped_records` | `sn_query` sets them when rows were dropped for size, and says how many; every list tool reports the same in `metadata.truncation`. |
961
- | `has_more` | True when rows were dropped for size **or** rows exist past the page: rows exist that this response did not contain. A response that came back empty because its rows were too large says `has_more: true`, not "no results". |
962
- | `next_offset` | `offset + record_count`: the first row not returned. Following it re-reads the dropped rows before anything later, so a client that only follows `next_offset` sees every row exactly once. |
963
-
964
- When **no row fit**, there is nothing to continue after, so `next_offset` is
965
- left out and `metadata.pagination.recovery` is
966
- `adjust_request_and_retry_same_offset`: `has_more: true` with no `next_offset`
967
- means the request must change (fewer `fields`, a lower `limit`, or a higher
968
- `max_response_bytes`; `sn_get` reads one row). The `hint` says which.
969
-
970
- This holds for `sn_query`, `sn_syslog`, `sn_schema`, `sn_relationships`,
971
- `sn_codesearch`, `sn_discover`, `sn_attach` (list) and `sn_atf`, whose `offset`
972
- is a row offset into the rows they return. Any other collection result that is cut to size
973
- (for example `sn_aggregate`) reports `has_more: true` with no `next_offset`.
974
- A page that lost no rows to size is unchanged: `has_more` and `next_offset`
975
- come from the row after the page, and `next_offset` is `offset + limit`.
976
-
977
- A client that follows `next_offset` should also pass the `limit` the hint names
978
- (`continue offset=8 limit=8`): at the original `limit` each page asks
979
- ServiceNow for that many rows and the cut drops most of them again, so the same
980
- rows are fetched many times over.
981
-
982
- Before this change `next_offset` after a cut page was `offset + limit`, which
983
- skipped the dropped rows, and a cut last page reported `has_more: false` with
984
- `record_count: 0`.
985
-
986
- **The `sn_query` hint gives values you can use.** For example
987
-
988
- ```text
989
- Dropped 14/22; continue offset=8 limit=8; retry offset=0 with fields="sys_id,name" or max_response_bytes=1500 (fits the next row) or max_response_bytes=31500 (fits all 22).
990
- ```
991
-
992
- - `continue offset=8 limit=8` is `next_offset` and the number of rows that fit:
993
- page on with that `limit` and nothing is dropped again.
994
- - `retry offset=0 with ...` re-reads the whole page in one response, with fewer
995
- fields or a larger budget. The two budgets are different numbers, and each
996
- says what it buys. `max_response_bytes=1500 (fits the next row)` holds one
997
- more row than this response did, so a retry with it returns about one more
998
- row; `max_response_bytes=31500 (fits all 22)` holds every row of the page.
999
- Both are measured from the response itself (the rows plus the envelope's own
1000
- metadata) and rounded up. The page figure is left out when it would be more
1001
- than the 1,000,000-byte maximum (or the `maxResponseBytes` of the raw-read
1002
- rule that approved a raw `query`, when that is lower) and when only one row
1003
- was dropped, since the next row is then the rest of the page. When even the
1004
- next row would be more than that maximum, the hint says the next row exceeds
1005
- it, names it, and offers only fields and `sn_get`. It never names a budget
1006
- the policy would deny.
1007
- - `fields=...` appears when it helps: the table's short default list for a
1008
- read of the defaults or of `all`, or your own list without its large fields
1009
- (for example `script`) when you chose one. It only ever names fields your
1010
- profile may read, and never a sensitive one. A list with nothing large in it
1011
- gets the `limit` and the budget instead. `response_format="concise"` is
1012
- offered to a `detailed` read.
1013
- - When no row fit, there is no `continue` clause and no `limit`: only the
1014
- retry options and `sn_get`.
1015
-
1016
896
  ### Unrestricted field selection (`fields=all`, `response_format=detailed`)
1017
897
 
1018
898
  Both resolve to the profile's readable set for the table. Where the field
@@ -1106,20 +986,6 @@ servicenow-mcp-setup grant --profile dev --read change_request --related change_
1106
986
  servicenow-mcp-setup grant --profile dev --flows # sn_flow_view's 15 tables, bound to sn_flow_view only
1107
987
  ```
1108
988
 
1109
- A read grant without `--tools` binds `sn_query`, `sn_get`, `sn_aggregate`,
1110
- `sn_schema` and `sn_codesearch` to each table it names. `sn_codesearch` is
1111
- authorized per code table it searches (`sys_script`, `sys_script_include`,
1112
- `sys_ui_script`, `sys_script_client`, `sys_ws_operation`), so
1113
- `servicenow-mcp-setup grant --profile dev --read sys_script_include` lets that
1114
- profile search script includes; a search with no `table` needs a read grant on
1115
- all five. On any other table the binding is inert. **A profile written before
1116
- `sn_codesearch` was a default keeps the tool list it was saved with** and is not
1117
- rewritten: re-run the same `grant --read <code table>` to add it, or pass
1118
- `--tools sn_codesearch` to add only that tool. Neither removes a tool. The
1119
- profile's field policy still decides the script field: `sn_codesearch` is
1120
- denied on a code table whose script field is not readable, exactly as `sn_query`
1121
- is for that field.
1122
-
1123
989
  Allowlist entries may be exact table names or the literal `*` to allow every
1124
990
  table for that operation. Table names are trimmed, lowercased, deduplicated,
1125
991
  and must be valid ServiceNow identifiers.
package/dist/client.d.ts CHANGED
@@ -17,7 +17,6 @@
17
17
  * @module client
18
18
  */
19
19
  import { type AtfFormInput } from "./atf-form.js";
20
- import { CallMetrics, type CacheOutcome } from "./call-metrics.js";
21
20
  import { ServiceNowConfig } from "./config.js";
22
21
  import { AuthProvider } from "./auth.js";
23
22
  /** @deprecated Inspect trusted tool-error provenance instead of raw fields. */
@@ -78,14 +77,7 @@ export declare const DEFAULT_MAX_CONCURRENT_REQUESTS = 4;
78
77
  * Bind one immutable execution-context signal and fresh atomic upstream byte
79
78
  * budgets to cached clients without adding mutable state to the client/cache.
80
79
  */
81
- export declare function runWithServiceNowRequestSignal<T>(signal: AbortSignal, operation: () => Promise<T>, metrics?: CallMetrics): Promise<T>;
82
- /** Count the cache outcome of one cacheable read against the current call. */
83
- export declare function recordCacheOutcome(outcome: CacheOutcome): void;
84
- /**
85
- * Run a cache freshness check so that its requests count as watermark time
86
- * rather than upstream time. Outside a call scope it just runs.
87
- */
88
- export declare function asWatermarkRead<T>(operation: () => Promise<T>): Promise<T>;
80
+ export declare function runWithServiceNowRequestSignal<T>(signal: AbortSignal, operation: () => Promise<T>): Promise<T>;
89
81
  export declare class ServiceNowClient {
90
82
  #private;
91
83
  constructor(config: ServiceNowConfig, options?: ClientOptions);
@@ -141,11 +133,7 @@ export declare class ServiceNowClient {
141
133
  private consumeErrorBody;
142
134
  private buildHttpError;
143
135
  }
144
- /**
145
- * Build an immutable, reflection-safe capability around a resolved client.
146
- * Every request it makes is timed against the current call (see
147
- * {@link CallMetrics}); the timing never alters, delays or retries a request.
148
- */
136
+ /** Build an immutable, reflection-safe capability around a resolved client. */
149
137
  export declare function createServiceNowOperations(client: ServiceNowOperations): ServiceNowOperations;
150
138
  /**
151
139
  * A response, or a request scope's cumulative upstream JSON, passed its byte
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtG,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAsB,MAAM,WAAW,CAAC;AAW7D,+EAA+E;AAC/E,MAAM,MAAM,eAAe,GAAG,KAAK,CAAC;AAEpC,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAExD,4EAA4E;AAC5E,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,UAAU;IAC3C,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,iBAAiB,CAAC,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvD,GAAG,CAAC,CAAC,GAAG,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC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,EACzB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR"}
package/dist/client.js CHANGED
@@ -20,8 +20,6 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.ServiceNowResponseTooLargeError = exports.ServiceNowClient = exports.DEFAULT_MAX_CONCURRENT_REQUESTS = exports.BASIC_AUTH_401_HINT = exports.MAX_ERROR_RESPONSE_BYTES = exports.DEFAULT_MAX_JSON_RESPONSE_BYTES = exports.MAX_CUMULATIVE_RAW_RESPONSE_BYTES = exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES = exports.MAX_RETRY_DELAY_MS = exports.DEFAULT_TIMEOUT_MS = void 0;
22
22
  exports.runWithServiceNowRequestSignal = runWithServiceNowRequestSignal;
23
- exports.recordCacheOutcome = recordCacheOutcome;
24
- exports.asWatermarkRead = asWatermarkRead;
25
23
  exports.createServiceNowOperations = createServiceNowOperations;
26
24
  exports.isServiceNowResponseTooLarge = isServiceNowResponseTooLarge;
27
25
  exports.isServiceNowRequestCancellation = isServiceNowRequestCancellation;
@@ -29,7 +27,6 @@ exports.parseRetryAfterMs = parseRetryAfterMs;
29
27
  exports.retryDelayMs = retryDelayMs;
30
28
  const atf_form_js_1 = require("./atf-form.js");
31
29
  const node_async_hooks_1 = require("node:async_hooks");
32
- const call_metrics_js_1 = require("./call-metrics.js");
33
30
  const html_response_js_1 = require("./html-response.js");
34
31
  const auth_js_1 = require("./auth.js");
35
32
  const incident_journal_policy_js_1 = require("./incident-journal-policy.js");
@@ -55,7 +52,7 @@ const REQUEST_SCOPE = new node_async_hooks_1.AsyncLocalStorage();
55
52
  * Bind one immutable execution-context signal and fresh atomic upstream byte
56
53
  * budgets to cached clients without adding mutable state to the client/cache.
57
54
  */
58
- function runWithServiceNowRequestSignal(signal, operation, metrics) {
55
+ function runWithServiceNowRequestSignal(signal, operation) {
59
56
  if (!(signal instanceof AbortSignal)) {
60
57
  return Promise.reject(new TypeError("request signal must be an AbortSignal"));
61
58
  }
@@ -67,10 +64,6 @@ function runWithServiceNowRequestSignal(signal, operation, metrics) {
67
64
  signal,
68
65
  upstreamJsonBytes: new CumulativeResponseByteBudget(exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES),
69
66
  upstreamRawBytes: new CumulativeResponseByteBudget(exports.MAX_CUMULATIVE_RAW_RESPONSE_BYTES),
70
- // A scope opened inside a call (a bounded sub-operation with its own
71
- // signal) belongs to the same call, so it keeps reporting to it.
72
- metrics: metrics ?? REQUEST_SCOPE.getStore()?.metrics ?? new call_metrics_js_1.CallMetrics(),
73
- lane: "upstream",
74
67
  });
75
68
  return Promise.resolve(REQUEST_SCOPE.run(scope, operation));
76
69
  }
@@ -78,25 +71,6 @@ function runWithServiceNowRequestSignal(signal, operation, metrics) {
78
71
  return Promise.reject(error);
79
72
  }
80
73
  }
81
- /** Count the cache outcome of one cacheable read against the current call. */
82
- function recordCacheOutcome(outcome) {
83
- REQUEST_SCOPE.getStore()?.metrics.recordCache(outcome);
84
- }
85
- /**
86
- * Run a cache freshness check so that its requests count as watermark time
87
- * rather than upstream time. Outside a call scope it just runs.
88
- */
89
- function asWatermarkRead(operation) {
90
- const scope = REQUEST_SCOPE.getStore();
91
- if (scope === undefined)
92
- return operation();
93
- return REQUEST_SCOPE.run(Object.freeze({ ...scope, lane: "watermark" }), operation);
94
- }
95
- /** Time one request against the current call, on whichever clock it belongs to. */
96
- function timedRequest(request) {
97
- const scope = REQUEST_SCOPE.getStore();
98
- return scope === undefined ? request() : scope.metrics.measure(scope.lane, request);
99
- }
100
74
  class ServiceNowClient {
101
75
  #baseUrl;
102
76
  #auth;
@@ -361,35 +335,31 @@ class ServiceNowClient {
361
335
  }
362
336
  }
363
337
  exports.ServiceNowClient = ServiceNowClient;
364
- /**
365
- * Build an immutable, reflection-safe capability around a resolved client.
366
- * Every request it makes is timed against the current call (see
367
- * {@link CallMetrics}); the timing never alters, delays or retries a request.
368
- */
338
+ /** Build an immutable, reflection-safe capability around a resolved client. */
369
339
  function createServiceNowOperations(client) {
370
340
  const operations = Object.create(null);
371
341
  Object.defineProperties(operations, {
372
- ...(client.saveAtfStepInputs ? { saveAtfStepInputs: { value: (input) => timedRequest(() => client.saveAtfStepInputs(input)) } } : {}),
342
+ ...(client.saveAtfStepInputs ? { saveAtfStepInputs: { value: (input) => client.saveAtfStepInputs(input) } } : {}),
373
343
  get: {
374
- value: (path, params) => timedRequest(() => client.get(path, params)),
344
+ value: (path, params) => client.get(path, params),
375
345
  },
376
346
  getWithMeta: {
377
- value: (path, params) => timedRequest(() => client.getWithMeta(path, params)),
347
+ value: (path, params) => client.getWithMeta(path, params),
378
348
  },
379
349
  post: {
380
- value: (path, body, params) => timedRequest(() => params === undefined ? client.post(path, body) : client.post(path, body, params)),
350
+ value: (path, body, params) => params === undefined ? client.post(path, body) : client.post(path, body, params),
381
351
  },
382
352
  patch: {
383
- value: (path, body) => timedRequest(() => client.patch(path, body)),
353
+ value: (path, body) => client.patch(path, body),
384
354
  },
385
355
  delete: {
386
- value: (path) => timedRequest(() => client.delete(path)),
356
+ value: (path) => client.delete(path),
387
357
  },
388
358
  postBinary: {
389
- value: (path, data, contentType, params) => timedRequest(() => client.postBinary(path, data, contentType, params)),
359
+ value: (path, data, contentType, params) => client.postBinary(path, data, contentType, params),
390
360
  },
391
361
  getRaw: {
392
- value: (path, options) => timedRequest(() => client.getRaw(path, options)),
362
+ value: (path, options) => client.getRaw(path, options),
393
363
  },
394
364
  });
395
365
  return Object.freeze(operations);