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