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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/CHANGELOG.md +788 -3
  2. package/README.md +446 -41
  3. package/dist/atf-policy.d.ts +1 -1
  4. package/dist/atf-policy.d.ts.map +1 -1
  5. package/dist/atf-policy.js +2 -0
  6. package/dist/atf-policy.js.map +1 -1
  7. package/dist/call-metrics.d.ts +42 -0
  8. package/dist/call-metrics.d.ts.map +1 -0
  9. package/dist/call-metrics.js +89 -0
  10. package/dist/call-metrics.js.map +1 -0
  11. package/dist/client.d.ts +18 -14
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +51 -36
  14. package/dist/client.js.map +1 -1
  15. package/dist/code-search-snippet.d.ts +25 -0
  16. package/dist/code-search-snippet.d.ts.map +1 -0
  17. package/dist/code-search-snippet.js +67 -0
  18. package/dist/code-search-snippet.js.map +1 -0
  19. package/dist/code-search-targets.d.ts +66 -0
  20. package/dist/code-search-targets.d.ts.map +1 -0
  21. package/dist/code-search-targets.js +82 -0
  22. package/dist/code-search-targets.js.map +1 -0
  23. package/dist/config.d.ts +1 -1
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/credential-tables.d.ts +32 -0
  26. package/dist/credential-tables.d.ts.map +1 -0
  27. package/dist/credential-tables.js +58 -0
  28. package/dist/credential-tables.js.map +1 -0
  29. package/dist/encoded-query-policy.d.ts +9 -0
  30. package/dist/encoded-query-policy.d.ts.map +1 -1
  31. package/dist/encoded-query-policy.js +27 -2
  32. package/dist/encoded-query-policy.js.map +1 -1
  33. package/dist/execution-context.d.ts +14 -0
  34. package/dist/execution-context.d.ts.map +1 -1
  35. package/dist/execution-context.js +8 -0
  36. package/dist/execution-context.js.map +1 -1
  37. package/dist/field-policy.d.ts +44 -1
  38. package/dist/field-policy.d.ts.map +1 -1
  39. package/dist/field-policy.js +623 -35
  40. package/dist/field-policy.js.map +1 -1
  41. package/dist/hidden-values.d.ts +225 -0
  42. package/dist/hidden-values.d.ts.map +1 -0
  43. package/dist/hidden-values.js +748 -0
  44. package/dist/hidden-values.js.map +1 -0
  45. package/dist/http-entrypoint.d.ts.map +1 -1
  46. package/dist/http-entrypoint.js +7 -0
  47. package/dist/http-entrypoint.js.map +1 -1
  48. package/dist/http-observability.js +1 -0
  49. package/dist/http-observability.js.map +1 -1
  50. package/dist/http-runtime.js +16 -0
  51. package/dist/http-runtime.js.map +1 -1
  52. package/dist/index.js +7 -0
  53. package/dist/index.js.map +1 -1
  54. package/dist/metadata-cache.d.ts +135 -7
  55. package/dist/metadata-cache.d.ts.map +1 -1
  56. package/dist/metadata-cache.js +357 -21
  57. package/dist/metadata-cache.js.map +1 -1
  58. package/dist/policy-card.d.ts +16 -1
  59. package/dist/policy-card.d.ts.map +1 -1
  60. package/dist/policy-card.js +15 -2
  61. package/dist/policy-card.js.map +1 -1
  62. package/dist/profile-admin.d.ts +18 -0
  63. package/dist/profile-admin.d.ts.map +1 -1
  64. package/dist/profile-admin.js +26 -1
  65. package/dist/profile-admin.js.map +1 -1
  66. package/dist/profile-manager.d.ts +13 -1
  67. package/dist/profile-manager.d.ts.map +1 -1
  68. package/dist/profile-manager.js +23 -1
  69. package/dist/profile-manager.js.map +1 -1
  70. package/dist/response-too-large.d.ts +23 -0
  71. package/dist/response-too-large.d.ts.map +1 -0
  72. package/dist/response-too-large.js +42 -0
  73. package/dist/response-too-large.js.map +1 -0
  74. package/dist/risky-grants.d.ts +6 -2
  75. package/dist/risky-grants.d.ts.map +1 -1
  76. package/dist/risky-grants.js +58 -5
  77. package/dist/risky-grants.js.map +1 -1
  78. package/dist/setup-prompts.js +1 -1
  79. package/dist/setup-prompts.js.map +1 -1
  80. package/dist/setup.d.ts +4 -0
  81. package/dist/setup.d.ts.map +1 -1
  82. package/dist/setup.js +176 -68
  83. package/dist/setup.js.map +1 -1
  84. package/dist/structured-query.d.ts +61 -2
  85. package/dist/structured-query.d.ts.map +1 -1
  86. package/dist/structured-query.js +382 -36
  87. package/dist/structured-query.js.map +1 -1
  88. package/dist/table-policy.d.ts +75 -2
  89. package/dist/table-policy.d.ts.map +1 -1
  90. package/dist/table-policy.js +184 -15
  91. package/dist/table-policy.js.map +1 -1
  92. package/dist/tool-error.d.ts +47 -4
  93. package/dist/tool-error.d.ts.map +1 -1
  94. package/dist/tool-error.js +104 -4
  95. package/dist/tool-error.js.map +1 -1
  96. package/dist/tool-table-access.d.ts +9 -2
  97. package/dist/tool-table-access.d.ts.map +1 -1
  98. package/dist/tool-table-access.js +118 -36
  99. package/dist/tool-table-access.js.map +1 -1
  100. package/dist/tools/aggregate.js +2 -2
  101. package/dist/tools/aggregate.js.map +1 -1
  102. package/dist/tools/all-fields-cap.d.ts.map +1 -1
  103. package/dist/tools/all-fields-cap.js +29 -7
  104. package/dist/tools/all-fields-cap.js.map +1 -1
  105. package/dist/tools/atf-author-module.d.ts +1 -7
  106. package/dist/tools/atf-author-module.d.ts.map +1 -1
  107. package/dist/tools/atf-author-module.js +16 -7
  108. package/dist/tools/atf-author-module.js.map +1 -1
  109. package/dist/tools/atf-contracts.d.ts +69 -4
  110. package/dist/tools/atf-contracts.d.ts.map +1 -1
  111. package/dist/tools/atf-contracts.js +32 -2
  112. package/dist/tools/atf-contracts.js.map +1 -1
  113. package/dist/tools/atf-renderers.js +2 -1
  114. package/dist/tools/atf-renderers.js.map +1 -1
  115. package/dist/tools/atf-results-module.d.ts.map +1 -1
  116. package/dist/tools/atf-results-module.js +5 -3
  117. package/dist/tools/atf-results-module.js.map +1 -1
  118. package/dist/tools/atf-run-module.js +3 -2
  119. package/dist/tools/atf-run-module.js.map +1 -1
  120. package/dist/tools/atf-shared.d.ts +6 -0
  121. package/dist/tools/atf-shared.d.ts.map +1 -1
  122. package/dist/tools/atf-shared.js +49 -10
  123. package/dist/tools/atf-shared.js.map +1 -1
  124. package/dist/tools/atf-step-catalog.d.ts +13 -8
  125. package/dist/tools/atf-step-catalog.d.ts.map +1 -1
  126. package/dist/tools/atf-step-catalog.js +169 -5
  127. package/dist/tools/atf-step-catalog.js.map +1 -1
  128. package/dist/tools/batch.d.ts.map +1 -1
  129. package/dist/tools/batch.js +25 -7
  130. package/dist/tools/batch.js.map +1 -1
  131. package/dist/tools/catalog.d.ts.map +1 -1
  132. package/dist/tools/catalog.js +2 -1
  133. package/dist/tools/catalog.js.map +1 -1
  134. package/dist/tools/codesearch.d.ts +2 -2
  135. package/dist/tools/codesearch.d.ts.map +1 -1
  136. package/dist/tools/codesearch.js +536 -67
  137. package/dist/tools/codesearch.js.map +1 -1
  138. package/dist/tools/flow-view-contracts.d.ts +59 -3
  139. package/dist/tools/flow-view-contracts.d.ts.map +1 -1
  140. package/dist/tools/flow-view-contracts.js +34 -2
  141. package/dist/tools/flow-view-contracts.js.map +1 -1
  142. package/dist/tools/flow-view-graph.d.ts +14 -0
  143. package/dist/tools/flow-view-graph.d.ts.map +1 -1
  144. package/dist/tools/flow-view-graph.js +43 -1
  145. package/dist/tools/flow-view-graph.js.map +1 -1
  146. package/dist/tools/flow-view-module.js +2 -2
  147. package/dist/tools/flow-view-module.js.map +1 -1
  148. package/dist/tools/flow-view-policy.d.ts +3 -3
  149. package/dist/tools/flow-view-policy.d.ts.map +1 -1
  150. package/dist/tools/flow-view-policy.js +5 -4
  151. package/dist/tools/flow-view-policy.js.map +1 -1
  152. package/dist/tools/flow-view-renderers.d.ts.map +1 -1
  153. package/dist/tools/flow-view-renderers.js +9 -21
  154. package/dist/tools/flow-view-renderers.js.map +1 -1
  155. package/dist/tools/get-module.js +1 -1
  156. package/dist/tools/get-module.js.map +1 -1
  157. package/dist/tools/index.d.ts.map +1 -1
  158. package/dist/tools/index.js +116 -25
  159. package/dist/tools/index.js.map +1 -1
  160. package/dist/tools/platform-view-contracts.d.ts +189 -0
  161. package/dist/tools/platform-view-contracts.d.ts.map +1 -0
  162. package/dist/tools/platform-view-contracts.js +353 -0
  163. package/dist/tools/platform-view-contracts.js.map +1 -0
  164. package/dist/tools/platform-view-evaluate.d.ts +219 -0
  165. package/dist/tools/platform-view-evaluate.d.ts.map +1 -0
  166. package/dist/tools/platform-view-evaluate.js +1346 -0
  167. package/dist/tools/platform-view-evaluate.js.map +1 -0
  168. package/dist/tools/platform-view-module.d.ts +28 -0
  169. package/dist/tools/platform-view-module.d.ts.map +1 -0
  170. package/dist/tools/platform-view-module.js +111 -0
  171. package/dist/tools/platform-view-module.js.map +1 -0
  172. package/dist/tools/platform-view-scan.d.ts +57 -0
  173. package/dist/tools/platform-view-scan.d.ts.map +1 -0
  174. package/dist/tools/platform-view-scan.js +375 -0
  175. package/dist/tools/platform-view-scan.js.map +1 -0
  176. package/dist/tools/platform-view-upgrades.d.ts +152 -0
  177. package/dist/tools/platform-view-upgrades.d.ts.map +1 -0
  178. package/dist/tools/platform-view-upgrades.js +545 -0
  179. package/dist/tools/platform-view-upgrades.js.map +1 -0
  180. package/dist/tools/profile.d.ts.map +1 -1
  181. package/dist/tools/profile.js +1 -0
  182. package/dist/tools/profile.js.map +1 -1
  183. package/dist/tools/query-module.d.ts.map +1 -1
  184. package/dist/tools/query-module.js +231 -64
  185. package/dist/tools/query-module.js.map +1 -1
  186. package/dist/tools/record-write-shared.d.ts.map +1 -1
  187. package/dist/tools/record-write-shared.js +4 -3
  188. package/dist/tools/record-write-shared.js.map +1 -1
  189. package/dist/tools/result-envelope.d.ts +429 -38
  190. package/dist/tools/result-envelope.d.ts.map +1 -1
  191. package/dist/tools/result-envelope.js +372 -36
  192. package/dist/tools/result-envelope.js.map +1 -1
  193. package/dist/tools/schema-module.d.ts.map +1 -1
  194. package/dist/tools/schema-module.js +1 -1
  195. package/dist/tools/schema-module.js.map +1 -1
  196. package/dist/tools/syslog-cursor.d.ts +61 -0
  197. package/dist/tools/syslog-cursor.d.ts.map +1 -0
  198. package/dist/tools/syslog-cursor.js +146 -0
  199. package/dist/tools/syslog-cursor.js.map +1 -0
  200. package/dist/tools/syslog.d.ts +2 -0
  201. package/dist/tools/syslog.d.ts.map +1 -1
  202. package/dist/tools/syslog.js +126 -2
  203. package/dist/tools/syslog.js.map +1 -1
  204. package/dist/tools/truncation-hint.d.ts +125 -0
  205. package/dist/tools/truncation-hint.d.ts.map +1 -0
  206. package/dist/tools/truncation-hint.js +298 -0
  207. package/dist/tools/truncation-hint.js.map +1 -0
  208. package/dist/unknown-filter-fields.d.ts +52 -0
  209. package/dist/unknown-filter-fields.d.ts.map +1 -0
  210. package/dist/unknown-filter-fields.js +87 -0
  211. package/dist/unknown-filter-fields.js.map +1 -0
  212. package/dist/update-set-eval/engine.d.ts +29 -0
  213. package/dist/update-set-eval/engine.d.ts.map +1 -0
  214. package/dist/update-set-eval/engine.js +405 -0
  215. package/dist/update-set-eval/engine.js.map +1 -0
  216. package/dist/update-set-eval/prepare.d.ts +72 -0
  217. package/dist/update-set-eval/prepare.d.ts.map +1 -0
  218. package/dist/update-set-eval/prepare.js +216 -0
  219. package/dist/update-set-eval/prepare.js.map +1 -0
  220. package/dist/update-set-eval/rules.d.ts +126 -0
  221. package/dist/update-set-eval/rules.d.ts.map +1 -0
  222. package/dist/update-set-eval/rules.js +927 -0
  223. package/dist/update-set-eval/rules.js.map +1 -0
  224. package/dist/update-set-eval/script-scan.d.ts +65 -0
  225. package/dist/update-set-eval/script-scan.d.ts.map +1 -0
  226. package/dist/update-set-eval/script-scan.js +378 -0
  227. package/dist/update-set-eval/script-scan.js.map +1 -0
  228. package/dist/update-set-eval/secret-patterns.d.ts +75 -0
  229. package/dist/update-set-eval/secret-patterns.d.ts.map +1 -0
  230. package/dist/update-set-eval/secret-patterns.js +570 -0
  231. package/dist/update-set-eval/secret-patterns.js.map +1 -0
  232. package/dist/update-set-eval/types.d.ts +181 -0
  233. package/dist/update-set-eval/types.d.ts.map +1 -0
  234. package/dist/update-set-eval/types.js +20 -0
  235. package/dist/update-set-eval/types.js.map +1 -0
  236. package/dist/update-set-eval/xml-reader.d.ts +117 -0
  237. package/dist/update-set-eval/xml-reader.d.ts.map +1 -0
  238. package/dist/update-set-eval/xml-reader.js +561 -0
  239. package/dist/update-set-eval/xml-reader.js.map +1 -0
  240. package/dist/version.d.ts +1 -1
  241. package/dist/version.js +1 -1
  242. package/docs/CLIENT-SETUP.md +30 -7
  243. package/docs/FLOW-VIEW.md +14 -5
  244. package/docs/PRODUCTION-SECURITY.md +84 -1
  245. package/docs/PROFILE-CREDENTIALS.md +10 -4
  246. package/docs/V2-MIGRATION.md +1 -1
  247. package/package.json +1 -1
  248. package/server.json +2 -2
package/README.md CHANGED
@@ -65,8 +65,11 @@ and **Codex** automatically; **Claude Desktop**, **Cursor**, **VS Code** and
65
65
  2. **Set up a connection:** `servicenow-mcp-setup`. It asks for your instance
66
66
  and credential, checks them against the instance, asks which tables to
67
67
  allow, and registers Claude Code and Codex if their CLIs are installed.
68
- Choose **OAuth** when the wizard asks for the authentication type; Basic
69
- is the wizard's default but is [deprecated by ServiceNow](#basic-default-deprecated-by-servicenow).
68
+ The wizard's authentication type defaults to **OAuth client credentials**,
69
+ so you can press Enter at that prompt. You need an Application Registry
70
+ entry on the instance first: see [OAuth 2.0](#oauth-20-recommended). Basic
71
+ is still offered, marked legacy, because ServiceNow is
72
+ [retiring it for REST calls](#basic-legacy-deprecated-by-servicenow).
70
73
  3. **Open your client and ask.** There is no server to start; the client
71
74
  launches `servicenow-mcp` itself.
72
75
 
@@ -114,19 +117,32 @@ instance. Press Ctrl+C at any point to stop; nothing will be saved.
114
117
  Profile name [dev]: dev
115
118
  ServiceNow instance (for example dev12345.service-now.com): dev12345.service-now.com
116
119
  Authentication:
117
- 1) basic (default)
118
- 2) oauth
119
- 3) apikey
120
+ 1) oauth (default) - client credentials, recommended
121
+ 2) apikey - inbound API key
122
+ 3) basic - legacy, not recommended: ServiceNow is retiring it
123
+ Choice [1]: 1
124
+
125
+ OAuth client credentials need these on the instance:
126
+ - an Application Registry entry (System OAuth > Application Registry)
127
+ with a client ID and client secret
128
+ - the client credentials grant enabled for it
129
+ - an OAuth Application User: the integration user this server acts as,
130
+ with only the roles it needs, not an administrator
131
+ Steps: README, section Authentication > OAuth 2.0.
132
+
133
+ OAuth grant type:
134
+ 1) client_credentials (default)
135
+ 2) password
120
136
  Choice [1]: 1
121
137
  How should the credential be stored?:
122
138
  1) encrypted (default)
123
139
  2) reference
124
140
  Choice [1]: 1
125
- ServiceNow username: integration.user
141
+ OAuth client id (not a secret): <your-client-id>
126
142
 
127
143
  Enter each secret now. Input is hidden — nothing you type from here
128
144
  is displayed.
129
- credential:
145
+ clientSecret:
130
146
 
131
147
  Verifying against the instance...
132
148
  ok https://dev12345.service-now.com accepted the credential.
@@ -161,7 +177,7 @@ ok node: v22.11.0
161
177
  ok server command: servicenow-mcp resolves on PATH; clients spawn it over stdio
162
178
  ok config directory: ~/.servicenow-mcp (0700)
163
179
  ok profile dev: instance: https://dev12345.service-now.com
164
- ok profile dev: credential: basic credential resolves from its encrypted source
180
+ ok profile dev: credential: oauth clientSecret resolves from its encrypted source
165
181
  ok profile dev: table access: 1 read, 1 write, 1 target(s)
166
182
 
167
183
  All checks passed.
@@ -191,11 +207,23 @@ servicenow-mcp-setup doctor --profile dev
191
207
  global install, and `servicenow-mcp setup` is an alias for
192
208
  `servicenow-mcp-setup`.
193
209
 
210
+ If you choose Basic and the instance answers 401, the wizard explains the
211
+ Basic Auth restriction and asks what next: `retry` with the same settings,
212
+ switch to `oauth` (it discards the Basic credential and asks the OAuth
213
+ questions, keeping the profile name and instance), or `stop`. Nothing is
214
+ saved until a credential verifies.
215
+
194
216
  ### Scripted setup
195
217
 
196
218
  Pass any flag, or run without a terminal, and the wizard steps aside for the
197
219
  original non-interactive behavior — so CI and provisioning scripts are
198
- unaffected. `--non-interactive` forces it explicitly:
220
+ unaffected. `--non-interactive` forces it explicitly. Only the interactive
221
+ wizard defaults to OAuth. `servicenow-mcp-profile create` has no default you
222
+ should rely on: pass `--auth-type oauth` (recommended) or `--auth-type basic`.
223
+ Left out, it still creates a Basic profile, as it always has, so existing
224
+ scripts keep working, and it prints a deprecation notice only when standard
225
+ error is an interactive terminal, so output a script captures is unchanged. A
226
+ future release may require the flag.
199
227
 
200
228
  ```bash
201
229
  servicenow-mcp-setup --non-interactive --clients none --json
@@ -217,7 +245,9 @@ servicenow-mcp-setup grant --profile dev --read incident,problem --write inciden
217
245
  `grant` and the wizard print a warning, and still grant, when write access
218
246
  lands on a privilege-sensitive table: role, group, approval, script,
219
247
  property, user or authentication tables such as `sys_user_has_role`,
220
- `sysapproval_approver` or `sys_script`.
248
+ `sysapproval_approver`, `sys_script` or `sp_widget`, and the MID Server queue
249
+ (`ecc_queue` and its rotation shards), whose records can run commands on MID
250
+ Server hosts.
221
251
 
222
252
  `--force` regenerates the owner/client identifiers but deliberately preserves
223
253
  `SN_PROFILE_ENCRYPTION_KEY`, which decrypts every credential envelope in
@@ -334,7 +364,8 @@ MCP_OWNER_ID=local-owner \
334
364
  MCP_CLIENT_ID=local-client \
335
365
  SN_PROFILE_NAME=dev \
336
366
  SN_INSTANCE=https://yourinstance.service-now.com \
337
- SN_USER=your_user \
367
+ SN_AUTH_TYPE=oauth \
368
+ SN_CLIENT_ID=your-non-secret-client-id \
338
369
  SN_ALLOWED_READ_TABLES=incident,problem,change_request \
339
370
  SN_ALLOWED_WRITE_TABLES=incident,change_request \
340
371
  SN_TABLE_ACCESS_TARGETS='[{"table":"incident","kind":"canonical","tools":["sn_query","sn_get","sn_create","sn_update","sn_incident_add_comment","sn_incident_add_work_note","sn_delete","sn_batch"],"closureComplete":true,"relatedTables":["incident"]},{"table":"problem","kind":"canonical","tools":["sn_query","sn_get"],"closureComplete":true,"relatedTables":["problem"]},{"table":"change_request","kind":"canonical","tools":["sn_query","sn_get"],"closureComplete":true,"relatedTables":["change_request"]}]' \
@@ -379,8 +410,8 @@ without putting them in argv, and it writes the file with the right ownership
379
410
  and mode:
380
411
 
381
412
  ```bash
382
- servicenow-mcp-profile create --name dev --instance https://mydev.service-now.com --auth-type basic --username admin --source reference --provider env
383
- servicenow-mcp-profile create --name prod --instance https://myprod.service-now.com --auth-type basic --username api.user --source reference --provider env
413
+ servicenow-mcp-profile create --name dev --instance https://mydev.service-now.com --auth-type oauth --client-id <dev-client-id> --source reference --provider env
414
+ servicenow-mcp-profile create --name prod --instance https://myprod.service-now.com --auth-type oauth --client-id <prod-client-id> --source reference --provider env
384
415
 
385
416
  servicenow-mcp-setup grant --profile dev --read incident,problem --write incident
386
417
  servicenow-mcp-setup grant --profile prod --read incident
@@ -395,8 +426,9 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
395
426
  "profiles": {
396
427
  "dev": {
397
428
  "instance": "https://mydev.service-now.com",
398
- "username": "admin",
399
- "credential": { "type": "secret_ref", "provider": "env", "reference": "SN_PASSWORD_DEV" },
429
+ "authType": "oauth",
430
+ "clientId": "your-dev-client-id",
431
+ "clientSecret": { "type": "secret_ref", "provider": "env", "reference": "SN_CLIENT_SECRET_DEV" },
400
432
  "description": "Development instance",
401
433
  "tableAccess": {
402
434
  "readTables": ["incident", "problem"],
@@ -406,7 +438,7 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
406
438
  "table": "incident",
407
439
  "kind": "canonical",
408
440
  "tools": [
409
- "sn_query", "sn_get", "sn_aggregate", "sn_schema",
441
+ "sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch",
410
442
  "sn_create", "sn_update",
411
443
  "sn_incident_add_comment", "sn_incident_add_work_note"
412
444
  ],
@@ -416,7 +448,7 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
416
448
  {
417
449
  "table": "problem",
418
450
  "kind": "canonical",
419
- "tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema"],
451
+ "tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_codesearch"],
420
452
  "closureComplete": true,
421
453
  "relatedTables": ["problem"]
422
454
  }
@@ -428,7 +460,7 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
428
460
  ```
429
461
 
430
462
  Have the approved supervisor, orchestrator, keychain, or secret manager provide
431
- the values referenced by `SN_PASSWORD_DEV` and `SN_PASSWORD_PROD` in the
463
+ the values referenced by `SN_CLIENT_SECRET_DEV` and `SN_CLIENT_SECRET_PROD` in the
432
464
  environment the server is spawned with, or in `~/.servicenow-mcp/server.env`,
433
465
  which the server falls back to. Do not type either value into a shell command,
434
466
  command argument, dotenv file, or command history.
@@ -492,8 +524,10 @@ administrative write; the MCP boundary never consults it.
492
524
 
493
525
  If no config file exists, canonical `SN_*` connection values are exposed only
494
526
  through an explicit `SN_PROFILE_NAME` mapping. For example, set
495
- `SN_PROFILE_NAME=dev` with `SN_INSTANCE`, `SN_USER`, and `SN_PASSWORD`, then
496
- call tools with `profile: "dev"`. Without `SN_PROFILE_NAME`, bare connection
527
+ `SN_PROFILE_NAME=dev` with `SN_INSTANCE`, `SN_AUTH_TYPE=oauth`, `SN_CLIENT_ID`
528
+ and `SN_CLIENT_SECRET`, then call tools with `profile: "dev"`. Without
529
+ `SN_AUTH_TYPE` the environment profile is Basic (`SN_USER` and `SN_PASSWORD`),
530
+ as it has always been; set `SN_AUTH_TYPE` explicitly. Without `SN_PROFILE_NAME`, bare connection
497
531
  variables create no profile and cannot route a request. Secret values remain
498
532
  runtime-only environment references and are never persisted as plaintext.
499
533
 
@@ -501,13 +535,19 @@ runtime-only environment references and are never persisted as plaintext.
501
535
 
502
536
  ## Authentication
503
537
 
504
- Three ServiceNow auth types are available per profile, selected with `authType` (default: `basic`). Profile configuration is managed out of band by the service operator. This is the only authentication involved: the transport is stdio, so there is no endpoint in front of the server to protect.
538
+ Three ServiceNow auth types are available per profile, selected with `authType`. The setup wizard and every example here use OAuth client credentials. A saved profile that has no `authType` is read as Basic, because that is what such a profile has always meant; saved profiles are never rewritten. Profile configuration is managed out of band by the service operator. This is the only authentication involved: the transport is stdio, so there is no endpoint in front of the server to protect.
505
539
 
506
540
  > **Heads up:** ServiceNow's [inbound Basic Auth restriction program](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB3096078) is phasing out basic auth for API requests — instances can start hard-rejecting it at any time (exemptions: Web-Service-Access-Only accounts or the `snc_basic_auth_api_access` role). **OAuth is the recommended auth type.** The server prints a startup warning for basic-auth profiles.
507
541
 
508
542
  ### OAuth 2.0 (recommended)
509
543
 
510
- `client_credentials` grant (default) — create an OAuth API endpoint client in ServiceNow (**System OAuth → Application Registry**) and reference the secret via `env:` indirection:
544
+ `client_credentials` grant (default). On the instance you need three things:
545
+
546
+ 1. An **Application Registry** entry, an OAuth API endpoint for external clients (**System OAuth → Application Registry**), which gives you a client ID and a client secret.
547
+ 2. The **client credentials grant enabled** for it: on current releases the system property `glide.oauth.inbound.client.credential.grant_type.enabled` must be `true`.
548
+ 3. An **OAuth Application User** set on that entry: the integration user the server acts as. Give it the least roles that do the job, not an administrator.
549
+
550
+ Then create the profile with the wizard (`servicenow-mcp-setup`, press Enter at the authentication prompt) or `servicenow-mcp-profile create --auth-type oauth --client-id <client-id>`, or reference the secret via `env:` indirection:
511
551
 
512
552
  ```json
513
553
  {
@@ -553,7 +593,9 @@ For instances using Inbound Authentication Profiles with API keys. The header na
553
593
  }
554
594
  ```
555
595
 
556
- ### Basic (default, deprecated by ServiceNow)
596
+ ### Basic (legacy, deprecated by ServiceNow)
597
+
598
+ Basic is no longer the wizard's default. Use it only for an instance that still accepts it.
557
599
 
558
600
  ```json
559
601
  {
@@ -563,7 +605,7 @@ For instances using Inbound Authentication Profiles with API keys. The header na
563
605
  }
564
606
  ```
565
607
 
566
- On a 401, the error explains the Basic Auth restriction program (KB3096078) and how to move to OAuth.
608
+ On a 401 for a basic-auth profile, the error explains the Basic Auth restriction program (KB3096078): the role `snc_basic_auth_api_access` or a Web-Service-Access-Only account is needed, and OAuth is the recommended way to move off Basic Auth. The setup wizard gives the same explanation when it verifies the credential.
567
609
 
568
610
  ### Timeouts & retries
569
611
 
@@ -626,7 +668,8 @@ export SN_ALLOWED_WRITE_TABLES="incident,change_request"
626
668
  export SN_TABLE_ACCESS_TARGETS='[{"table":"incident","kind":"canonical","tools":["sn_query","sn_get","sn_create","sn_update","sn_incident_add_comment","sn_incident_add_work_note","sn_delete","sn_batch"],"closureComplete":true,"relatedTables":["incident"]},{"table":"problem","kind":"canonical","tools":["sn_query","sn_get"],"closureComplete":true,"relatedTables":["problem"]},{"table":"change_request","kind":"canonical","tools":["sn_query","sn_get"],"closureComplete":true,"relatedTables":["change_request"]}]'
627
669
  export SN_PROFILE_NAME="dev"
628
670
  export SN_INSTANCE="https://yourinstance.service-now.com"
629
- export SN_USER="your_username"
671
+ export SN_AUTH_TYPE="oauth"
672
+ export SN_CLIENT_ID="your-non-secret-oauth-client-id"
630
673
  npm run build
631
674
  npm start
632
675
  ```
@@ -692,7 +735,7 @@ in this section is needed to use this server.
692
735
 
693
736
  | Tool | Description |
694
737
  |------|-------------|
695
- | `sn_query` | Query an approved table with structured filters, field selection, pagination, and sorting; bounded raw reads require an explicit policy rule |
738
+ | `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
739
  | `sn_get` | Get a single record by sys_id from an approved table |
697
740
  | `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
741
  | `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 |
@@ -715,10 +758,42 @@ in this section is needed to use this server.
715
758
  |------|-------------|
716
759
  | `sn_relationships` | CMDB CI graph traversal — upstream/downstream/both, configurable depth |
717
760
  | `sn_attach` | List attachments, return downloads as inline base64, and upload inline base64 content; never touches a host filesystem path |
718
- | `sn_syslog` | Query system logs with severity/source/time filters |
719
- | `sn_codesearch` | Search business rules, script includes, client scripts, etc. |
761
+ | `sn_syslog` | Query system logs with severity/source/time filters, newest first. `tail: true` starts a tail (the newest entries, oldest first, plus a `cursor`); each later call with `after_cursor` returns only the entries after it, oldest first, plus a new `cursor` ([Tailing the system log](#tailing-the-system-log)) |
762
+ | `sn_codesearch` | Search business rules, script includes, client scripts, etc., with a snippet around each match ([Code search](#code-search)). Part of the default read grant, so a plain read grant on a code table allows it |
720
763
  | `sn_discover` | Discover tables, scoped apps, store apps, plugins |
721
764
 
765
+ #### Tailing the system log
766
+
767
+ `sn_syslog` can follow the log without re-reading it. The first call sends
768
+ `tail: true` and gets the newest `limit` entries (inside the `since` window),
769
+ oldest first, and a `cursor`. Each later call sends that cursor as
770
+ `after_cursor` and gets only the entries created after it, oldest first, and a
771
+ new `cursor`; poll no faster than every few seconds.
772
+
773
+ - **No skips, no repeats.** Many log rows share one `sys_created_on` second, so
774
+ the cursor holds the second and the row's `sys_id`, and a call returns the
775
+ rows after that pair. It is an opaque token: pass it back as given.
776
+ - **`has_more`.** If more than `limit` entries are waiting, the call returns
777
+ `limit` of them with `has_more: true` and a cursor at the last one; call again
778
+ with it. A response cut to fit the byte budget does the same, and the cursor
779
+ always names the last entry actually returned. Tail pages carry no `total` and
780
+ no `next_offset`, and `offset` cannot be combined with a tail.
781
+ - **Same filters on every call.** The cursor is bound to the `level`, `source`
782
+ and `message` it was issued for. A call that changes them is refused (so is a
783
+ malformed, oversized or altered cursor) with a fixed message that does not
784
+ repeat the cursor. `since` applies to the first call only, but a cursor older
785
+ than the longest `since` (525,600 minutes, one year) is refused with a fixed
786
+ message: start a new tail. With nothing to return, the call gives the same
787
+ position back, so keep polling with it. If the first call finds no entries in
788
+ its window it returns no cursor; call it again.
789
+ - **Reads go straight to the instance**, never through the metadata cache, and
790
+ use the same table and field policy as an ordinary `sn_syslog` read. A tail
791
+ also reads `sys_id` and `sys_created_on` to place the cursor, so a field policy
792
+ that withholds either refuses it.
793
+ - **Limits.** Order is by creation second, then `sys_id`. A row the instance
794
+ stores late with a creation time at or before the cursor's second is not seen
795
+ by a tail that has already moved past it.
796
+
722
797
  ### Testing & Automation
723
798
 
724
799
  | Tool | Description |
@@ -843,15 +918,102 @@ Two failure modes are worth knowing:
843
918
  builds the request policy with only `allowedHosts` and `allowedOrigins`, so the
844
919
  limit is always 1 MiB and no environment variable changes it.
845
920
 
921
+ ### Code search
922
+
923
+ `sn_codesearch {search_term, table?, field?, limit?, offset?}` finds records
924
+ whose script contains the text, in the business rules, script includes, UI
925
+ scripts, client scripts, scripted REST operations, ES modules and ATF step
926
+ scripts of the instance. Each row
927
+ is `{table, table_label, sys_id, name, snippet, line}`: `snippet` is about 200
928
+ characters of the script centred on the first match (`...` marks a cut) and
929
+ `line` is the line that match is on. The comparison is the instance's
930
+ case-insensitive `LIKE`; if the text holds no literal match for the term, the
931
+ snippet is the head of the script and the row has no `line`.
932
+
933
+ - **One table or all.** With `table`, one table is searched (and `field` can
934
+ name another field of it, such as `name`). With none, every code table the
935
+ profile may read is searched, and the tables left out are named in a warning
936
+ (`Not searched, because this profile does not allow sn_codesearch to read
937
+ them: sys_script, sys_ws_operation. To include one, run servicenow-mcp-setup
938
+ grant --profile <profile> --read <table> --tools sn_codesearch.`). A table is
939
+ left out when the table policy does not bind `sn_codesearch` to it or the field
940
+ policy does not let the profile read its script field. The call fails only when
941
+ none can be read, and the error says why.
942
+ - **ES modules** are `sys_module`: the script is its `content` column and a row
943
+ is named by its `path`, because the table has no `name`. A profile reads it
944
+ once the table policy allows it: `servicenow-mcp-setup grant --profile dev
945
+ --read sys_module`, or a read wildcard. It is cached by default like the other
946
+ code tables, and `fields=all` reads `content`. A default `sn_query` of it lists
947
+ `sys_id`, `path` and `sys_updated_on`. `sys_module` is a built-in system table
948
+ (the 24th), so a `"*"` entry in the field policy does not narrow it: a profile
949
+ whose `"*"` entry limits `readable` and that can read `sys_module` now reads
950
+ `content`, where it did not before. To narrow it, name it in `fieldPolicy`
951
+ (`"sys_module": { "readable": ["sys_id", "path"] }`).
952
+ - **ATF step scripts** are searched with `table: "sys_atf_step"`. A step's script
953
+ is not a column of the step but the value of its script input, a row of
954
+ `sys_variable_value`. The search reads only the rows whose `document` is
955
+ `sys_atf_step` and whose `variable` ends with `script`, a condition fixed in
956
+ the server: no argument can widen it to another table's variables, and `field`
957
+ is refused. Each result is the step (`sys_id` is the step's), named
958
+ `<test name> > step <order>` where `order` is the step's own order value, and
959
+ the steps and then their tests are read by id to say so. Three tables are read,
960
+ so the profile needs read on `sys_variable_value`, `sys_atf_step` and
961
+ `sys_atf_test`, each bound to `sn_codesearch`:
962
+ `servicenow-mcp-setup grant --profile dev --read sys_variable_value,sys_atf_step,sys_atf_test`
963
+ (or `--tools sn_codesearch` to bind only this tool: `sys_variable_value` also
964
+ holds other tables' variable values, which that grant does not let this tool
965
+ search). `grant --atf` binds those tables to `sn_atf_author` only, so a profile
966
+ that has it adds this grant on top. A search with no `table` includes ATF
967
+ step scripts when all three are held and names `sys_atf_step` in the warning
968
+ when they are not. These tables are not in the default cache list: the reads go
969
+ straight to the instance.
970
+ - **A page is shared among the tables.** A search of several tables takes turns:
971
+ each table's first match (script includes first, then business rules, UI
972
+ scripts, client scripts, scripted REST operations, ES modules), then each
973
+ table's second,
974
+ and so on, each table in `sys_id` order. No table crowds the others off page
975
+ 1, and the order depends only on the data, so `offset` and `next_offset` page
976
+ through it exactly. A table with few matches leaves its share to the others.
977
+ - **Large pages degrade, they do not fail.** A script can be hundreds of
978
+ kilobytes, so a page of them does not fit one response. A search of one table
979
+ with `limit` 49 or less reads the scripts with the rows, in one request (and
980
+ falls back to the two steps below if that page passes the cap). A larger page, or a search of several tables, first finds the rows without
981
+ their scripts and then reads the scripts of the rows it returns, 50 at a time,
982
+ narrowing a batch that is still too large. One search spends at most 12 such
983
+ requests and 8 MiB, and only for the rows one response can hold (about 280);
984
+ when that is spent, the remaining rows keep an empty `snippet` and a warning
985
+ says how many (lower `limit`). A script too large to read even on its own gives
986
+ its row an empty `snippet` and `note: "script too large to preview"`; read it
987
+ with `sn_get`. If the rows alone pass the response cap, the
988
+ error says the response was too large and to lower `limit` or `offset`.
989
+ - **The scripts are still field-policy readable fields.** The search reads the
990
+ identifier, the name and the searched field of each table, each subject to the
991
+ profile's field policy, and the sensitive-name rules apply to `field`.
992
+
846
993
  ### Metadata cache
847
994
 
848
995
  Stable ServiceNow metadata reads are cached per instance and credential identity
849
996
  for 24 hours by default. The default cached table patterns are
850
997
  `sys_glide_object`, `sys_dictionary`, `sys_db_object`, `sys_app`, `sys_plugins`,
851
- `sys_metadata*`, and `sys_flow*`. Set `metadataCache.ttlMs` and
998
+ `sys_metadata*`, `sys_flow*`, and the six code tables `sn_codesearch`
999
+ searches: `sys_script`, `sys_script_include`, `sys_ui_script`,
1000
+ `sys_script_client`, `sys_ws_operation`, and `sys_module`. A repeated code search or
1001
+ `sn_query` page on those tables is served from the cache while the table's
1002
+ watermark is unchanged. Set `metadataCache.ttlMs` and
852
1003
  `metadataCache.tables` on a file-backed profile, or `SN_METADATA_CACHE_TTL_MS`
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.
1004
+ / `SN_METADATA_CACHE_TABLES` for the explicit environment profile; a table
1005
+ list you set replaces the default list, so name the code tables in it to keep
1006
+ caching them. `sn_query`, `sn_get`, and `sn_schema` accept `force_recache: true`
1007
+ to refresh metadata; `sn_codesearch` has no such flag, so a change the
1008
+ watermark cannot see shows there after at most one TTL. A cold `sn_get` of a
1009
+ code-table record costs two requests (the watermark, then the record), and
1010
+ `sn_batch` and `sn_aggregate` reads are never cached. Memory is bounded: a
1011
+ response over 512 KiB is not cached, one credential scope keeps at most 32 MiB
1012
+ and the whole cache 128 MiB, evicting the least recently used first. Cached
1013
+ code-table entries hold full script bodies, which can contain hard-coded
1014
+ credentials, in process memory (never on disk) for up to the TTL; to keep them
1015
+ out, set `metadataCache.tables` or `SN_METADATA_CACHE_TABLES` to
1016
+ `sys_glide_object,sys_dictionary,sys_db_object,sys_app,sys_plugins,sys_metadata*,sys_flow*`.
855
1017
 
856
1018
  **Freshness is checked against the instance, in every auth mode.** Before each
857
1019
  fetch the cache reads a watermark in one small request: the table's row count
@@ -871,6 +1033,45 @@ A tool call reads each table's watermark once, however many times it reads the
871
1033
  table, until the call writes. A hierarchy walk reads `sys_db_object` once for
872
1034
  the whole chain. An empty table caches like any other.
873
1035
 
1036
+ **Small responses are not cached.** A hit costs a round trip about the size of
1037
+ a plain read, so a response under 32 KiB (serialized body) saves nothing and is
1038
+ not kept. The first read of such a selector costs the watermark and the read,
1039
+ as before; the server then remembers that selector as small, for one TTL, and
1040
+ reads it again in a single request with no watermark. If a later read of it
1041
+ comes back at 32 KiB or more, it is cached from the next read on. Large reads,
1042
+ such as script bodies, are cached and checked exactly as above, and
1043
+ `force_recache: true` still reads the watermark and refreshes. The memory is
1044
+ per credential scope, holds at most 512 selectors (least recently used out),
1045
+ and costs no cached bytes. A call that read a small selector this way reports
1046
+ `miss`. On a table whose watermark is slow (`sys_dictionary` on a large
1047
+ instance: about 0.5 s against a 0.1 to 0.2 s read in one measurement) even a
1048
+ large read may be faster uncached; the threshold is a size, not a time. A
1049
+ profile's `metadataCache.smallReadBytes` sets the threshold (0 caches every
1050
+ response; at most 512 KiB).
1051
+
1052
+ **Seeing what the cache did.** Every successful response carries two optional
1053
+ fields in `structuredContent.metadata`. `cache` says how the call's cacheable
1054
+ reads were served: `hit` (all from the cache), `miss` (from ServiceNow: nothing
1055
+ cached yet, the watermark moved, the entry expired, the table could not be
1056
+ cached just then, or the response is small and not kept), `bypass` (a `force_recache: true` refresh), or `mixed` (the
1057
+ call made several cacheable reads with different outcomes, such as an
1058
+ `sn_codesearch` with no `table` over the code tables). It is absent when
1059
+ the call read no cache-eligible table. `timing` is `{ total_ms, upstream_ms,
1060
+ watermark_ms }` in whole milliseconds, measured wall-clock: `total_ms` is the
1061
+ whole tool call; `upstream_ms` is the time during which at least one request to
1062
+ ServiceNow other than a watermark read was in flight (retry waits included);
1063
+ `watermark_ms` is the same for the cache's watermark reads. Overlapping
1064
+ requests are counted once, not summed, so each figure is at most `total_ms`,
1065
+ though the two can overlap each other and add up to more than it. A hit reports
1066
+ `upstream_ms: 0` and the watermark round trip it still costs. Callers that
1067
+ share a credential share cache warmth (several profiles on one credential, or
1068
+ several HTTP clients on one profile), so `cache: "hit"` can reflect another
1069
+ caller's earlier read made with the same credential. Both fields hold only
1070
+ numbers and those four words, and appear whether or not the cache is on
1071
+ (`timing` always, `cache` only when a cacheable read happened). Only the server
1072
+ sets them; a tool cannot supply its own. Each tool's `outputSchema` grows by
1073
+ about 320 characters for them.
1074
+
874
1075
  If a table's watermark cannot be used, its reads go straight upstream, without
875
1076
  a watermark request, for a while: 15 minutes when the cause persists (an
876
1077
  incomplete or future-dated watermark, a 403 or 404), 30 seconds when it may not
@@ -893,6 +1094,72 @@ identity, and effective policy, so a repeat call costs no request at all. They
893
1094
  are not revalidated in that window; `force_recache: true` refreshes them, and
894
1095
  `schemaCacheTtlMs` / `SN_SCHEMA_CACHE_TTL_MS` (up to 1 hour) changes the window.
895
1096
 
1097
+ ### Paging when a response is cut to size
1098
+
1099
+ A read that does not fit `max_response_bytes` (or, for a result with more than
1100
+ 1,000 rows, the record limit) is cut by dropping whole rows from the tail, so
1101
+ the rows that come back are always a prefix of the page you asked for. For the
1102
+ list tools, `has_more` and `next_offset` count the rows that were dropped:
1103
+
1104
+ | Field | Meaning |
1105
+ |-------|---------|
1106
+ | `record_count` | Rows in `results`. |
1107
+ | `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`. |
1108
+ | `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". |
1109
+ | `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. |
1110
+
1111
+ When **no row fit**, there is nothing to continue after, so `next_offset` is
1112
+ left out and `metadata.pagination.recovery` is
1113
+ `adjust_request_and_retry_same_offset`: `has_more: true` with no `next_offset`
1114
+ means the request must change (fewer `fields`, a lower `limit`, or a higher
1115
+ `max_response_bytes`; `sn_get` reads one row). The `hint` says which.
1116
+
1117
+ This holds for `sn_query`, `sn_syslog`, `sn_schema`, `sn_relationships`,
1118
+ `sn_codesearch`, `sn_discover`, `sn_attach` (list) and `sn_atf`, whose `offset`
1119
+ is a row offset into the rows they return. Any other collection result that is cut to size
1120
+ (for example `sn_aggregate`) reports `has_more: true` with no `next_offset`.
1121
+ A page that lost no rows to size is unchanged: `has_more` and `next_offset`
1122
+ come from the row after the page, and `next_offset` is `offset + limit`.
1123
+
1124
+ A client that follows `next_offset` should also pass the `limit` the hint names
1125
+ (`continue offset=8 limit=8`): at the original `limit` each page asks
1126
+ ServiceNow for that many rows and the cut drops most of them again, so the same
1127
+ rows are fetched many times over.
1128
+
1129
+ Before this change `next_offset` after a cut page was `offset + limit`, which
1130
+ skipped the dropped rows, and a cut last page reported `has_more: false` with
1131
+ `record_count: 0`.
1132
+
1133
+ **The `sn_query` hint gives values you can use.** For example
1134
+
1135
+ ```text
1136
+ 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).
1137
+ ```
1138
+
1139
+ - `continue offset=8 limit=8` is `next_offset` and the number of rows that fit:
1140
+ page on with that `limit` and nothing is dropped again.
1141
+ - `retry offset=0 with ...` re-reads the whole page in one response, with fewer
1142
+ fields or a larger budget. The two budgets are different numbers, and each
1143
+ says what it buys. `max_response_bytes=1500 (fits the next row)` holds one
1144
+ more row than this response did, so a retry with it returns about one more
1145
+ row; `max_response_bytes=31500 (fits all 22)` holds every row of the page.
1146
+ Both are measured from the response itself (the rows plus the envelope's own
1147
+ metadata) and rounded up. The page figure is left out when it would be more
1148
+ than the 1,000,000-byte maximum (or the `maxResponseBytes` of the raw-read
1149
+ rule that approved a raw `query`, when that is lower) and when only one row
1150
+ was dropped, since the next row is then the rest of the page. When even the
1151
+ next row would be more than that maximum, the hint says the next row exceeds
1152
+ it, names it, and offers only fields and `sn_get`. It never names a budget
1153
+ the policy would deny.
1154
+ - `fields=...` appears when it helps: the table's short default list for a
1155
+ read of the defaults or of `all`, or your own list without its large fields
1156
+ (for example `script`) when you chose one. It only ever names fields your
1157
+ profile may read, and never a sensitive one. A list with nothing large in it
1158
+ gets the `limit` and the budget instead. `response_format="concise"` is
1159
+ offered to a `detailed` read.
1160
+ - When no row fit, there is no `continue` clause and no `limit`: only the
1161
+ retry options and `sn_get`.
1162
+
896
1163
  ### Unrestricted field selection (`fields=all`, `response_format=detailed`)
897
1164
 
898
1165
  Both resolve to the profile's readable set for the table. Where the field
@@ -986,6 +1253,31 @@ servicenow-mcp-setup grant --profile dev --read change_request --related change_
986
1253
  servicenow-mcp-setup grant --profile dev --flows # sn_flow_view's 15 tables, bound to sn_flow_view only
987
1254
  ```
988
1255
 
1256
+ A read grant without `--tools` binds `sn_query`, `sn_get`, `sn_aggregate`,
1257
+ `sn_schema` and `sn_codesearch` to each table it names. `sn_codesearch` is
1258
+ authorized per code table it searches (`sys_script`, `sys_script_include`,
1259
+ `sys_ui_script`, `sys_script_client`, `sys_ws_operation`, `sys_module`), so
1260
+ `servicenow-mcp-setup grant --profile dev --read sys_script_include` lets that
1261
+ profile search script includes. A search with no `table` searches the code tables
1262
+ the profile may read and names the others in a warning; it fails only when the
1263
+ profile may read none of them. On any other table the binding is inert. **A profile written before
1264
+ `sn_codesearch` was a default keeps the tool list it was saved with** and is not
1265
+ rewritten: re-run the same `grant --read <code table>` to add it, or pass
1266
+ `--tools sn_codesearch` to add only that tool. Neither removes a tool. The
1267
+ profile's field policy still decides the script field: `sn_codesearch` is
1268
+ denied on a code table whose script field is not readable, exactly as `sn_query`
1269
+ is for that field (in a search with no `table` that table is left out and named
1270
+ in the warning instead).
1271
+
1272
+ A call the table policy refuses says which table and which tool were refused, and
1273
+ whether the table is missing from the profile or only the tool is, and it gives
1274
+ the command that lifts it: `Table access was denied by policy: "sys_script_include"
1275
+ is granted to this profile, but not for sn_codesearch. To allow it, run:
1276
+ servicenow-mcp-setup grant --profile <profile> --read sys_script_include --tools
1277
+ sn_codesearch`. `--tools` adds to the tools a table already has, so that command
1278
+ removes nothing. The message names only the table and the tool of that call,
1279
+ never the rest of the profile's rules.
1280
+
989
1281
  Allowlist entries may be exact table names or the literal `*` to allow every
990
1282
  table for that operation. Table names are trimmed, lowercased, deduplicated,
991
1283
  and must be valid ServiceNow identifiers.
@@ -1001,8 +1293,8 @@ and must be valid ServiceNow identifiers.
1001
1293
 
1002
1294
  | Variable | Required | Default | Description |
1003
1295
  |----------|----------|---------|-------------|
1004
- | `SN_ALLOWED_READ_TABLES` | ❌ | deny all | Tables permitted for read operations on the explicit `SN_PROFILE_NAME` environment profile only. Use `*` to allow every readable table. |
1005
- | `SN_ALLOWED_WRITE_TABLES` | ❌ | deny all | Tables permitted for create, update, incident journal append, delete, upload, and confirmed batch operations on the explicit `SN_PROFILE_NAME` environment profile only. Use `*` to allow every writable table. Write permission never implies read permission. |
1296
+ | `SN_ALLOWED_READ_TABLES` | ❌ | deny all | Tables permitted for read operations on the explicit `SN_PROFILE_NAME` environment profile only. Use `*` to allow every readable table except `sys_audit`, `sys_journal_field`, `sys_history_line`, `sys_audit_delete`, `sys_attachment_doc` and `sys_email`, which are covered only when named (see [Field policy](#field-policy)). |
1297
+ | `SN_ALLOWED_WRITE_TABLES` | ❌ | deny all | Tables permitted for create, update, incident journal append, delete, upload, and confirmed batch operations on the explicit `SN_PROFILE_NAME` environment profile only. Use `*` to allow every writable table except the same six named-only tables. Write permission never implies read permission. |
1006
1298
  | `SN_TABLE_ACCESS_TARGETS` | Required for exact allowlisted caller-addressable tables; optional with `*` | `[]` | Trusted JSON classification with `table`, exact permitted `tools`, `kind` (`canonical`, `alias`, `view`, or `extension`), literal `closureComplete: true`, and `relatedTables`: the target itself plus any backing or parent tables the operator declares. The loader checks that every related table has the target's operation permission; it does not derive the list from the instance, and the list grants no access. A self-only list is valid for a `canonical` target; `alias`, `view` and `extension` targets must name at least one backing table, and a view or alias should declare every table it reads, because it returns data from each of them whatever the list says. With `*`, omitted target entries use the wildcard operation grant; explicit target entries can still narrow tools and check their related tables. |
1007
1299
  | `SN_FIELD_POLICY_DEFINITIONS` | ❌ | no narrowing | Field policy for the explicit `SN_PROFILE_NAME` environment profile only, like the `SN_ALLOWED_*` variables. **If `~/.servicenow-mcp/config.json` exists, setting this variable stops startup**; give those profiles their own `fieldPolicy` instead. The value is trusted JSON, at most 65,536 characters: either a table map keyed by table name or `*`, the same shape as a profile's `fieldPolicy`, or an object holding the profile keys (`fieldPolicy`, or `readableTableFields` / `writableTableFields`), not both. Each field set is a list of exact field names or `"*"`; `["*"]` means `"*"` in that exact form only, and patterns such as `"u_*"` are rejected. A malformed value stops startup with the key named. Sensitive field names are always denied. See [Field policy](#field-policy). |
1008
1300
  | `SN_ENCODED_QUERY_READ_POLICY` | ❌ | deny all | Trusted JSON object containing bounded `rules` for an exact `sn_query`/table pair. Each rule requires `maxLength`, `maxTerms`, readable `fields`, supported `operators`, `maxLimit`, `maxOffset`, and `maxResponseBytes`. No rule can authorize a write or another tool. |
@@ -1029,8 +1321,9 @@ startup configuration. File-backed profile example:
1029
1321
  "profiles": {
1030
1322
  "dev": {
1031
1323
  "instance": "https://dev.service-now.com",
1032
- "username": "integration.user",
1033
- "credential": "env:SN_PASSWORD",
1324
+ "authType": "oauth",
1325
+ "clientId": "your-oauth-client-id",
1326
+ "clientSecret": "env:SN_CLIENT_SECRET",
1034
1327
  "tableAccess": {
1035
1328
  "readTables": ["incident", "sys_dictionary"],
1036
1329
  "writeTables": ["incident"],
@@ -1052,7 +1345,23 @@ startup configuration. File-backed profile example:
1052
1345
  `run`/`run-suite` return migration guidance; use `sn_atf_run` with an explicit
1053
1346
  `atf.execute` profile grant. Typed ATF steps use the authenticated native form
1054
1347
  to save and verify inputs and output references without ACL changes or an
1055
- installed application. See [ATF workflow](docs/ATF-WORKFLOW.md).
1348
+ installed application. `sn_atf_author` checks each step that names a table
1349
+ against the profile's grants: a `record_query`, `record_validation`,
1350
+ `field_values_validation` or `open_existing_record` step needs a read grant on its
1351
+ table, and an `open_new_form` or `set_field_values` step a write grant (a
1352
+ named-only table must be named, for either). The conditions of the three steps
1353
+ that have them may use only the operators that compare a field with a literal
1354
+ (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`, `NOT LIKE`, `STARTSWITH`, `ENDSWITH`,
1355
+ `IN`, `NOT IN`, `ISEMPTY`, `ISNOTEMPTY`, `BETWEEN`), name plain fields the field
1356
+ policy lets the profile read (no dot-walks), and may refer to an earlier step's
1357
+ output only by its record id or sys_id (`record_id`, `first_record`, `sys_id`
1358
+ or `user`), as may the values a `set_field_values` step sets; a refused term
1359
+ refuses the whole call. The fields a `set_field_values` step sets must be
1360
+ writable on its table under the profile's field policy, as for `sn_update`. `record_query` and `record_validation` also refuse
1361
+ `enforce_security: false`; leave it out and it stays `true`. The impersonated
1362
+ user's ACLs still apply on top of all this. Suites authored in the instance are
1363
+ not checked by the server's table grants, and `atf.execute` stays opt-in. See
1364
+ [ATF workflow](docs/ATF-WORKFLOW.md).
1056
1365
 
1057
1366
  #### Field policy
1058
1367
 
@@ -1062,6 +1371,13 @@ denies a table the profile grants. A profile with no field policy may read and
1062
1371
  write every field of a granted table, except that sensitive-looking names
1063
1372
  (`password`, `token`, `secret`, `api_key` and similar) are always denied, and
1064
1373
  the class and domain fields below must be listed before they can be written.
1374
+ Fields of type `password`, `password2`, `masked` or `encrypted_text` are denied
1375
+ the same way, whatever their name, and a `sys_properties` value shows only for
1376
+ a known non-secret `type`. The types come from a cached `sys_dictionary` read,
1377
+ so the integration user needs read access to `sys_dictionary` and
1378
+ `sys_db_object`; without it the tools refuse, unless the profile sets
1379
+ `"fieldTypes": { "dictionary": "not_required" }` to hide by name only (see
1380
+ [Production security](docs/PRODUCTION-SECURITY.md#password-type-fields)).
1065
1381
 
1066
1382
  State it on a profile in `~/.servicenow-mcp/config.json`, beside
1067
1383
  `tableAccess`, in one of two forms. A profile that states both fails to load.
@@ -1150,20 +1466,23 @@ The same policy in the list form:
1150
1466
  }
1151
1467
  ```
1152
1468
 
1153
- **Which tables a `"*"` entry reaches.** Tables fall into three groups:
1469
+ **Which tables a `"*"` entry reaches.** Tables fall into four groups:
1154
1470
 
1155
1471
  - **ITSM tables:** `incident`, `change_request`, `problem`, `sc_request`,
1156
1472
  `sc_req_item`, `sc_task`, `task`, `cmdb_ci`, `cmdb_ci_server`,
1157
1473
  `cmdb_ci_computer`, `kb_knowledge`.
1158
1474
  - **Every table without a built-in entry:** `u_*` and `x_*` tables, and
1159
1475
  platform tables such as `change_task` and `sys_properties`.
1160
- - **The 23 system tables:** `sys_script`, `sys_script_include`,
1161
- `sys_script_client`, `sys_ui_script`, `sys_ws_operation`, `sys_user`,
1476
+ - **The 24 system tables:** `sys_script`, `sys_script_include`,
1477
+ `sys_script_client`, `sys_ui_script`, `sys_ws_operation`, `sys_module`, `sys_user`,
1162
1478
  `sys_user_group`, `sys_user_grmember`, `sys_db_object`, `sys_app`,
1163
1479
  `sys_store_app`, `v_plugin`, `sys_atf_test`, `sys_atf_test_suite`,
1164
1480
  `sys_atf_test_suite_test`, `sys_atf_test_result`, `sys_atf_step`,
1165
1481
  `sys_element_mapping`, `sys_variable_value`, `sys_atf_test_suite_result`,
1166
1482
  `sys_atf_test_result_step`, `sys_atf_agent`, `syslog`.
1483
+ - **The 6 named-only tables:** `sys_audit`, `sys_journal_field`,
1484
+ `sys_history_line`, `sys_audit_delete`, `sys_attachment_doc`, `sys_email`. A
1485
+ `"*"` entry reaches them once the profile names them in `tableAccess` (below).
1167
1486
 
1168
1487
  On an ITSM table or a table without a built-in entry, named in the policy or
1169
1488
  not, `readable` and `writable` each resolve from the table's own entry, then
@@ -1175,11 +1494,72 @@ projections, trimmed to the effective `readable` set.
1175
1494
  A `"*"` entry never reaches a system table, named or not: each key comes from
1176
1495
  the table's own entry, or else covers every field. The system tables include
1177
1496
  the script tables (`sys_script`, `sys_script_include`, `sys_script_client`,
1178
- `sys_ui_script`, `sys_ws_operation`), whose records hold server- or
1497
+ `sys_ui_script`, `sys_ws_operation`, `sys_module`), whose records hold server- or
1179
1498
  client-side code, and the user and group tables (`sys_user`,
1180
1499
  `sys_user_group`, `sys_user_grmember`). Name a system table to narrow it, and
1181
1500
  grant it in `tableAccess` only deliberately.
1182
1501
 
1502
+ **Six tables are granted by name.** A `"*"` entry in `readTables` or
1503
+ `writeTables` covers every other table, but not `sys_audit`, `sys_journal_field`,
1504
+ `sys_history_line`, `sys_audit_delete`, `sys_attachment_doc` or `sys_email`.
1505
+ Their rows hold the old and new values of other tables' fields, comments and
1506
+ work notes, the history built from them, deleted records, attachment content
1507
+ and email bodies. A profile reaches one only when `tableAccess` names it, for
1508
+ example
1509
+ `servicenow-mcp-setup grant --profile <profile> --read sys_audit --tools sn_query`.
1510
+ Without that, every tool refuses it, `sn_query`, `sn_get`, `sn_aggregate`,
1511
+ `sn_schema` and `sn_batch` included, and the message names the table and the
1512
+ grant that allows it. A `relatedTables` list that reaches one of them under a
1513
+ `"*"` grant stops the profile loading, and the message names the table and says
1514
+ to grant it by name.
1515
+
1516
+ Once named, these tables follow the profile's field policy like an ITSM table:
1517
+ a `"*"` field entry narrows them, and an entry for the table narrows or widens
1518
+ them. A read that names no `fields` leaves out the value columns, which are asked
1519
+ for by name: `oldvalue` and `newvalue` for `sys_audit`; `value` for
1520
+ `sys_journal_field`; `old`, `new`, `old_value` and `new_value` for
1521
+ `sys_history_line`; `payload` for `sys_audit_delete`; `data` for
1522
+ `sys_attachment_doc`; and `body`, `body_text`, `subject`, `recipients`,
1523
+ `copied`, `blind_copied`, `reply_to`, `headers` and `error_string` for
1524
+ `sys_email`. `sn_attach` is unchanged: it uses the Attachment API, under the
1525
+ grants for `sys_attachment` and the record's table, and never reads
1526
+ `sys_attachment_doc`.
1527
+
1528
+ **A `"*"` write grant does not cover three ATF tables.** `sys_atf_step`,
1529
+ `sys_variable_value` and `sys_element_mapping` hold the step types, input values
1530
+ and pill mappings that `sn_atf_author` checks when it adds a step. Under a `"*"`
1531
+ write grant they are written by `sn_atf_author` only; `sn_create`, `sn_update`, `sn_delete`, `sn_batch` and
1532
+ attachment uploads reach them only when `tableAccess` names the table for write,
1533
+ and the refusal names the table and the grant that allows it. Reads are
1534
+ unchanged. `sys_variable_value` and `sys_element_mapping` also hold other
1535
+ variables' values and mappings (catalog variables, for example), so a profile
1536
+ that writes those with the generic tools needs to name them.
1537
+
1538
+ **Database views and extension tables are not covered by the name list.** The
1539
+ six tables are matched by table name. A database view built over one of them (a
1540
+ `sys_db_view` that joins any of the six) has a different name, so a `"*"` grant
1541
+ reaches the view and, through it, the columns of the joined table. The same holds
1542
+ for a custom table that extends one of the six. Do not grant such a view or table
1543
+ unless you mean to expose those rows, and on a profile with a `"*"` grant ask
1544
+ your instance administrator to review database views first; a profile with an
1545
+ explicit table list never reaches a view it does not name. To have the loader
1546
+ check it, declare the view as a `view` target with every table it reads in
1547
+ `relatedTables`: the profile then fails to load unless it also names each of
1548
+ those tables (for a named-only table, by name).
1549
+
1550
+ **Code tables list without their scripts.** A read of `sys_script`,
1551
+ `sys_script_include`, `sys_ui_script`, `sys_script_client` or `sys_ws_operation`
1552
+ that names no `fields` returns identifiers and metadata, not the script body, so
1553
+ a page of them is not cut short by a few large bodies. For `sys_script_include`
1554
+ that is `sys_id`, `name`, `api_name`, `active` and `sys_updated_on`; the others
1555
+ keep `sys_id`, `name`, `active`, `sys_updated_on` and what identifies them
1556
+ (`collection` and `when` for a business rule, `table` and `type` for a client
1557
+ script, `http_method` and `relative_path` for a scripted REST operation, `global`
1558
+ for a UI script). The body is one named field away, and `fields=all` and
1559
+ `response_format: "detailed"` still include it:
1560
+ `sn_query {table: "sys_script_include", fields: "sys_id,name,script"}`. A profile
1561
+ that states its own `defaults` for one of these tables keeps them.
1562
+
1183
1563
  **Read-only profiles.** A `"*"` entry with `writable: []` does not make a
1184
1564
  profile read-only, because it never reaches the system tables. To make a
1185
1565
  profile read-only, grant no writes: `tableAccess.writeTables: []`, or
@@ -1197,6 +1577,31 @@ Otherwise the write is denied with:
1197
1577
  Write denied by policy: field "sys_domain" on "incident" changes the record's class or domain, so a writable wildcard never covers it. List it explicitly in fieldPolicy.incident.writable to allow this write.
1198
1578
  ```
1199
1579
 
1580
+ **Record payload columns.** Some columns carry other records' content or
1581
+ packaged content, so no wildcard covers them: not the open default of a
1582
+ profile with no field policy, a `"*"` entry, or `"*"` on the table's own
1583
+ entry. They are `payload` and `payload_diff` on `sys_update_xml`,
1584
+ `sys_update_version`, `sys_update_preview_xml`, `sys_update_diff`,
1585
+ `sys_sync_preview_remote`, `sys_upgrade_history_log`, `sys_metadata_link`,
1586
+ `sys_metadata_delete`, `sys_audit_delete`, `sys_archive_log` and
1587
+ `clone_preserved_data`; `payload` on `ecc_queue`, `data_replication_queue`,
1588
+ `sys_rt_change_log`, `sys_hub_snapshot` and `sys_hub_flow_version`; `payload`
1589
+ and `payload_short` on `sys_replication_queue`; `payload` and
1590
+ `previous_payload` on every `cdc_queue_*` table except `cdc_queue_state_*`;
1591
+ `data` on `sys_hub_snapshot_chunk`; and
1592
+ `encoded_keystore` on `sn_disco_certmgmt_certificate_ca_credentials`. The
1593
+ numbered rotation shards of the queue tables (`ecc_queue0003`,
1594
+ `sys_replication_queue5`, ...) are covered too, each as its own table. Each
1595
+ column is read only where it is named in that table's own `readable`, and
1596
+ written only where it is named in its own `writable`. Until then it is
1597
+ refused by name and as a filter, order, group-by, aggregate or write field,
1598
+ and is left out of `fields=all`, detailed and default reads and write
1599
+ echoes. A named read is denied with:
1600
+
1601
+ ```text
1602
+ Read denied by policy: field "payload" on "sys_update_xml" holds record payloads, so a readable wildcard never covers it. List it explicitly in fieldPolicy.sys_update_xml.readable to allow this read.
1603
+ ```
1604
+
1200
1605
  **`readable: []` and `writable: []`.** `readable: []` makes a table
1201
1606
  write-only: writes succeed and return only `sys_id`, reads are denied, and
1202
1607
  `sn_batch` cannot run there. `writable: []` blocks writes. To make a table
@@ -1356,7 +1761,7 @@ smaller.
1356
1761
  | `SN_INSTANCE` | ✅* | — | Instance URL (e.g. `https://yourinstance.service-now.com`) |
1357
1762
  | `SN_USER` | ✅* | — | ServiceNow username (basic auth / OAuth password grant) |
1358
1763
  | `SN_PASSWORD` | ✅* | — | ServiceNow password (basic auth / OAuth password grant) |
1359
- | `SN_AUTH_TYPE` | ❌ | `basic` | Auth scheme: `basic`, `oauth`, or `apikey` |
1764
+ | `SN_AUTH_TYPE` | ❌ | `basic` (legacy; set `oauth` explicitly) | Auth scheme: `basic`, `oauth`, or `apikey` |
1360
1765
  | `SN_CLIENT_ID` | ❌ | — | OAuth client id (`SN_AUTH_TYPE=oauth`) |
1361
1766
  | `SN_CLIENT_SECRET` | ❌ | — | OAuth client secret (`SN_AUTH_TYPE=oauth`) |
1362
1767
  | `SN_GRANT_TYPE` | ❌ | `client_credentials` | OAuth grant: `client_credentials` or `password` |