@onlyflows/servicenow-mcp 2.3.0-dev.2 → 2.3.0-dev.4

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 (89) hide show
  1. package/CHANGELOG.md +235 -26
  2. package/README.md +174 -36
  3. package/dist/client.d.ts +5 -13
  4. package/dist/client.d.ts.map +1 -1
  5. package/dist/client.js +11 -26
  6. package/dist/client.js.map +1 -1
  7. package/dist/code-search-snippet.d.ts +25 -0
  8. package/dist/code-search-snippet.d.ts.map +1 -0
  9. package/dist/code-search-snippet.js +67 -0
  10. package/dist/code-search-snippet.js.map +1 -0
  11. package/dist/code-search-targets.d.ts +66 -0
  12. package/dist/code-search-targets.d.ts.map +1 -0
  13. package/dist/code-search-targets.js +82 -0
  14. package/dist/code-search-targets.js.map +1 -0
  15. package/dist/config.d.ts +1 -1
  16. package/dist/config.d.ts.map +1 -1
  17. package/dist/field-policy.d.ts.map +1 -1
  18. package/dist/field-policy.js +17 -5
  19. package/dist/field-policy.js.map +1 -1
  20. package/dist/http-observability.js +1 -0
  21. package/dist/http-observability.js.map +1 -1
  22. package/dist/metadata-cache.d.ts +2 -2
  23. package/dist/metadata-cache.d.ts.map +1 -1
  24. package/dist/metadata-cache.js +3 -2
  25. package/dist/metadata-cache.js.map +1 -1
  26. package/dist/policy-card.js +1 -1
  27. package/dist/policy-card.js.map +1 -1
  28. package/dist/profile-admin.d.ts +18 -0
  29. package/dist/profile-admin.d.ts.map +1 -1
  30. package/dist/profile-admin.js +26 -1
  31. package/dist/profile-admin.js.map +1 -1
  32. package/dist/profile-manager.d.ts +1 -1
  33. package/dist/profile-manager.d.ts.map +1 -1
  34. package/dist/response-too-large.d.ts +23 -0
  35. package/dist/response-too-large.d.ts.map +1 -0
  36. package/dist/response-too-large.js +42 -0
  37. package/dist/response-too-large.js.map +1 -0
  38. package/dist/risky-grants.d.ts.map +1 -1
  39. package/dist/risky-grants.js +1 -0
  40. package/dist/risky-grants.js.map +1 -1
  41. package/dist/setup.d.ts +4 -0
  42. package/dist/setup.d.ts.map +1 -1
  43. package/dist/setup.js +165 -70
  44. package/dist/setup.js.map +1 -1
  45. package/dist/table-policy.d.ts +42 -2
  46. package/dist/table-policy.d.ts.map +1 -1
  47. package/dist/table-policy.js +90 -6
  48. package/dist/table-policy.js.map +1 -1
  49. package/dist/tool-error.d.ts +40 -4
  50. package/dist/tool-error.d.ts.map +1 -1
  51. package/dist/tool-error.js +81 -4
  52. package/dist/tool-error.js.map +1 -1
  53. package/dist/tool-table-access.d.ts +9 -2
  54. package/dist/tool-table-access.d.ts.map +1 -1
  55. package/dist/tool-table-access.js +93 -30
  56. package/dist/tool-table-access.js.map +1 -1
  57. package/dist/tools/batch.d.ts.map +1 -1
  58. package/dist/tools/batch.js +21 -5
  59. package/dist/tools/batch.js.map +1 -1
  60. package/dist/tools/catalog.d.ts.map +1 -1
  61. package/dist/tools/catalog.js +2 -1
  62. package/dist/tools/catalog.js.map +1 -1
  63. package/dist/tools/codesearch.d.ts +2 -2
  64. package/dist/tools/codesearch.d.ts.map +1 -1
  65. package/dist/tools/codesearch.js +535 -86
  66. package/dist/tools/codesearch.js.map +1 -1
  67. package/dist/tools/flow-view-contracts.d.ts +2 -2
  68. package/dist/tools/index.d.ts.map +1 -1
  69. package/dist/tools/index.js +13 -2
  70. package/dist/tools/index.js.map +1 -1
  71. package/dist/tools/query-module.d.ts.map +1 -1
  72. package/dist/tools/query-module.js +25 -4
  73. package/dist/tools/query-module.js.map +1 -1
  74. package/dist/tools/result-envelope.d.ts +2 -2
  75. package/dist/tools/result-envelope.d.ts.map +1 -1
  76. package/dist/tools/result-envelope.js +20 -2
  77. package/dist/tools/result-envelope.js.map +1 -1
  78. package/dist/unknown-filter-fields.d.ts +52 -0
  79. package/dist/unknown-filter-fields.d.ts.map +1 -0
  80. package/dist/unknown-filter-fields.js +87 -0
  81. package/dist/unknown-filter-fields.js.map +1 -0
  82. package/dist/version.d.ts +1 -1
  83. package/dist/version.js +1 -1
  84. package/docs/CLIENT-SETUP.md +23 -10
  85. package/docs/PRODUCTION-SECURITY.md +10 -6
  86. package/docs/PROFILE-CREDENTIALS.md +10 -4
  87. package/docs/V2-MIGRATION.md +1 -1
  88. package/package.json +1 -1
  89. 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"],
@@ -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
  ```
@@ -716,7 +757,7 @@ in this section is needed to use this server.
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
759
  | `sn_syslog` | Query system logs with severity/source/time filters |
719
- | `sn_codesearch` | Search business rules, script includes, client scripts, etc. Part of the default read grant, so a plain read grant on a code table allows it |
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
 
722
763
  ### Testing & Automation
@@ -843,14 +884,86 @@ Two failure modes are worth knowing:
843
884
  builds the request policy with only `allowedHosts` and `allowedOrigins`, so the
844
885
  limit is always 1 MiB and no environment variable changes it.
845
886
 
887
+ ### Code search
888
+
889
+ `sn_codesearch {search_term, table?, field?, limit?, offset?}` finds records
890
+ whose script contains the text, in the business rules, script includes, UI
891
+ scripts, client scripts, scripted REST operations, ES modules and ATF step
892
+ scripts of the instance. Each row
893
+ is `{table, table_label, sys_id, name, snippet, line}`: `snippet` is about 200
894
+ characters of the script centred on the first match (`...` marks a cut) and
895
+ `line` is the line that match is on. The comparison is the instance's
896
+ case-insensitive `LIKE`; if the text holds no literal match for the term, the
897
+ snippet is the head of the script and the row has no `line`.
898
+
899
+ - **One table or all.** With `table`, one table is searched (and `field` can
900
+ name another field of it, such as `name`). With none, every code table the
901
+ profile may read is searched, and the tables left out are named in a warning
902
+ (`Not searched, because this profile does not allow sn_codesearch to read
903
+ them: sys_script, sys_ws_operation. To include one, run servicenow-mcp-setup
904
+ grant --profile <profile> --read <table> --tools sn_codesearch.`). A table is
905
+ left out when the table policy does not bind `sn_codesearch` to it or the field
906
+ policy does not let the profile read its script field. The call fails only when
907
+ none can be read, and the error says why.
908
+ - **ES modules** are `sys_module`: the script is its `content` column and a row
909
+ is named by its `path`, because the table has no `name`. A profile reads it
910
+ once the table policy allows it: `servicenow-mcp-setup grant --profile dev
911
+ --read sys_module`, or a read wildcard. It is cached by default like the other
912
+ code tables, and `fields=all` reads `content`. A default `sn_query` of it lists
913
+ `sys_id`, `path` and `sys_updated_on`. `sys_module` is a built-in system table
914
+ (the 24th), so a `"*"` entry in the field policy does not narrow it: a profile
915
+ whose `"*"` entry limits `readable` and that can read `sys_module` now reads
916
+ `content`, where it did not before. To narrow it, name it in `fieldPolicy`
917
+ (`"sys_module": { "readable": ["sys_id", "path"] }`).
918
+ - **ATF step scripts** are searched with `table: "sys_atf_step"`. A step's script
919
+ is not a column of the step but the value of its script input, a row of
920
+ `sys_variable_value`. The search reads only the rows whose `document` is
921
+ `sys_atf_step` and whose `variable` ends with `script`, a condition fixed in
922
+ the server: no argument can widen it to another table's variables, and `field`
923
+ is refused. Each result is the step (`sys_id` is the step's), named
924
+ `<test name> > step <order>` where `order` is the step's own order value, and
925
+ the steps and then their tests are read by id to say so. Three tables are read,
926
+ so the profile needs read on `sys_variable_value`, `sys_atf_step` and
927
+ `sys_atf_test`, each bound to `sn_codesearch`:
928
+ `servicenow-mcp-setup grant --profile dev --read sys_variable_value,sys_atf_step,sys_atf_test`
929
+ (or `--tools sn_codesearch` to bind only this tool: `sys_variable_value` also
930
+ holds other tables' variable values, which that grant does not let this tool
931
+ search). `grant --atf` binds those tables to `sn_atf_author` only, so a profile
932
+ that has it adds this grant on top. A search with no `table` includes ATF
933
+ step scripts when all three are held and names `sys_atf_step` in the warning
934
+ when they are not. These tables are not in the default cache list: the reads go
935
+ straight to the instance.
936
+ - **A page is shared among the tables.** A search of several tables takes turns:
937
+ each table's first match (script includes first, then business rules, UI
938
+ scripts, client scripts, scripted REST operations, ES modules), then each
939
+ table's second,
940
+ and so on, each table in `sys_id` order. No table crowds the others off page
941
+ 1, and the order depends only on the data, so `offset` and `next_offset` page
942
+ through it exactly. A table with few matches leaves its share to the others.
943
+ - **Large pages degrade, they do not fail.** A script can be hundreds of
944
+ kilobytes, so a page of them does not fit one response. A search of one table
945
+ with `limit` 49 or less reads the scripts with the rows, in one request (and
946
+ 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
947
+ their scripts and then reads the scripts of the rows it returns, 50 at a time,
948
+ narrowing a batch that is still too large. One search spends at most 12 such
949
+ requests and 8 MiB, and only for the rows one response can hold (about 280);
950
+ when that is spent, the remaining rows keep an empty `snippet` and a warning
951
+ says how many (lower `limit`). A script too large to read even on its own gives
952
+ its row an empty `snippet` and `note: "script too large to preview"`; read it
953
+ with `sn_get`. If the rows alone pass the response cap, the
954
+ error says the response was too large and to lower `limit` or `offset`.
955
+ - **The scripts are still field-policy readable fields.** The search reads the
956
+ identifier, the name and the searched field of each table, each subject to the
957
+ profile's field policy, and the sensitive-name rules apply to `field`.
958
+
846
959
  ### Metadata cache
847
960
 
848
961
  Stable ServiceNow metadata reads are cached per instance and credential identity
849
962
  for 24 hours by default. The default cached table patterns are
850
963
  `sys_glide_object`, `sys_dictionary`, `sys_db_object`, `sys_app`, `sys_plugins`,
851
- `sys_metadata*`, `sys_flow*`, and the five code tables `sn_codesearch`
964
+ `sys_metadata*`, `sys_flow*`, and the six code tables `sn_codesearch`
852
965
  searches: `sys_script`, `sys_script_include`, `sys_ui_script`,
853
- `sys_script_client`, and `sys_ws_operation`. A repeated code search or
966
+ `sys_script_client`, `sys_ws_operation`, and `sys_module`. A repeated code search or
854
967
  `sn_query` page on those tables is served from the cache while the table's
855
968
  watermark is unchanged. Set `metadataCache.ttlMs` and
856
969
  `metadataCache.tables` on a file-backed profile, or `SN_METADATA_CACHE_TTL_MS`
@@ -908,7 +1021,7 @@ reads were served: `hit` (all from the cache), `miss` (from ServiceNow: nothing
908
1021
  cached yet, the watermark moved, the entry expired, the table could not be
909
1022
  cached just then, or the response is small and not kept), `bypass` (a `force_recache: true` refresh), or `mixed` (the
910
1023
  call made several cacheable reads with different outcomes, such as an
911
- `sn_codesearch` with no `table` over the five code tables). It is absent when
1024
+ `sn_codesearch` with no `table` over the code tables). It is absent when
912
1025
  the call read no cache-eligible table. `timing` is `{ total_ms, upstream_ms,
913
1026
  watermark_ms }` in whole milliseconds, measured wall-clock: `total_ms` is the
914
1027
  whole tool call; `upstream_ms` is the time during which at least one request to
@@ -1109,16 +1222,27 @@ servicenow-mcp-setup grant --profile dev --flows # sn_flow_view's 15 tables, b
1109
1222
  A read grant without `--tools` binds `sn_query`, `sn_get`, `sn_aggregate`,
1110
1223
  `sn_schema` and `sn_codesearch` to each table it names. `sn_codesearch` is
1111
1224
  authorized per code table it searches (`sys_script`, `sys_script_include`,
1112
- `sys_ui_script`, `sys_script_client`, `sys_ws_operation`), so
1225
+ `sys_ui_script`, `sys_script_client`, `sys_ws_operation`, `sys_module`), so
1113
1226
  `servicenow-mcp-setup grant --profile dev --read sys_script_include` lets that
1114
- profile search script includes; a search with no `table` needs a read grant on
1115
- all five. On any other table the binding is inert. **A profile written before
1227
+ profile search script includes. A search with no `table` searches the code tables
1228
+ the profile may read and names the others in a warning; it fails only when the
1229
+ profile may read none of them. On any other table the binding is inert. **A profile written before
1116
1230
  `sn_codesearch` was a default keeps the tool list it was saved with** and is not
1117
1231
  rewritten: re-run the same `grant --read <code table>` to add it, or pass
1118
1232
  `--tools sn_codesearch` to add only that tool. Neither removes a tool. The
1119
1233
  profile's field policy still decides the script field: `sn_codesearch` is
1120
1234
  denied on a code table whose script field is not readable, exactly as `sn_query`
1121
- is for that field.
1235
+ is for that field (in a search with no `table` that table is left out and named
1236
+ in the warning instead).
1237
+
1238
+ A call the table policy refuses says which table and which tool were refused, and
1239
+ whether the table is missing from the profile or only the tool is, and it gives
1240
+ the command that lifts it: `Table access was denied by policy: "sys_script_include"
1241
+ is granted to this profile, but not for sn_codesearch. To allow it, run:
1242
+ servicenow-mcp-setup grant --profile <profile> --read sys_script_include --tools
1243
+ sn_codesearch`. `--tools` adds to the tools a table already has, so that command
1244
+ removes nothing. The message names only the table and the tool of that call,
1245
+ never the rest of the profile's rules.
1122
1246
 
1123
1247
  Allowlist entries may be exact table names or the literal `*` to allow every
1124
1248
  table for that operation. Table names are trimmed, lowercased, deduplicated,
@@ -1163,8 +1287,9 @@ startup configuration. File-backed profile example:
1163
1287
  "profiles": {
1164
1288
  "dev": {
1165
1289
  "instance": "https://dev.service-now.com",
1166
- "username": "integration.user",
1167
- "credential": "env:SN_PASSWORD",
1290
+ "authType": "oauth",
1291
+ "clientId": "your-oauth-client-id",
1292
+ "clientSecret": "env:SN_CLIENT_SECRET",
1168
1293
  "tableAccess": {
1169
1294
  "readTables": ["incident", "sys_dictionary"],
1170
1295
  "writeTables": ["incident"],
@@ -1291,8 +1416,8 @@ The same policy in the list form:
1291
1416
  `cmdb_ci_computer`, `kb_knowledge`.
1292
1417
  - **Every table without a built-in entry:** `u_*` and `x_*` tables, and
1293
1418
  platform tables such as `change_task` and `sys_properties`.
1294
- - **The 23 system tables:** `sys_script`, `sys_script_include`,
1295
- `sys_script_client`, `sys_ui_script`, `sys_ws_operation`, `sys_user`,
1419
+ - **The 24 system tables:** `sys_script`, `sys_script_include`,
1420
+ `sys_script_client`, `sys_ui_script`, `sys_ws_operation`, `sys_module`, `sys_user`,
1296
1421
  `sys_user_group`, `sys_user_grmember`, `sys_db_object`, `sys_app`,
1297
1422
  `sys_store_app`, `v_plugin`, `sys_atf_test`, `sys_atf_test_suite`,
1298
1423
  `sys_atf_test_suite_test`, `sys_atf_test_result`, `sys_atf_step`,
@@ -1309,11 +1434,24 @@ projections, trimmed to the effective `readable` set.
1309
1434
  A `"*"` entry never reaches a system table, named or not: each key comes from
1310
1435
  the table's own entry, or else covers every field. The system tables include
1311
1436
  the script tables (`sys_script`, `sys_script_include`, `sys_script_client`,
1312
- `sys_ui_script`, `sys_ws_operation`), whose records hold server- or
1437
+ `sys_ui_script`, `sys_ws_operation`, `sys_module`), whose records hold server- or
1313
1438
  client-side code, and the user and group tables (`sys_user`,
1314
1439
  `sys_user_group`, `sys_user_grmember`). Name a system table to narrow it, and
1315
1440
  grant it in `tableAccess` only deliberately.
1316
1441
 
1442
+ **Code tables list without their scripts.** A read of `sys_script`,
1443
+ `sys_script_include`, `sys_ui_script`, `sys_script_client` or `sys_ws_operation`
1444
+ that names no `fields` returns identifiers and metadata, not the script body, so
1445
+ a page of them is not cut short by a few large bodies. For `sys_script_include`
1446
+ that is `sys_id`, `name`, `api_name`, `active` and `sys_updated_on`; the others
1447
+ keep `sys_id`, `name`, `active`, `sys_updated_on` and what identifies them
1448
+ (`collection` and `when` for a business rule, `table` and `type` for a client
1449
+ script, `http_method` and `relative_path` for a scripted REST operation, `global`
1450
+ for a UI script). The body is one named field away, and `fields=all` and
1451
+ `response_format: "detailed"` still include it:
1452
+ `sn_query {table: "sys_script_include", fields: "sys_id,name,script"}`. A profile
1453
+ that states its own `defaults` for one of these tables keeps them.
1454
+
1317
1455
  **Read-only profiles.** A `"*"` entry with `writable: []` does not make a
1318
1456
  profile read-only, because it never reaches the system tables. To make a
1319
1457
  profile read-only, grant no writes: `tableAccess.writeTables: []`, or
@@ -1490,7 +1628,7 @@ smaller.
1490
1628
  | `SN_INSTANCE` | ✅* | — | Instance URL (e.g. `https://yourinstance.service-now.com`) |
1491
1629
  | `SN_USER` | ✅* | — | ServiceNow username (basic auth / OAuth password grant) |
1492
1630
  | `SN_PASSWORD` | ✅* | — | ServiceNow password (basic auth / OAuth password grant) |
1493
- | `SN_AUTH_TYPE` | ❌ | `basic` | Auth scheme: `basic`, `oauth`, or `apikey` |
1631
+ | `SN_AUTH_TYPE` | ❌ | `basic` (legacy; set `oauth` explicitly) | Auth scheme: `basic`, `oauth`, or `apikey` |
1494
1632
  | `SN_CLIENT_ID` | ❌ | — | OAuth client id (`SN_AUTH_TYPE=oauth`) |
1495
1633
  | `SN_CLIENT_SECRET` | ❌ | — | OAuth client secret (`SN_AUTH_TYPE=oauth`) |
1496
1634
  | `SN_GRANT_TYPE` | ❌ | `client_credentials` | OAuth grant: `client_credentials` or `password` |
package/dist/client.d.ts CHANGED
@@ -20,6 +20,9 @@ import { type AtfFormInput } from "./atf-form.js";
20
20
  import { CallMetrics, type CacheOutcome } from "./call-metrics.js";
21
21
  import { ServiceNowConfig } from "./config.js";
22
22
  import { AuthProvider } from "./auth.js";
23
+ import { BASIC_AUTH_401_HINT } from "./tool-error.js";
24
+ import { ServiceNowResponseTooLargeError, isServiceNowResponseTooLarge } from "./response-too-large.js";
25
+ export { ServiceNowResponseTooLargeError, isServiceNowResponseTooLarge };
23
26
  /** @deprecated Inspect trusted tool-error provenance instead of raw fields. */
24
27
  export type ServiceNowError = Error;
25
28
  type ParsedJson = Awaited<ReturnType<Response["json"]>>;
@@ -71,8 +74,8 @@ export declare const MAX_CUMULATIVE_UPSTREAM_JSON_BYTES: number;
71
74
  export declare const MAX_CUMULATIVE_RAW_RESPONSE_BYTES: number;
72
75
  export declare const DEFAULT_MAX_JSON_RESPONSE_BYTES: number;
73
76
  export declare const MAX_ERROR_RESPONSE_BYTES: number;
74
- /** Guidance appended to 401 errors on basic-auth profiles. */
75
- export declare const BASIC_AUTH_401_HINT: string;
77
+ /** Guidance carried by 401 errors on basic-auth profiles (fixed text). */
78
+ export { BASIC_AUTH_401_HINT };
76
79
  export declare const DEFAULT_MAX_CONCURRENT_REQUESTS = 4;
77
80
  /**
78
81
  * Bind one immutable execution-context signal and fresh atomic upstream byte
@@ -147,16 +150,6 @@ export declare class ServiceNowClient {
147
150
  * {@link CallMetrics}); the timing never alters, delays or retries a request.
148
151
  */
149
152
  export declare function createServiceNowOperations(client: ServiceNowOperations): ServiceNowOperations;
150
- /**
151
- * A response, or a request scope's cumulative upstream JSON, passed its byte
152
- * limit. A RangeError, as before, so existing handling is unchanged; the
153
- * class lets callers tell it apart from any other RangeError.
154
- */
155
- export declare class ServiceNowResponseTooLargeError extends RangeError {
156
- constructor(message: string);
157
- }
158
- /** True when a request failed because a response or its scope passed a byte limit. */
159
- export declare function isServiceNowResponseTooLarge(error: unknown): boolean;
160
153
  /** True when a request failed because its caller cancelled it. */
161
154
  export declare function isServiceNowRequestCancellation(error: unknown): boolean;
162
155
  /**
@@ -171,5 +164,4 @@ export declare function parseRetryAfterMs(value: string | null): number | undefi
171
164
  * MAX_RETRY_DELAY_MS either way.
172
165
  */
173
166
  export declare function retryDelayMs(retryAfter: string | null, attempt: number, baseDelayMs: number): number;
174
- export {};
175
167
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAsD,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtG,OAAO,EAAE,WAAW,EAAE,KAAK,YAAY,EAAoB,MAAM,mBAAmB,CAAC;AAErF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAsB,MAAM,WAAW,CAAC;AAW7D,+EAA+E;AAC/E,M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AAE,MAAM,CAAA;KAAO,GAC3C,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IA0BjD;;;OAGG;IACG,eAAe,CAAC,CAAC,GAAG,UAAU,EAClC,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAO,GAChE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IA4C5B;;;;OAIG;YACW,QAAQ;IAuBtB,OAAO,CAAC,QAAQ;IAiBhB;;;;;;;;OAQG;YACW,eAAe;YA+Ff,gBAAgB;IAc9B,OAAO,CAAC,cAAc;CAsBvB;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,oBAAoB,GAC3B,oBAAoB,CAyCtB;AAqJD,kEAAkE;AAClE,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEvE;AAoID;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAW1E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,MAAM,GAAG,IAAI,EACzB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR"}
package/dist/client.js CHANGED
@@ -18,12 +18,11 @@
18
18
  * @module client
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.ServiceNowResponseTooLargeError = exports.ServiceNowClient = exports.DEFAULT_MAX_CONCURRENT_REQUESTS = exports.BASIC_AUTH_401_HINT = exports.MAX_ERROR_RESPONSE_BYTES = exports.DEFAULT_MAX_JSON_RESPONSE_BYTES = exports.MAX_CUMULATIVE_RAW_RESPONSE_BYTES = exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES = exports.MAX_RETRY_DELAY_MS = exports.DEFAULT_TIMEOUT_MS = void 0;
21
+ exports.ServiceNowClient = exports.DEFAULT_MAX_CONCURRENT_REQUESTS = exports.BASIC_AUTH_401_HINT = exports.MAX_ERROR_RESPONSE_BYTES = exports.DEFAULT_MAX_JSON_RESPONSE_BYTES = exports.MAX_CUMULATIVE_RAW_RESPONSE_BYTES = exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES = exports.MAX_RETRY_DELAY_MS = exports.DEFAULT_TIMEOUT_MS = exports.isServiceNowResponseTooLarge = exports.ServiceNowResponseTooLargeError = void 0;
22
22
  exports.runWithServiceNowRequestSignal = runWithServiceNowRequestSignal;
23
23
  exports.recordCacheOutcome = recordCacheOutcome;
24
24
  exports.asWatermarkRead = asWatermarkRead;
25
25
  exports.createServiceNowOperations = createServiceNowOperations;
26
- exports.isServiceNowResponseTooLarge = isServiceNowResponseTooLarge;
27
26
  exports.isServiceNowRequestCancellation = isServiceNowRequestCancellation;
28
27
  exports.parseRetryAfterMs = parseRetryAfterMs;
29
28
  exports.retryDelayMs = retryDelayMs;
@@ -34,17 +33,16 @@ const html_response_js_1 = require("./html-response.js");
34
33
  const auth_js_1 = require("./auth.js");
35
34
  const incident_journal_policy_js_1 = require("./incident-journal-policy.js");
36
35
  const tool_error_js_1 = require("./tool-error.js");
36
+ Object.defineProperty(exports, "BASIC_AUTH_401_HINT", { enumerable: true, get: function () { return tool_error_js_1.BASIC_AUTH_401_HINT; } });
37
+ const response_too_large_js_1 = require("./response-too-large.js");
38
+ Object.defineProperty(exports, "ServiceNowResponseTooLargeError", { enumerable: true, get: function () { return response_too_large_js_1.ServiceNowResponseTooLargeError; } });
39
+ Object.defineProperty(exports, "isServiceNowResponseTooLarge", { enumerable: true, get: function () { return response_too_large_js_1.isServiceNowResponseTooLarge; } });
37
40
  exports.DEFAULT_TIMEOUT_MS = 30_000;
38
41
  exports.MAX_RETRY_DELAY_MS = 30_000;
39
42
  exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES = 1024 * 1024;
40
43
  exports.MAX_CUMULATIVE_RAW_RESPONSE_BYTES = 10 * 1024 * 1024;
41
44
  exports.DEFAULT_MAX_JSON_RESPONSE_BYTES = exports.MAX_CUMULATIVE_UPSTREAM_JSON_BYTES;
42
45
  exports.MAX_ERROR_RESPONSE_BYTES = 64 * 1024;
43
- /** Guidance appended to 401 errors on basic-auth profiles. */
44
- exports.BASIC_AUTH_401_HINT = "ServiceNow may be enforcing Basic Auth restrictions on this instance " +
45
- "(see KB3096078). Exemptions: Web-Service-Access-Only account or " +
46
- "snc_basic_auth_api_access role. Recommended: switch this profile to " +
47
- "OAuth (authType: 'oauth').";
48
46
  const DEFAULT_MAX_RETRIES = 2;
49
47
  const DEFAULT_BASE_RETRY_DELAY_MS = 500;
50
48
  exports.DEFAULT_MAX_CONCURRENT_REQUESTS = 4;
@@ -354,6 +352,9 @@ class ServiceNowClient {
354
352
  }
355
353
  buildHttpError(method, status, headers) {
356
354
  const classification = classifyHttpFailure(status, method);
355
+ if (status === 401 && this.#auth.kind === "basic") {
356
+ return (0, tool_error_js_1.createBasicAuthRestrictedError)();
357
+ }
357
358
  const retryAfterSeconds = classification.retry === "retry_later"
358
359
  ? (0, tool_error_js_1.boundedRetryAfterSeconds)(parseRetryAfterMs(headers.get("retry-after")))
359
360
  : undefined;
@@ -465,7 +466,7 @@ async function readBoundedResponseBody(response, maximum, signal, cumulativeBudg
465
466
  catch {
466
467
  // Cancellation is best effort after the response is rejected.
467
468
  }
468
- throw new ServiceNowResponseTooLargeError("raw response exceeds configured byte limit");
469
+ throw new response_too_large_js_1.ServiceNowResponseTooLargeError("raw response exceeds configured byte limit");
469
470
  }
470
471
  if (cumulativeBudget) {
471
472
  try {
@@ -502,7 +503,7 @@ async function readBoundedResponseBody(response, maximum, signal, cumulativeBudg
502
503
  total += chunk.length;
503
504
  if (total > maximum) {
504
505
  await reader.cancel("response exceeds configured byte limit");
505
- throw new ServiceNowResponseTooLargeError("raw response exceeds configured byte limit");
506
+ throw new response_too_large_js_1.ServiceNowResponseTooLargeError("raw response exceeds configured byte limit");
506
507
  }
507
508
  if (cumulativeBudget && total > reserved) {
508
509
  try {
@@ -525,22 +526,6 @@ async function readBoundedResponseBody(response, maximum, signal, cumulativeBudg
525
526
  }
526
527
  return Buffer.concat(chunks, total);
527
528
  }
528
- /**
529
- * A response, or a request scope's cumulative upstream JSON, passed its byte
530
- * limit. A RangeError, as before, so existing handling is unchanged; the
531
- * class lets callers tell it apart from any other RangeError.
532
- */
533
- class ServiceNowResponseTooLargeError extends RangeError {
534
- constructor(message) {
535
- super(message);
536
- this.name = "ServiceNowResponseTooLargeError";
537
- }
538
- }
539
- exports.ServiceNowResponseTooLargeError = ServiceNowResponseTooLargeError;
540
- /** True when a request failed because a response or its scope passed a byte limit. */
541
- function isServiceNowResponseTooLarge(error) {
542
- return error instanceof ServiceNowResponseTooLargeError;
543
- }
544
529
  class ServiceNowRequestCancelledError extends Error {
545
530
  constructor() {
546
531
  super("ServiceNow request cancelled");
@@ -605,7 +590,7 @@ class CumulativeResponseByteBudget {
605
590
  throw new TypeError("upstream byte reservation is invalid");
606
591
  }
607
592
  if (this.#consumed + bytes > this.maximum) {
608
- throw new ServiceNowResponseTooLargeError("cumulative upstream response exceeds configured byte limit");
593
+ throw new response_too_large_js_1.ServiceNowResponseTooLargeError("cumulative upstream response exceeds configured byte limit");
609
594
  }
610
595
  this.#consumed += bytes;
611
596
  }