@onlyflows/servicenow-mcp 2.2.0 → 2.3.0-dev.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +288 -1
- package/README.md +141 -7
- package/dist/call-metrics.d.ts +42 -0
- package/dist/call-metrics.d.ts.map +1 -0
- package/dist/call-metrics.js +89 -0
- package/dist/call-metrics.js.map +1 -0
- package/dist/client.d.ts +14 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +40 -10
- package/dist/client.js.map +1 -1
- package/dist/encoded-query-policy.d.ts +9 -0
- package/dist/encoded-query-policy.d.ts.map +1 -1
- package/dist/encoded-query-policy.js +19 -1
- package/dist/encoded-query-policy.js.map +1 -1
- package/dist/http-runtime.js +16 -0
- package/dist/http-runtime.js.map +1 -1
- package/dist/metadata-cache.d.ts +97 -7
- package/dist/metadata-cache.d.ts.map +1 -1
- package/dist/metadata-cache.js +283 -21
- package/dist/metadata-cache.js.map +1 -1
- package/dist/setup-prompts.js +1 -1
- package/dist/setup-prompts.js.map +1 -1
- package/dist/setup.d.ts.map +1 -1
- package/dist/setup.js +10 -1
- package/dist/setup.js.map +1 -1
- package/dist/structured-query.d.ts +61 -2
- package/dist/structured-query.d.ts.map +1 -1
- package/dist/structured-query.js +376 -35
- package/dist/structured-query.js.map +1 -1
- package/dist/tools/codesearch.d.ts.map +1 -1
- package/dist/tools/codesearch.js +24 -4
- package/dist/tools/codesearch.js.map +1 -1
- package/dist/tools/flow-view-module.js +1 -1
- package/dist/tools/flow-view-module.js.map +1 -1
- package/dist/tools/get-module.js +1 -1
- package/dist/tools/get-module.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +24 -11
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/query-module.d.ts.map +1 -1
- package/dist/tools/query-module.js +205 -59
- package/dist/tools/query-module.js.map +1 -1
- package/dist/tools/result-envelope.d.ts +311 -0
- package/dist/tools/result-envelope.d.ts.map +1 -1
- package/dist/tools/result-envelope.js +314 -31
- package/dist/tools/result-envelope.js.map +1 -1
- package/dist/tools/schema-module.d.ts.map +1 -1
- package/dist/tools/schema-module.js +1 -1
- package/dist/tools/schema-module.js.map +1 -1
- package/dist/tools/truncation-hint.d.ts +125 -0
- package/dist/tools/truncation-hint.d.ts.map +1 -0
- package/dist/tools/truncation-hint.js +298 -0
- package/dist/tools/truncation-hint.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/docs/CLIENT-SETUP.md +11 -1
- package/docs/PRODUCTION-SECURITY.md +17 -1
- package/docs/RELEASE-VALIDATION.md +9 -3
- package/package.json +3 -3
- package/scripts/release-validate.mjs +6 -6
- package/server.json +2 -2
- package/tools/inspector/package-lock.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -5,7 +5,294 @@ 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
|
-
## [
|
|
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
|
+
## [2.3.0-rc.1] — 2026-11-14
|
|
262
|
+
|
|
263
|
+
Release candidate for 2.3.0, published to the `next` dist-tag. It contains the
|
|
264
|
+
changes listed under 2.3.0-dev.1 below and nothing else.
|
|
265
|
+
|
|
266
|
+
## [2.3.0-dev.1] — 2026-11-14
|
|
267
|
+
|
|
268
|
+
### Added
|
|
269
|
+
|
|
270
|
+
- **Release candidates publish to `next`.** A `vX.Y.Z-rc.N` tag (cut on the
|
|
271
|
+
`test` branch by convention) now publishes to the `next` dist-tag. Stable and
|
|
272
|
+
`-dev.N` tags are unchanged, and every other prerelease suffix is still
|
|
273
|
+
rejected.
|
|
274
|
+
|
|
275
|
+
### Security
|
|
276
|
+
|
|
277
|
+
- **Container base image.** The runtime base,
|
|
278
|
+
`gcr.io/distroless/nodejs22-debian13:nonroot`, moves to a newer digest whose
|
|
279
|
+
`zlib1g` is 1:1.3.dfsg+really1.3.1-1+deb13u1 and whose Node is 22.23.4,
|
|
280
|
+
clearing CVE-2026-76844 and CVE-2026-85091 from the `container-release`
|
|
281
|
+
scan. The image serves the dormant HTTP transport and is not published.
|
|
282
|
+
- **HTTP server dependencies.** `@hono/node-server` moves from 2.1.3 to 2.1.7
|
|
283
|
+
and `hono` (transitive, through the MCP SDK) from 4.13.13 to 4.13.18,
|
|
284
|
+
clearing the advisories that `npm audit --omit=dev` reported:
|
|
285
|
+
GHSA-qv5m-9pm6-hqp3 and GHSA-jpvv-r467-5p4w in `@hono/node-server`, and
|
|
286
|
+
GHSA-4m76-xfj5-7975, GHSA-h7mg-cq63-vhpq, GHSA-3gg2-335m-rxc6,
|
|
287
|
+
GHSA-4h7h-rv7c-7m2v and GHSA-46wx-v44x-9hh2 in `hono`. The same releases
|
|
288
|
+
also carry the fixes for GHSA-7v5p-43qr-wch5 and GHSA-fj57-4f93-cfw6
|
|
289
|
+
(`@hono/node-server`) and GHSA-92p4-j3wq-jmqx, GHSA-39q9-qp46-w8xg and
|
|
290
|
+
GHSA-74fm-fwc7-3fwp (`hono`). The `tools/inspector` lock moves to `hono`
|
|
291
|
+
4.13.18 and `@hono/node-server` 2.1.8. In the published package, only the
|
|
292
|
+
dormant HTTP transport uses these packages. One behaviour
|
|
293
|
+
change: a request to `/mcp` whose raw path contains a backslash (for example
|
|
294
|
+
`\mcp`, which the server's own path check reads as `/mcp`) now gets 400 Bad
|
|
295
|
+
Request.
|
|
9
296
|
|
|
10
297
|
## [2.2.0] — 2026-10-30
|
|
11
298
|
|
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",
|
|
409
|
+
"sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch",
|
|
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"],
|
|
419
|
+
"tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch"],
|
|
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 |
|
|
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) |
|
|
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. |
|
|
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 |
|
|
720
720
|
| `sn_discover` | Discover tables, scoped apps, store apps, plugins |
|
|
721
721
|
|
|
722
722
|
### Testing & Automation
|
|
@@ -848,10 +848,25 @@ 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*`,
|
|
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
|
|
852
856
|
`metadataCache.tables` on a file-backed profile, or `SN_METADATA_CACHE_TTL_MS`
|
|
853
|
-
/ `SN_METADATA_CACHE_TABLES` for the explicit environment profile
|
|
854
|
-
|
|
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*`.
|
|
855
870
|
|
|
856
871
|
**Freshness is checked against the instance, in every auth mode.** Before each
|
|
857
872
|
fetch the cache reads a watermark in one small request: the table's row count
|
|
@@ -871,6 +886,45 @@ A tool call reads each table's watermark once, however many times it reads the
|
|
|
871
886
|
table, until the call writes. A hierarchy walk reads `sys_db_object` once for
|
|
872
887
|
the whole chain. An empty table caches like any other.
|
|
873
888
|
|
|
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
|
+
|
|
874
928
|
If a table's watermark cannot be used, its reads go straight upstream, without
|
|
875
929
|
a watermark request, for a while: 15 minutes when the cause persists (an
|
|
876
930
|
incomplete or future-dated watermark, a 403 or 404), 30 seconds when it may not
|
|
@@ -893,6 +947,72 @@ identity, and effective policy, so a repeat call costs no request at all. They
|
|
|
893
947
|
are not revalidated in that window; `force_recache: true` refreshes them, and
|
|
894
948
|
`schemaCacheTtlMs` / `SN_SCHEMA_CACHE_TTL_MS` (up to 1 hour) changes the window.
|
|
895
949
|
|
|
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
|
+
|
|
896
1016
|
### Unrestricted field selection (`fields=all`, `response_format=detailed`)
|
|
897
1017
|
|
|
898
1018
|
Both resolve to the profile's readable set for the table. Where the field
|
|
@@ -986,6 +1106,20 @@ servicenow-mcp-setup grant --profile dev --read change_request --related change_
|
|
|
986
1106
|
servicenow-mcp-setup grant --profile dev --flows # sn_flow_view's 15 tables, bound to sn_flow_view only
|
|
987
1107
|
```
|
|
988
1108
|
|
|
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
|
+
|
|
989
1123
|
Allowlist entries may be exact table names or the literal `*` to allow every
|
|
990
1124
|
table for that operation. Table names are trimmed, lowercased, deduplicated,
|
|
991
1125
|
and must be valid ServiceNow identifiers.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What one tool call reports about itself: whether the metadata cache served
|
|
3
|
+
* its reads, and where its time went.
|
|
4
|
+
*
|
|
5
|
+
* One {@link CallMetrics} lives in the per-call request scope (see
|
|
6
|
+
* `runWithServiceNowRequestSignal`), so concurrent calls never share one and
|
|
7
|
+
* nothing is global. It only observes: no request, cache decision or policy
|
|
8
|
+
* reads from it. Everything it exposes is a number or one of four fixed
|
|
9
|
+
* strings; it never holds a host, path, parameter or response data.
|
|
10
|
+
*
|
|
11
|
+
* Timing is wall-clock, measured with `performance.now()`. `upstream_ms` and
|
|
12
|
+
* `watermark_ms` are not sums over requests: each is the time during which at
|
|
13
|
+
* least one request of that kind was in flight, so requests that run
|
|
14
|
+
* side by side count once. A figure can therefore never exceed `total_ms`,
|
|
15
|
+
* though the two kinds can overlap each other.
|
|
16
|
+
*
|
|
17
|
+
* @module call-metrics
|
|
18
|
+
*/
|
|
19
|
+
/** How one cacheable read was served. */
|
|
20
|
+
export type CacheOutcome = "hit" | "miss" | "bypass";
|
|
21
|
+
/** The call's cache status: one outcome, or `mixed` when reads differed. */
|
|
22
|
+
export type CacheStatus = CacheOutcome | "mixed";
|
|
23
|
+
/** Which kind of ServiceNow request is being timed. */
|
|
24
|
+
export type RequestLane = "upstream" | "watermark";
|
|
25
|
+
export interface CallTiming {
|
|
26
|
+
readonly total_ms: number;
|
|
27
|
+
readonly upstream_ms: number;
|
|
28
|
+
readonly watermark_ms: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CallMetricsSnapshot {
|
|
31
|
+
/** Absent when the call made no cacheable read. */
|
|
32
|
+
readonly cache?: CacheStatus;
|
|
33
|
+
readonly timing: CallTiming;
|
|
34
|
+
}
|
|
35
|
+
export declare class CallMetrics {
|
|
36
|
+
#private;
|
|
37
|
+
recordCache(outcome: CacheOutcome): void;
|
|
38
|
+
/** Run one request, counting its time against `lane` whether it settles or throws. */
|
|
39
|
+
measure<T>(lane: RequestLane, request: () => Promise<T>): Promise<T>;
|
|
40
|
+
snapshot(): CallMetricsSnapshot;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=call-metrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-metrics.d.ts","sourceRoot":"","sources":["../src/call-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,yCAAyC;AACzC,MAAM,MAAM,YAAY,GAAG,KAAK,GAAG,MAAM,GAAG,QAAQ,CAAC;AAErD,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,OAAO,CAAC;AAEjD,uDAAuD;AACvD,MAAM,MAAM,WAAW,GAAG,UAAU,GAAG,WAAW,CAAC;AAEnD,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,mDAAmD;IACnD,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;CAC7B;AA4BD,qBAAa,WAAW;;IAQtB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAIxC,sFAAsF;IAChF,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAS1E,QAAQ,IAAI,mBAAmB;CAiBhC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What one tool call reports about itself: whether the metadata cache served
|
|
4
|
+
* its reads, and where its time went.
|
|
5
|
+
*
|
|
6
|
+
* One {@link CallMetrics} lives in the per-call request scope (see
|
|
7
|
+
* `runWithServiceNowRequestSignal`), so concurrent calls never share one and
|
|
8
|
+
* nothing is global. It only observes: no request, cache decision or policy
|
|
9
|
+
* reads from it. Everything it exposes is a number or one of four fixed
|
|
10
|
+
* strings; it never holds a host, path, parameter or response data.
|
|
11
|
+
*
|
|
12
|
+
* Timing is wall-clock, measured with `performance.now()`. `upstream_ms` and
|
|
13
|
+
* `watermark_ms` are not sums over requests: each is the time during which at
|
|
14
|
+
* least one request of that kind was in flight, so requests that run
|
|
15
|
+
* side by side count once. A figure can therefore never exceed `total_ms`,
|
|
16
|
+
* though the two kinds can overlap each other.
|
|
17
|
+
*
|
|
18
|
+
* @module call-metrics
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.CallMetrics = void 0;
|
|
22
|
+
/**
|
|
23
|
+
* Time during which at least one tracked request was in flight. A request
|
|
24
|
+
* entering while another is running does not restart the clock.
|
|
25
|
+
*/
|
|
26
|
+
class BusyClock {
|
|
27
|
+
#active = 0;
|
|
28
|
+
#busySince = 0;
|
|
29
|
+
#accumulated = 0;
|
|
30
|
+
enter() {
|
|
31
|
+
if (this.#active === 0)
|
|
32
|
+
this.#busySince = performance.now();
|
|
33
|
+
this.#active += 1;
|
|
34
|
+
let left = false;
|
|
35
|
+
return () => {
|
|
36
|
+
if (left)
|
|
37
|
+
return;
|
|
38
|
+
left = true;
|
|
39
|
+
this.#active -= 1;
|
|
40
|
+
if (this.#active === 0)
|
|
41
|
+
this.#accumulated += performance.now() - this.#busySince;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
read(now) {
|
|
45
|
+
return this.#accumulated + (this.#active > 0 ? now - this.#busySince : 0);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class CallMetrics {
|
|
49
|
+
#startedAt = performance.now();
|
|
50
|
+
#outcomes = new Set();
|
|
51
|
+
#clocks = {
|
|
52
|
+
upstream: new BusyClock(),
|
|
53
|
+
watermark: new BusyClock(),
|
|
54
|
+
};
|
|
55
|
+
recordCache(outcome) {
|
|
56
|
+
this.#outcomes.add(outcome);
|
|
57
|
+
}
|
|
58
|
+
/** Run one request, counting its time against `lane` whether it settles or throws. */
|
|
59
|
+
async measure(lane, request) {
|
|
60
|
+
const leave = this.#clocks[lane].enter();
|
|
61
|
+
try {
|
|
62
|
+
return await request();
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
leave();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
snapshot() {
|
|
69
|
+
const now = performance.now();
|
|
70
|
+
const cache = this.#outcomes.size === 0
|
|
71
|
+
? undefined
|
|
72
|
+
: this.#outcomes.size === 1
|
|
73
|
+
? [...this.#outcomes][0]
|
|
74
|
+
: "mixed";
|
|
75
|
+
return {
|
|
76
|
+
...(cache === undefined ? {} : { cache }),
|
|
77
|
+
timing: {
|
|
78
|
+
total_ms: wholeMs(now - this.#startedAt),
|
|
79
|
+
upstream_ms: wholeMs(this.#clocks.upstream.read(now)),
|
|
80
|
+
watermark_ms: wholeMs(this.#clocks.watermark.read(now)),
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.CallMetrics = CallMetrics;
|
|
86
|
+
function wholeMs(value) {
|
|
87
|
+
return Number.isFinite(value) && value > 0 ? Math.round(value) : 0;
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=call-metrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"call-metrics.js","sourceRoot":"","sources":["../src/call-metrics.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAuBH;;;GAGG;AACH,MAAM,SAAS;IACb,OAAO,GAAG,CAAC,CAAC;IACZ,UAAU,GAAG,CAAC,CAAC;IACf,YAAY,GAAG,CAAC,CAAC;IAEjB,KAAK;QACH,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC;YAAE,IAAI,CAAC,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC5D,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,IAAI,IAAI,GAAG,KAAK,CAAC;QACjB,OAAO,GAAG,EAAE;YACV,IAAI,IAAI;gBAAE,OAAO;YACjB,IAAI,GAAG,IAAI,CAAC;YACZ,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;YAClB,IAAI,IAAI,CAAC,OAAO,KAAK,CAAC;gBAAE,IAAI,CAAC,YAAY,IAAI,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;QACnF,CAAC,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,GAAW;QACd,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,IAAI,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5E,CAAC;CACF;AAED,MAAa,WAAW;IACb,UAAU,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;IAC/B,SAAS,GAAG,IAAI,GAAG,EAAgB,CAAC;IACpC,OAAO,GAA6C;QAC3D,QAAQ,EAAE,IAAI,SAAS,EAAE;QACzB,SAAS,EAAE,IAAI,SAAS,EAAE;KAC3B,CAAC;IAEF,WAAW,CAAC,OAAqB;QAC/B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,sFAAsF;IACtF,KAAK,CAAC,OAAO,CAAI,IAAiB,EAAE,OAAyB;QAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,CAAC;QACzC,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,EAAE,CAAC;QACzB,CAAC;gBAAS,CAAC;YACT,KAAK,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IAED,QAAQ;QACN,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QAC9B,MAAM,KAAK,GACT,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;YACvB,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC;gBACzB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;gBACxB,CAAC,CAAC,OAAO,CAAC;QAChB,OAAO;YACL,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;YACzC,MAAM,EAAE;gBACN,QAAQ,EAAE,OAAO,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC;gBACxC,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACrD,YAAY,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;aACxD;SACF,CAAC;IACJ,CAAC;CACF;AAvCD,kCAuCC;AAED,SAAS,OAAO,CAAC,KAAa;IAC5B,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC"}
|