@onlyflows/servicenow-mcp 2.2.0-dev.6 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/.env.example +6 -3
  2. package/CHANGELOG.md +404 -0
  3. package/README.md +580 -104
  4. package/dist/atf-form.d.ts +3 -15
  5. package/dist/atf-form.d.ts.map +1 -1
  6. package/dist/atf-policy.d.ts +1 -1
  7. package/dist/atf-policy.d.ts.map +1 -1
  8. package/dist/atf-policy.js +2 -0
  9. package/dist/atf-policy.js.map +1 -1
  10. package/dist/atf-result-cache.d.ts +23 -59
  11. package/dist/atf-result-cache.d.ts.map +1 -1
  12. package/dist/auth.d.ts +1 -0
  13. package/dist/auth.d.ts.map +1 -1
  14. package/dist/auth.js +17 -0
  15. package/dist/auth.js.map +1 -1
  16. package/dist/batch-limits.d.ts +18 -0
  17. package/dist/batch-limits.d.ts.map +1 -0
  18. package/dist/batch-limits.js +21 -0
  19. package/dist/batch-limits.js.map +1 -0
  20. package/dist/bounded-input.d.ts +49 -0
  21. package/dist/bounded-input.d.ts.map +1 -0
  22. package/dist/bounded-input.js +81 -0
  23. package/dist/bounded-input.js.map +1 -0
  24. package/dist/client.d.ts +25 -0
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/client.js +92 -18
  27. package/dist/client.js.map +1 -1
  28. package/dist/credential-tables.d.ts +32 -0
  29. package/dist/credential-tables.d.ts.map +1 -0
  30. package/dist/credential-tables.js +58 -0
  31. package/dist/credential-tables.js.map +1 -0
  32. package/dist/encoded-query-policy.d.ts +11 -0
  33. package/dist/encoded-query-policy.d.ts.map +1 -1
  34. package/dist/encoded-query-policy.js +18 -2
  35. package/dist/encoded-query-policy.js.map +1 -1
  36. package/dist/execution-context.d.ts +14 -0
  37. package/dist/execution-context.d.ts.map +1 -1
  38. package/dist/execution-context.js +8 -0
  39. package/dist/execution-context.js.map +1 -1
  40. package/dist/field-policy.d.ts +115 -3
  41. package/dist/field-policy.d.ts.map +1 -1
  42. package/dist/field-policy.js +909 -97
  43. package/dist/field-policy.js.map +1 -1
  44. package/dist/hidden-values.d.ts +225 -0
  45. package/dist/hidden-values.d.ts.map +1 -0
  46. package/dist/hidden-values.js +748 -0
  47. package/dist/hidden-values.js.map +1 -0
  48. package/dist/html-response.d.ts +34 -0
  49. package/dist/html-response.d.ts.map +1 -0
  50. package/dist/html-response.js +72 -0
  51. package/dist/html-response.js.map +1 -0
  52. package/dist/http-entrypoint.d.ts.map +1 -1
  53. package/dist/http-entrypoint.js +7 -0
  54. package/dist/http-entrypoint.js.map +1 -1
  55. package/dist/http-runtime.d.ts.map +1 -1
  56. package/dist/http-runtime.js +8 -0
  57. package/dist/http-runtime.js.map +1 -1
  58. package/dist/incident-journal-policy.d.ts +27 -5
  59. package/dist/incident-journal-policy.d.ts.map +1 -1
  60. package/dist/incident-journal-policy.js +34 -21
  61. package/dist/incident-journal-policy.js.map +1 -1
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/json-shape-limits.d.ts +71 -0
  65. package/dist/json-shape-limits.d.ts.map +1 -0
  66. package/dist/json-shape-limits.js +131 -0
  67. package/dist/json-shape-limits.js.map +1 -0
  68. package/dist/metadata-cache.d.ts +84 -21
  69. package/dist/metadata-cache.d.ts.map +1 -1
  70. package/dist/metadata-cache.js +316 -196
  71. package/dist/metadata-cache.js.map +1 -1
  72. package/dist/policy-card.d.ts +146 -0
  73. package/dist/policy-card.d.ts.map +1 -0
  74. package/dist/policy-card.js +420 -0
  75. package/dist/policy-card.js.map +1 -0
  76. package/dist/profile-manager.d.ts +19 -3
  77. package/dist/profile-manager.d.ts.map +1 -1
  78. package/dist/profile-manager.js +89 -4
  79. package/dist/profile-manager.js.map +1 -1
  80. package/dist/record-identifier-policy.d.ts +2 -8
  81. package/dist/record-identifier-policy.d.ts.map +1 -1
  82. package/dist/risky-grants.d.ts +25 -0
  83. package/dist/risky-grants.d.ts.map +1 -0
  84. package/dist/risky-grants.js +77 -0
  85. package/dist/risky-grants.js.map +1 -0
  86. package/dist/server.d.ts.map +1 -1
  87. package/dist/server.js +26 -5
  88. package/dist/server.js.map +1 -1
  89. package/dist/setup-prompts.js +1 -0
  90. package/dist/setup-prompts.js.map +1 -1
  91. package/dist/setup.d.ts +1 -1
  92. package/dist/setup.d.ts.map +1 -1
  93. package/dist/setup.js +305 -59
  94. package/dist/setup.js.map +1 -1
  95. package/dist/stdio-runtime.d.ts +15 -0
  96. package/dist/stdio-runtime.d.ts.map +1 -1
  97. package/dist/stdio-runtime.js +60 -0
  98. package/dist/stdio-runtime.js.map +1 -1
  99. package/dist/structured-query.d.ts +100 -115
  100. package/dist/structured-query.d.ts.map +1 -1
  101. package/dist/structured-query.js +138 -17
  102. package/dist/structured-query.js.map +1 -1
  103. package/dist/table-policy.d.ts +41 -4
  104. package/dist/table-policy.d.ts.map +1 -1
  105. package/dist/table-policy.js +82 -10
  106. package/dist/table-policy.js.map +1 -1
  107. package/dist/tool-error.d.ts +34 -0
  108. package/dist/tool-error.d.ts.map +1 -1
  109. package/dist/tool-error.js +109 -1
  110. package/dist/tool-error.js.map +1 -1
  111. package/dist/tool-table-access.d.ts.map +1 -1
  112. package/dist/tool-table-access.js +35 -5
  113. package/dist/tool-table-access.js.map +1 -1
  114. package/dist/tools/aggregate.d.ts +13 -19
  115. package/dist/tools/aggregate.d.ts.map +1 -1
  116. package/dist/tools/aggregate.js +4 -5
  117. package/dist/tools/aggregate.js.map +1 -1
  118. package/dist/tools/all-fields-cap.d.ts.map +1 -1
  119. package/dist/tools/all-fields-cap.js +32 -45
  120. package/dist/tools/all-fields-cap.js.map +1 -1
  121. package/dist/tools/atf-author-module.d.ts +29 -14
  122. package/dist/tools/atf-author-module.d.ts.map +1 -1
  123. package/dist/tools/atf-author-module.js +11 -5
  124. package/dist/tools/atf-author-module.js.map +1 -1
  125. package/dist/tools/atf-contracts.d.ts +135 -829
  126. package/dist/tools/atf-contracts.d.ts.map +1 -1
  127. package/dist/tools/atf-shared.js +2 -2
  128. package/dist/tools/atf-shared.js.map +1 -1
  129. package/dist/tools/atf-step-catalog.d.ts +16 -15
  130. package/dist/tools/atf-step-catalog.d.ts.map +1 -1
  131. package/dist/tools/atf-step-catalog.js +181 -10
  132. package/dist/tools/atf-step-catalog.js.map +1 -1
  133. package/dist/tools/atf.d.ts +8 -24
  134. package/dist/tools/atf.d.ts.map +1 -1
  135. package/dist/tools/atf.js +2 -2
  136. package/dist/tools/atf.js.map +1 -1
  137. package/dist/tools/attach.d.ts +6 -22
  138. package/dist/tools/attach.d.ts.map +1 -1
  139. package/dist/tools/batch.d.ts +18 -71
  140. package/dist/tools/batch.d.ts.map +1 -1
  141. package/dist/tools/batch.js +566 -100
  142. package/dist/tools/batch.js.map +1 -1
  143. package/dist/tools/catalog.d.ts +2 -2
  144. package/dist/tools/catalog.d.ts.map +1 -1
  145. package/dist/tools/catalog.js +7 -1
  146. package/dist/tools/catalog.js.map +1 -1
  147. package/dist/tools/codesearch.d.ts +1 -13
  148. package/dist/tools/codesearch.d.ts.map +1 -1
  149. package/dist/tools/create-module.d.ts +9 -14
  150. package/dist/tools/create-module.d.ts.map +1 -1
  151. package/dist/tools/create-module.js +4 -8
  152. package/dist/tools/create-module.js.map +1 -1
  153. package/dist/tools/delete.d.ts +1 -9
  154. package/dist/tools/delete.d.ts.map +1 -1
  155. package/dist/tools/delete.js +2 -3
  156. package/dist/tools/delete.js.map +1 -1
  157. package/dist/tools/discover.d.ts +6 -14
  158. package/dist/tools/discover.d.ts.map +1 -1
  159. package/dist/tools/flow-view-contracts.d.ts +1023 -0
  160. package/dist/tools/flow-view-contracts.d.ts.map +1 -0
  161. package/dist/tools/flow-view-contracts.js +570 -0
  162. package/dist/tools/flow-view-contracts.js.map +1 -0
  163. package/dist/tools/flow-view-graph.d.ts +86 -0
  164. package/dist/tools/flow-view-graph.d.ts.map +1 -0
  165. package/dist/tools/flow-view-graph.js +993 -0
  166. package/dist/tools/flow-view-graph.js.map +1 -0
  167. package/dist/tools/flow-view-gzip.d.ts +52 -0
  168. package/dist/tools/flow-view-gzip.d.ts.map +1 -0
  169. package/dist/tools/flow-view-gzip.js +179 -0
  170. package/dist/tools/flow-view-gzip.js.map +1 -0
  171. package/dist/tools/flow-view-mermaid.d.ts +37 -0
  172. package/dist/tools/flow-view-mermaid.d.ts.map +1 -0
  173. package/dist/tools/flow-view-mermaid.js +337 -0
  174. package/dist/tools/flow-view-mermaid.js.map +1 -0
  175. package/dist/tools/flow-view-module.d.ts +61 -0
  176. package/dist/tools/flow-view-module.d.ts.map +1 -0
  177. package/dist/tools/flow-view-module.js +378 -0
  178. package/dist/tools/flow-view-module.js.map +1 -0
  179. package/dist/tools/flow-view-policy.d.ts +106 -0
  180. package/dist/tools/flow-view-policy.d.ts.map +1 -0
  181. package/dist/tools/flow-view-policy.js +462 -0
  182. package/dist/tools/flow-view-policy.js.map +1 -0
  183. package/dist/tools/flow-view-renderers.d.ts +68 -0
  184. package/dist/tools/flow-view-renderers.d.ts.map +1 -0
  185. package/dist/tools/flow-view-renderers.js +513 -0
  186. package/dist/tools/flow-view-renderers.js.map +1 -0
  187. package/dist/tools/flow-view-table.d.ts +115 -0
  188. package/dist/tools/flow-view-table.d.ts.map +1 -0
  189. package/dist/tools/flow-view-table.js +1002 -0
  190. package/dist/tools/flow-view-table.js.map +1 -0
  191. package/dist/tools/get-module.d.ts +36 -42
  192. package/dist/tools/get-module.d.ts.map +1 -1
  193. package/dist/tools/health.d.ts +9 -6
  194. package/dist/tools/health.d.ts.map +1 -1
  195. package/dist/tools/incident-journal-module.d.ts +8 -7
  196. package/dist/tools/incident-journal-module.d.ts.map +1 -1
  197. package/dist/tools/index.d.ts +4 -4
  198. package/dist/tools/index.d.ts.map +1 -1
  199. package/dist/tools/index.js +118 -18
  200. package/dist/tools/index.js.map +1 -1
  201. package/dist/tools/markdown.d.ts +27 -0
  202. package/dist/tools/markdown.d.ts.map +1 -1
  203. package/dist/tools/markdown.js +104 -1
  204. package/dist/tools/markdown.js.map +1 -1
  205. package/dist/tools/nl.d.ts +1 -11
  206. package/dist/tools/nl.d.ts.map +1 -1
  207. package/dist/tools/profile.d.ts +1 -1
  208. package/dist/tools/profile.d.ts.map +1 -1
  209. package/dist/tools/profile.js +20 -1
  210. package/dist/tools/profile.js.map +1 -1
  211. package/dist/tools/query-module.d.ts +59 -71
  212. package/dist/tools/query-module.d.ts.map +1 -1
  213. package/dist/tools/query-module.js +28 -7
  214. package/dist/tools/query-module.js.map +1 -1
  215. package/dist/tools/record-write-shared.d.ts.map +1 -1
  216. package/dist/tools/record-write-shared.js +20 -2
  217. package/dist/tools/record-write-shared.js.map +1 -1
  218. package/dist/tools/relationships.d.ts +6 -22
  219. package/dist/tools/relationships.d.ts.map +1 -1
  220. package/dist/tools/result-envelope.d.ts +2255 -1357
  221. package/dist/tools/result-envelope.d.ts.map +1 -1
  222. package/dist/tools/result-envelope.js +24 -2
  223. package/dist/tools/result-envelope.js.map +1 -1
  224. package/dist/tools/schema-module.d.ts +36 -21
  225. package/dist/tools/schema-module.d.ts.map +1 -1
  226. package/dist/tools/schema-module.js +106 -65
  227. package/dist/tools/schema-module.js.map +1 -1
  228. package/dist/tools/script.d.ts +1 -11
  229. package/dist/tools/script.d.ts.map +1 -1
  230. package/dist/tools/syslog.d.ts +11 -18
  231. package/dist/tools/syslog.d.ts.map +1 -1
  232. package/dist/tools/syslog.js +2 -3
  233. package/dist/tools/syslog.js.map +1 -1
  234. package/dist/tools/table-hierarchy.d.ts +35 -0
  235. package/dist/tools/table-hierarchy.d.ts.map +1 -0
  236. package/dist/tools/table-hierarchy.js +74 -0
  237. package/dist/tools/table-hierarchy.js.map +1 -0
  238. package/dist/tools/tool-module.d.ts +40 -15
  239. package/dist/tools/tool-module.d.ts.map +1 -1
  240. package/dist/tools/tool-module.js +755 -205
  241. package/dist/tools/tool-module.js.map +1 -1
  242. package/dist/tools/update-module.d.ts +11 -17
  243. package/dist/tools/update-module.d.ts.map +1 -1
  244. package/dist/tools/update-module.js +10 -12
  245. package/dist/tools/update-module.js.map +1 -1
  246. package/dist/unknown-filter-fields.d.ts +52 -0
  247. package/dist/unknown-filter-fields.d.ts.map +1 -0
  248. package/dist/unknown-filter-fields.js +87 -0
  249. package/dist/unknown-filter-fields.js.map +1 -0
  250. package/dist/version.d.ts +1 -1
  251. package/dist/version.d.ts.map +1 -1
  252. package/dist/version.js +1 -1
  253. package/dist/version.js.map +1 -1
  254. package/dist/write-value-policy.d.ts +20 -12
  255. package/dist/write-value-policy.d.ts.map +1 -1
  256. package/dist/write-value-policy.js +179 -67
  257. package/dist/write-value-policy.js.map +1 -1
  258. package/docs/ADDING-TOOLS.md +22 -13
  259. package/docs/CLIENT-SETUP.md +110 -52
  260. package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +2 -2
  261. package/docs/FLOW-VIEW.md +214 -0
  262. package/docs/PRODUCTION-SECURITY.md +218 -25
  263. package/docs/RELEASE-VALIDATION.md +2 -2
  264. package/docs/TESTING-OAUTH.md +1 -1
  265. package/docs/V2-MIGRATION.md +404 -30
  266. package/package.json +20 -6
  267. package/scripts/release-validate.mjs +56 -0
  268. package/server.json +22 -0
  269. package/tools/inspector/package-lock.json +163 -201
package/README.md CHANGED
@@ -1,17 +1,92 @@
1
1
  # @onlyflows/servicenow-mcp
2
2
 
3
- <!-- Logo placeholder -->
4
- <!-- ![ServiceNow MCP Server](banner.png) -->
3
+ A governed ServiceNow MCP server: it lets an AI client read and change records on your instances, within limits you set per connection.
5
4
 
6
- **The most comprehensive ServiceNow MCP server.** 23 tools for full CRUD, append-only incident journals, CMDB graph traversal, ATF testing, multi-instance profiles, and more.
7
-
8
- Built by [OnlyFlows](https://onlyflows.tech) · Published by [@onlyflowstech](https://github.com/onlyflowstech)
5
+ <!-- DEMO GIF PLACEHOLDER: add a short screen recording here (asking a question, then a denied write and a dry-run batch). Not recorded yet. -->
9
6
 
10
7
  [![npm version](https://img.shields.io/npm/v/@onlyflows/servicenow-mcp)](https://www.npmjs.com/package/@onlyflows/servicenow-mcp)
11
8
  [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
12
9
 
13
- ---
10
+ Built by [OnlyFlows](https://onlyflows.tech) · Published by [@onlyflowstech](https://github.com/onlyflowstech)
14
11
 
12
+ ## Governed and safe for production
13
+
14
+ The server exposes 24 tools over stdio. Every call runs inside controls that
15
+ you configure and that no tool of this server can change:
16
+
17
+ - **Per-profile table and field policy.** Each profile (a named ServiceNow
18
+ connection) has its own read and write table allowlists. Access is
19
+ deny-by-default: a profile with no rules denies every ServiceNow call. Field
20
+ policy decides which fields can be read or written; sensitive field names
21
+ are refused.
22
+ - **Confirmation flag on destructive tools.** `sn_delete` and `sn_batch`
23
+ change nothing unless the call carries `confirm: true`. The model sets that
24
+ flag itself, so it is a guard against accidents, not an approval. A person
25
+ approves through the client's own tool-approval prompt, and many clients let
26
+ you "always allow" a tool. `sn_create` and `sn_update` take no confirm flag;
27
+ keep write grants narrow.
28
+ - **Safe batching.** `sn_batch` takes a structured filter (no raw encoded
29
+ queries), runs as a dry run by default, caps a run at 10,000 records, and
30
+ never re-sends a batch.
31
+ - **Activity events.** Each completed tool call writes one JSON line to
32
+ stderr with the tool, profile, instance and outcome, plus hashed owner and
33
+ client labels. It records no table, record or fields. Delivery is
34
+ best-effort through stderr, and events are dropped above 256 pending lines.
35
+ Use ServiceNow's own audit history for record changes.
36
+ - **Explicit profile on every call.** There is no default or "active"
37
+ instance. Each call names its profile, so nothing reaches an instance the
38
+ call didn't name. Keep write grants on production profiles narrow.
39
+ - **Credentials stay out of clients.** Secrets are entered at a hidden prompt,
40
+ verified against the instance before anything is saved, and stored
41
+ encrypted in an owner-only `~/.servicenow-mcp` directory.
42
+
43
+ > **Limits of these controls.** They hold against the model's tool calls. A
44
+ > client that gives the model a shell or file access (Claude Code and Codex
45
+ > can) could run `servicenow-mcp-setup grant` or read
46
+ > `~/.servicenow-mcp/server.env`. The encryption key sits in the same
47
+ > owner-only folder as the encrypted profiles, so it protects against other
48
+ > users and stray copies of the files, not against your own account. Run
49
+ > production profiles from a client or account without shell access where you
50
+ > can.
51
+
52
+ Details: [Table access policy](#table-access-policy),
53
+ [Safety Features](#safety-features) and [docs/PRODUCTION-SECURITY.md](docs/PRODUCTION-SECURITY.md).
54
+
55
+ ## Works with
56
+
57
+ Any MCP client that can launch a stdio server. Setup registers **Claude Code**
58
+ and **Codex** automatically; **Claude Desktop**, **Cursor**, **VS Code** and
59
+ **Windsurf** are configured with `servicenow-mcp-setup client --client <name>`
60
+ (see [Connecting a client](#connecting-a-client)). Requires Node.js 20 or newer.
61
+
62
+ ## Quick start
63
+
64
+ 1. **Install:** `npm install -g @onlyflows/servicenow-mcp`
65
+ 2. **Set up a connection:** `servicenow-mcp-setup`. It asks for your instance
66
+ and credential, checks them against the instance, asks which tables to
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).
70
+ 3. **Open your client and ask.** There is no server to start; the client
71
+ launches `servicenow-mcp` itself.
72
+
73
+ The default read grant in the wizard is **just `incident`**, and writes default
74
+ to **none**. Grant more later with `servicenow-mcp-setup grant`.
75
+
76
+ ## Try asking
77
+
78
+ These work with the default read grant (profile named `dev`):
79
+
80
+ 1. "On dev, list the 10 most recent open P1 incidents."
81
+ 2. "On dev, how many incidents are there, grouped by priority?"
82
+ 3. "On dev, which assignment groups have the most incidents?"
83
+ 4. "On dev, which open incidents have no assignee, oldest first?"
84
+ 5. "On dev, show incident INC0010001 and summarize where it stands."
85
+
86
+ Your client sends `profile: "dev"` with each call. Asking about other tables
87
+ (for example `change_request`) is denied until you grant them.
88
+
89
+ ---
15
90
 
16
91
  ## Installation
17
92
 
@@ -136,8 +211,14 @@ servicenow-mcp-setup grant --profile dev --read incident,problem --write inciden
136
211
  | `servicenow-mcp-setup` | Generate local auth material and register supported clients |
137
212
  | `servicenow-mcp-setup client --client <name>` | Print copy-pasteable config for a client |
138
213
  | `servicenow-mcp-setup grant --profile <name> --read <tables>` | Add table access rules to a profile |
214
+ | `servicenow-mcp-setup policy show --profile <name>` | Print the profile's effective policy as one table (tables, tools, fields, batch limits); never prints a secret |
139
215
  | `servicenow-mcp-setup doctor` | Diagnose the install and print remedies |
140
216
 
217
+ `grant` and the wizard print a warning, and still grant, when write access
218
+ lands on a privilege-sensitive table: role, group, approval, script,
219
+ property, user or authentication tables such as `sys_user_has_role`,
220
+ `sysapproval_approver` or `sys_script`.
221
+
141
222
  `--force` regenerates the owner/client identifiers but deliberately preserves
142
223
  `SN_PROFILE_ENCRYPTION_KEY`, which decrypts every credential envelope in
143
224
  `config.json`. Add `--help` to any command for its full options.
@@ -324,7 +405,11 @@ The resulting `~/.servicenow-mcp/config.json` looks like this. Note
324
405
  {
325
406
  "table": "incident",
326
407
  "kind": "canonical",
327
- "tools": ["sn_query", "sn_get", "sn_aggregate", "sn_schema", "sn_create", "sn_update"],
408
+ "tools": [
409
+ "sn_query", "sn_get", "sn_aggregate", "sn_schema",
410
+ "sn_create", "sn_update",
411
+ "sn_incident_add_comment", "sn_incident_add_work_note"
412
+ ],
328
413
  "closureComplete": true,
329
414
  "relatedTables": ["incident"]
330
415
  },
@@ -348,12 +433,29 @@ environment the server is spawned with, or in `~/.servicenow-mcp/server.env`,
348
433
  which the server falls back to. Do not type either value into a shell command,
349
434
  command argument, dotenv file, or command history.
350
435
 
351
- Each `targets` entry asserts `closureComplete: true`, meaning `relatedTables`
352
- lists every backing, ancestor, and descendant table the operation can reach.
353
- When a table extends another, declare it:
436
+ Each `targets` entry must set the literal `closureComplete: true`, and its
437
+ `relatedTables` must include the target table itself. `relatedTables` is a
438
+ declaration that the loader checks for consistency: every related table must
439
+ be in the allowlist of each operation the target is in, or the profile is
440
+ rejected. The loader does not derive it from the instance. ServiceNow returns
441
+ inherited fields through the child table's own endpoint, so a self-only list
442
+ such as `["incident"]` is enough to read them. Declaring the immediate parent,
443
+ as `servicenow-mcp-setup` offers, is optional:
354
444
  `servicenow-mcp-setup grant --profile dev --read change_request --related change_request=task`.
355
- Related tables join the allowlist but get no target of their own, so a caller
356
- cannot address them directly.
445
+ That adds `task` to the read allowlist, because the loader requires it, and a
446
+ later grant that gives `change_request` another operation adds `task` to that
447
+ operation's allowlist too. On its own this makes `task` addressable by no tool,
448
+ because it has no target of its own, unless such an allowlist is `*`. If
449
+ `task` has, or later gets, a target of its own, that target's tools can then
450
+ use those operations on it, so declare a table only where every tool on its
451
+ own target may use every operation the declaring target has or will have.
452
+ A grant on a base table such as `task` reaches the records of the tables that
453
+ extend it, such as `incident`, whatever `relatedTables` lists, so grant a base
454
+ table only when those records should be reachable through it. Likewise, a
455
+ view or alias returns data from every table it reads, whatever
456
+ `relatedTables` lists: declare each of those tables, so the loader requires
457
+ each to carry the same permission, and grant the view only when all of that
458
+ data should be reachable.
357
459
 
358
460
  ### Credential Options
359
461
 
@@ -471,36 +573,28 @@ ServiceNow upstream can return HTTP 429 with an empty body, while this server's
471
573
 
472
574
  ---
473
575
 
474
- ## Why This MCP Server?
475
-
476
- Most ServiceNow MCP integrations are **read-only** and support a handful of
477
- tables. This service offers a broader tool catalog behind explicit,
478
- deny-by-default table and tool policy:
479
-
480
- | Feature | Others | @onlyflows/servicenow-mcp |
481
- |---------|--------|--------------------------|
482
- | Query records | ✅ | ✅ |
483
- | Create records | ❌ | ✅ |
484
- | Update records | ❌ | ✅ |
485
- | Delete records | ❌ | ✅ (with safety confirm) |
486
- | Bulk operations | ❌ | ✅ (dry-run by default) |
487
- | Aggregations (COUNT/AVG/MIN/MAX/SUM) | ❌ | ✅ |
488
- | Table schema introspection | ❌ | ✅ |
489
- | CMDB relationship traversal | ❌ | ✅ (recursive, configurable depth) |
490
- | Instance health monitoring | ❌ | ✅ (version, nodes, jobs, stats) |
491
- | Attachment management | ❌ | ✅ (list, upload, download; inline base64, no host filesystem) |
492
- | System log queries | ❌ | ✅ |
493
- | Code search across artifacts | ❌ | ✅ |
494
- | Table/app/plugin discovery | ❌ | ✅ |
495
- | ATF test execution | ❌ | ✅ suite execution with explicit profile grant |
496
- | Natural language interface | ❌ | 🚧 currently policy-denied pending a typed access plan |
497
- | Background scripts | ❌ | 🚧 on the [roadmap](#roadmap) (SNS-39) |
498
- | Multi-instance profiles | ❌ | ✅ (named profiles, per-call override) |
499
- | **Total tools** | **1–3** | **23** |
576
+ ## What the tools cover
577
+
578
+ The registered catalog has 24 tools (see [Tools Reference](#tools-reference)):
579
+
580
+ | Area | Tools |
581
+ |------|-------|
582
+ | Records | `sn_query`, `sn_get`, `sn_create`, `sn_update`, `sn_delete`, `sn_batch` |
583
+ | Incident journals (append-only) | `sn_incident_add_comment`, `sn_incident_add_work_note` |
584
+ | Analytics and schema | `sn_aggregate`, `sn_schema`, `sn_health` |
585
+ | CMDB and operations | `sn_relationships`, `sn_attach`, `sn_syslog`, `sn_codesearch`, `sn_discover` |
586
+ | ATF | `sn_atf_author`, `sn_atf_run`, `sn_atf_results`, `sn_atf_readiness`, `sn_atf` |
587
+ | Flow Designer (read-only) | `sn_flow_view` |
588
+ | Profiles | `sn_profile` |
589
+ | Natural language | `sn_nl` (currently policy-denied pending a typed access plan) |
590
+
591
+ Every tool requires a `profile`, and every tool is subject to the profile's
592
+ table and field policy. `sn_script` (background scripts) is not registered; see
593
+ the [Roadmap](#roadmap).
500
594
 
501
595
  ---
502
596
 
503
- ## Quick Start
597
+ ## Manual environment setup
504
598
 
505
599
  The server speaks stdio and requires Node.js 20 or newer. The shortest path is
506
600
  the bootstrap described under [Installation](#installation):
@@ -570,6 +664,10 @@ Those two require action on every install. The transport is stdio, as it was in
570
664
  The breaking changes from `1.0.0`, each with a before/after example, are in
571
665
  [Migrating to 2.0](docs/V2-MIGRATION.md#breaking-changes-at-a-glance).
572
666
 
667
+ Already on 2.x? 2.2.0 changes field-policy loading and journal writes, and
668
+ can refuse to start on a configuration that loads today. Read
669
+ [Upgrading to 2.2.0](docs/V2-MIGRATION.md#upgrading-to-220) first.
670
+
573
671
  ### Deployment guides for the dormant HTTP transport
574
672
 
575
673
  2.0 ships stdio only. The container image, the health and shutdown contract,
@@ -596,12 +694,12 @@ in this section is needed to use this server.
596
694
  |------|-------------|
597
695
  | `sn_query` | Query an approved table with structured filters, field selection, pagination, and sorting; bounded raw reads require an explicit policy rule |
598
696
  | `sn_get` | Get a single record by sys_id from an approved table |
599
- | `sn_create` | Create a record on any table granted for writes, using only field-policy-approved writable fields; `incident` additionally requires a bounded `short_description` |
600
- | `sn_update` | Update one record selected by exact `sys_id` on any table granted for writes, using only field-policy-approved writable fields; rejects `comments` and `work_notes` with dedicated-tool migration guidance |
697
+ | `sn_create` | Create a record on any table granted for writes, using only field-policy-approved writable fields, including the journal fields `comments` and `work_notes`; `incident` additionally requires a bounded `short_description` |
698
+ | `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 |
601
699
  | `sn_incident_add_comment` | Append one bounded customer-visible comment to an incident; repeated calls append again |
602
700
  | `sn_incident_add_work_note` | Append one bounded internal work note to an incident; repeated calls append again |
603
701
  | `sn_delete` | Delete a record on an approved write table (requires `confirm: true`) |
604
- | `sn_batch` | Bulk update/delete using a required structured filter and dry-run safety (raw encoded selectors are prohibited; requires `confirm: true` to execute) |
702
+ | `sn_batch` | Bulk update/delete using a required structured filter and dry-run safety (raw encoded selectors are prohibited; requires `confirm: true` to execute; a dry run returns the count, up to 5 sample records the profile may read, and the field names it would write). Values get the same policy as `sn_update`; execution uses the ServiceNow REST Batch API and never re-sends a batch |
605
703
 
606
704
  ### Analytics & Schema
607
705
 
@@ -636,11 +734,17 @@ in this section is needed to use this server.
636
734
  stub and is **not published in 2.0** — it does not appear in `tools/list`. Use
637
735
  `sn_query` and `sn_batch` instead. See [Roadmap](#roadmap).
638
736
 
737
+ ### Flow Designer
738
+
739
+ | Tool | Description |
740
+ |------|-------------|
741
+ | `sn_flow_view` | Show a flow or subflow as a Mermaid diagram, an outline and a structured graph: trigger, steps, branches, loops, error handling, input values under field policy, and called subflows to depth 3. Read-only through the Table API; never calls Flow Designer's internal API. See [docs/FLOW-VIEW.md](docs/FLOW-VIEW.md) |
742
+
639
743
  ### Profile Management
640
744
 
641
745
  | Tool | Description |
642
746
  |------|-------------|
643
- | `sn_profile` | Inspect non-secret metadata for one explicitly named profile; profile configuration is operator-managed out of band |
747
+ | `sn_profile` | Inspect non-secret metadata and the effective policy card for one explicitly named profile; profile configuration is operator-managed out of band |
644
748
 
645
749
  ---
646
750
 
@@ -747,49 +851,57 @@ for 24 hours by default. The default cached table patterns are
747
851
  `sys_metadata*`, and `sys_flow*`. Set `metadataCache.ttlMs` and
748
852
  `metadataCache.tables` on a file-backed profile, or `SN_METADATA_CACHE_TTL_MS`
749
853
  / `SN_METADATA_CACHE_TABLES` for the explicit environment profile. `sn_query`,
750
- `sn_get`, and `sn_schema` accept `force_recache: true` to refresh metadata. A
751
- cache hit performs a lightweight `sys_updated_on` probe and is used only when no
752
- matching metadata rows changed since the previous sync.
753
-
754
- **Prerequisite: a resolvable session timezone.** The freshness probe compares
755
- `sys_updated_on`, which ServiceNow evaluates in the *session user's* timezone,
756
- not UTC. Resolving that zone requires the authenticating account's `user_name`
757
- to look up `sys_user.time_zone`, falling back to the `glide.sys.default.tz`
758
- property. When it cannot be resolved the cache **disables itself** for that
759
- identity rather than assuming UTC — a wrong assumption would silently serve
760
- stale metadata for the length of the offset. The server logs a warning naming
761
- the reads it needs.
762
-
763
- This has one consequence worth knowing before you configure it:
764
-
765
- | Profile auth | Metadata caching |
766
- |---|---|
767
- | Basic | works — the profile carries a username |
768
- | OAuth **password** grant | works — the profile carries a username |
769
- | OAuth **client_credentials** | **disabled** — no username to resolve a timezone from |
770
- | API key | **disabled** — no username to resolve a timezone from |
771
-
772
- The profile also needs read access to `sys_user` (for `time_zone`) and
773
- `sys_properties` (for `glide.sys.default.tz`) for the lookup to succeed at all.
854
+ `sn_get`, and `sn_schema` accept `force_recache: true` to refresh metadata.
855
+
856
+ **Freshness is checked against the instance, in every auth mode.** Before each
857
+ fetch the cache reads a watermark in one small request: the table's row count
858
+ (`X-Total-Count`) and its newest row by `sys_updated_on`, as ServiceNow stores
859
+ it (UTC). A cache hit is served only while a new read of that watermark still
860
+ matches. Inserts and deletes change the count, and inserts and updates change
861
+ the newest row. Both sides of the comparison come from the instance, so the
862
+ session timezone, the date format, and clock skew between this host and the
863
+ instance play no part, and no user lookup is needed. Basic, OAuth (password or
864
+ client_credentials), and API-key profiles all cache the same way. The only
865
+ access it needs is the ServiceNow read permission of the user the credential
866
+ runs as, on the cached table itself; no `tableAccess` change is needed.
774
867
 
775
868
  **The honest tradeoff:** the cache only ever saved payload bytes, never round
776
- trips — a cache hit still costs one freshness probe. So on a client-credentials
777
- or API-key profile the practical loss is bandwidth on `sys_dictionary` reads,
778
- not latency. If you are choosing an auth mode, this should not be the deciding
779
- factor.
780
-
781
- **Deletions become visible within one TTL.** The freshness probe detects
782
- updates, not deletes, so a row deleted upstream stays served until its entry
783
- expires and is re-fetched — up to 24 hours at the default TTL. This is accepted
784
- behavior, not a defect; lower `SN_METADATA_CACHE_TTL_MS` or pass
785
- `force_recache: true` if you need a deletion reflected sooner.
869
+ trips — a cache hit still costs one watermark read, and a miss costs one extra.
870
+ A tool call reads each table's watermark once, however many times it reads the
871
+ table, until the call writes. A hierarchy walk reads `sys_db_object` once for
872
+ the whole chain. An empty table caches like any other.
873
+
874
+ If a table's watermark cannot be used, its reads go straight upstream, without
875
+ a watermark request, for a while: 15 minutes when the cause persists (an
876
+ incomplete or future-dated watermark, a 403 or 404), 30 seconds when it may not
877
+ (429, 5xx, timeouts, network), never longer than the TTL. A table whose newest
878
+ row is dated after the instance's own clock is one of these: that row would
879
+ stay the newest however many others were updated. Entries cached earlier are
880
+ kept and serve again once the table is cacheable, and `force_recache: true`
881
+ asks again at once.
882
+
883
+ **What the watermark can miss.** An update within the same second as the stored
884
+ watermark, to a row other than the newest, and a write that skips the system
885
+ fields (`autoSysFields(false)`) leave it unchanged. Such a change shows within
886
+ one TTL — up to 24 hours at the default. Lower `SN_METADATA_CACHE_TTL_MS` or
887
+ pass `force_recache: true` to see it sooner. `sn_batch` is not exposed to these
888
+ gaps: it looks up the records it will update or delete on the instance on every
889
+ run, never in the cache, even on a cached table.
890
+
891
+ **`sn_schema` results** are also kept for 5 minutes per profile, credential
892
+ identity, and effective policy, so a repeat call costs no request at all. They
893
+ are not revalidated in that window; `force_recache: true` refreshes them, and
894
+ `schemaCacheTtlMs` / `SN_SCHEMA_CACHE_TTL_MS` (up to 1 hour) changes the window.
786
895
 
787
896
  ### Unrestricted field selection (`fields=all`, `response_format=detailed`)
788
897
 
789
- Both resolve to a wildcard selection. They previously dropped `sysparm_fields`
790
- entirely, so ServiceNow returned every column and a wide table could breach the
791
- 1 MiB cumulative upstream cap and **fail the call outright**. They are now
792
- bounded to at most **100 columns**.
898
+ Both resolve to the profile's readable set for the table. Where the field
899
+ policy narrows that set, they request exactly the listed fields and read no
900
+ dictionary rows; the rest of this section applies when the readable set is
901
+ every field. That wildcard selection used to drop `sysparm_fields` entirely,
902
+ so ServiceNow returned every column and a wide table could breach the 1 MiB
903
+ cumulative upstream cap and **fail the call outright**. It is now bounded to at
904
+ most **100 columns**.
793
905
 
794
906
  The cap bounds the *upstream request*, not the response — truncating after
795
907
  receipt would not help, because the bytes have already crossed the wire and
@@ -808,7 +920,8 @@ Two behavior changes worth stating plainly, because they change what a caller
808
920
  gets back:
809
921
 
810
922
  - **Journal fields are now returned.** `comments` and `work_notes` are included
811
- in the resolved set for `fields=all` and `detailed`. See
923
+ in the resolved set for `fields=all` and `detailed` wherever the profile can
924
+ read them. See
812
925
  [Journal content and field selection](#journal-content-and-field-selection).
813
926
  - **Sensitive-looking field names are excluded from the resolved set entirely.**
814
927
  A name matching the sensitive-field pattern is never *requested*, rather than
@@ -870,6 +983,7 @@ the same loader the server uses at request time:
870
983
  servicenow-mcp-setup grant --profile dev --read incident,problem --write incident
871
984
  servicenow-mcp-setup grant --profile dev --read cmdb_ci --tools sn_query,sn_relationships
872
985
  servicenow-mcp-setup grant --profile dev --read change_request --related change_request=task
986
+ servicenow-mcp-setup grant --profile dev --flows # sn_flow_view's 15 tables, bound to sn_flow_view only
873
987
  ```
874
988
 
875
989
  Allowlist entries may be exact table names or the literal `*` to allow every
@@ -887,23 +1001,27 @@ and must be valid ServiceNow identifiers.
887
1001
 
888
1002
  | Variable | Required | Default | Description |
889
1003
  |----------|----------|---------|-------------|
890
- | `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. |
891
- | `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. |
892
- | `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 the complete backing/ancestor/descendant `relatedTables` closure. With `*`, omitted target entries use the wildcard operation grant; explicit target entries can still narrow tools and validate related-table closure. |
893
- | `SN_FIELD_POLICY_DEFINITIONS` | Required for custom/generic table fields | built-in finite policy | Trusted JSON object keyed by table name or `*`. Each entry may define `defaults`, `readable`, and `writable`; `readable`/`writable` accept exact field arrays or `"*"`. Sensitive field names are still denied. Use `{"*":{"defaults":["sys_id"],"readable":"*","writable":[]}}` for broad read-only custom-table exploration. Use `writable:"*"` only for intentional broad mutation access. |
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 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)). |
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 except the same six named-only tables. Write permission never implies read permission. |
1006
+ | `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
+ | `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). |
894
1008
  | `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. |
895
1009
 
896
1010
  Invalid policy configuration fails startup. A composed tool is admitted only
897
- when its complete backing-table plan is allowed before the first ServiceNow
898
- client access. Every related target must have the same read or write
899
- permission, so a base table, alias, view, or extension cannot bypass an
900
- unlisted backing or descendant table.
901
- Related permission does not make a dependency directly caller-addressable
902
- without its own target entry. Field policy narrows what a granted table exposes; it does not deny a table the
1011
+ when every table in its access plan is allowed before the first ServiceNow
1012
+ client access. A target's declared related tables must each have the same
1013
+ read or write permission as the target, or the policy is rejected. Related
1014
+ permission does not make a table directly caller-addressable without its own
1015
+ target entry. The related tables are a declaration, not a list derived from
1016
+ the instance: a grant on a base table reaches the records of the tables that
1017
+ extend it whether or not they are listed, so grant a base table only when
1018
+ those records should be reachable. Likewise, a view or alias returns data from
1019
+ every table it reads, whatever `relatedTables` lists: declare each of those
1020
+ tables, so the loader requires each to carry the same permission, and grant
1021
+ the view only when all of that data should be reachable. Field policy narrows what a granted table exposes; it does not deny a table the
903
1022
  operator granted. Sensitive-looking field names remain excluded regardless. Build the
904
- complete target catalog from approved ServiceNow metadata and treat it as
905
- trusted startup configuration; omit a target when reachability cannot be proven
906
- complete. File-backed profile example:
1023
+ target catalog from approved ServiceNow metadata and treat it as trusted
1024
+ startup configuration. File-backed profile example:
907
1025
 
908
1026
  ```json
909
1027
  {
@@ -920,7 +1038,7 @@ complete. File-backed profile example:
920
1038
  {
921
1039
  "table": "incident",
922
1040
  "kind": "canonical",
923
- "tools": ["sn_query", "sn_get", "sn_create", "sn_update"],
1041
+ "tools": ["sn_query", "sn_get", "sn_create", "sn_update", "sn_incident_add_comment", "sn_incident_add_work_note"],
924
1042
  "closureComplete": true,
925
1043
  "relatedTables": ["incident"]
926
1044
  }
@@ -934,12 +1052,370 @@ complete. File-backed profile example:
934
1052
  `run`/`run-suite` return migration guidance; use `sn_atf_run` with an explicit
935
1053
  `atf.execute` profile grant. Typed ATF steps use the authenticated native form
936
1054
  to save and verify inputs and output references without ACL changes or an
937
- installed application. See [ATF workflow](docs/ATF-WORKFLOW.md).
938
- Incident journal fields are append-only: generic `sn_update` rejects `comments`
939
- and `work_notes` before credentials or client creation. Use
940
- `sn_incident_add_comment` or `sn_incident_add_work_note` with exactly
941
- `profile`, incident `sys_id`, and bounded `content`; grant the selected tool
942
- explicitly on the `incident` target as well as write access to that table.
1055
+ installed application. `sn_atf_author` checks each step that names a table
1056
+ against the profile's grants: a `record_query`, `record_validation`,
1057
+ `field_values_validation` or `open_existing_record` step needs a read grant on its
1058
+ table, and an `open_new_form` or `set_field_values` step a write grant (a
1059
+ named-only table must be named, for either). The conditions of the three steps
1060
+ that have them may use only the operators that compare a field with a literal
1061
+ (`=`, `!=`, `<`, `<=`, `>`, `>=`, `LIKE`, `NOT LIKE`, `STARTSWITH`, `ENDSWITH`,
1062
+ `IN`, `NOT IN`, `ISEMPTY`, `ISNOTEMPTY`, `BETWEEN`), name plain fields the field
1063
+ policy lets the profile read (no dot-walks), and may refer to an earlier step's
1064
+ output only by its record id or sys_id (`record_id`, `first_record`, `sys_id`
1065
+ or `user`), as may the values a `set_field_values` step sets; a refused term
1066
+ refuses the whole call. The fields a `set_field_values` step sets must be
1067
+ writable on its table under the profile's field policy, as for `sn_update`. `record_query` and `record_validation` also refuse
1068
+ `enforce_security: false`; leave it out and it stays `true`. The impersonated
1069
+ user's ACLs still apply on top of all this. Suites authored in the instance are
1070
+ not checked by the server's table grants, and `atf.execute` stays opt-in. See
1071
+ [ATF workflow](docs/ATF-WORKFLOW.md).
1072
+
1073
+ #### Field policy
1074
+
1075
+ Field policy is the second gate after `tableAccess`. It narrows which fields
1076
+ of a granted table a profile may read, filter on, return and write; it never
1077
+ denies a table the profile grants. A profile with no field policy may read and
1078
+ write every field of a granted table, except that sensitive-looking names
1079
+ (`password`, `token`, `secret`, `api_key` and similar) are always denied, and
1080
+ the class and domain fields below must be listed before they can be written.
1081
+ Fields of type `password`, `password2`, `masked` or `encrypted_text` are denied
1082
+ the same way, whatever their name, and a `sys_properties` value shows only for
1083
+ a known non-secret `type`. The types come from a cached `sys_dictionary` read,
1084
+ so the integration user needs read access to `sys_dictionary` and
1085
+ `sys_db_object`; without it the tools refuse, unless the profile sets
1086
+ `"fieldTypes": { "dictionary": "not_required" }` to hide by name only (see
1087
+ [Production security](docs/PRODUCTION-SECURITY.md#password-type-fields)).
1088
+
1089
+ State it on a profile in `~/.servicenow-mcp/config.json`, beside
1090
+ `tableAccess`, in one of two forms. A profile that states both fails to load.
1091
+ For the `SN_PROFILE_NAME` environment profile, `SN_FIELD_POLICY_DEFINITIONS`
1092
+ supplies the same keys.
1093
+
1094
+ **`fieldPolicy`** maps a table name, or `"*"`, to an entry with up to three
1095
+ keys:
1096
+
1097
+ | Key | What it limits | When the entry leaves it out |
1098
+ |---|---|---|
1099
+ | `readable` | Fields a call may read, return, or filter on | The `"*"` entry's `readable` where that entry applies (below); otherwise every field |
1100
+ | `writable` | Fields a write may set | The `"*"` entry's `writable` where that entry applies; otherwise every field |
1101
+ | `defaults` | Fields a read returns when the caller names none | A bounded projection inside `readable`: a built-in table's own projection; on other tables the `"*"` entry's `defaults`, or `sys_id` |
1102
+
1103
+ **`readableTableFields` / `writableTableFields`** are lists of
1104
+ `{ "table": ..., "fields": ... }` entries that set `readable` and `writable`.
1105
+ They have no `defaults`. A table may appear once in each list.
1106
+
1107
+ Every field set is a list of exact field names, or `"*"` for every field.
1108
+ `["*"]` means the same as `"*"`, in that exact form only: `["*", "number"]`,
1109
+ `[" * "]` and patterns such as `"u_*"` are rejected. Table and field names are
1110
+ letters, digits and underscores, start with a letter, are at most 80
1111
+ characters, and are compared case-insensitively. `defaults` must stay inside
1112
+ `readable`. On a table with no built-in entry, an entry that lists
1113
+ `readable` but no `defaults` returns that whole list by default, and an entry
1114
+ that states only `defaults` also limits `readable` to those fields unless a
1115
+ `"*"` entry states `readable`.
1116
+
1117
+ A worked example, added to a profile beside `tableAccess`:
1118
+
1119
+ ```json
1120
+ {
1121
+ "fieldPolicy": {
1122
+ "*": {
1123
+ "writable": ["short_description", "description", "state", "work_notes"]
1124
+ },
1125
+ "incident": {
1126
+ "writable": ["short_description", "description", "state", "assigned_to", "assignment_group", "work_notes"]
1127
+ },
1128
+ "u_integration_log": {
1129
+ "readable": [],
1130
+ "writable": "*"
1131
+ },
1132
+ "sys_user": {
1133
+ "readable": ["sys_id", "user_name", "name", "email"],
1134
+ "writable": []
1135
+ }
1136
+ }
1137
+ }
1138
+ ```
1139
+
1140
+ On that profile, for the tables its `tableAccess` grants:
1141
+
1142
+ - Every ITSM table except `incident`, and every table without a built-in
1143
+ entry except `u_integration_log`, can be written only in the four fields of
1144
+ the `"*"` entry. `comments` is not listed, so no customer-visible comment
1145
+ can be posted there. The `"*"` entry states no `readable`, so reads stay
1146
+ open.
1147
+ - `incident` states its own `writable`, which replaces the `"*"` list for
1148
+ `incident` only. `sn_incident_add_comment` is denied there, because
1149
+ `comments` is not listed, and `sn_incident_add_work_note` is allowed.
1150
+ - `u_integration_log` is write-only. Any field except sensitive names and the
1151
+ class and domain fields can be written, and a write returns only `sys_id`.
1152
+ Reads are denied, so `sn_batch`, which reads the matching `sys_id`s first,
1153
+ cannot run there.
1154
+ - `sys_user` is a system table, so the `"*"` entry does not reach it, and
1155
+ naming it is the only way to narrow it. Here it can read four fields and
1156
+ cannot be written. Other system tables, such as `sys_script`, are not
1157
+ narrowed by this policy at all.
1158
+
1159
+ The same policy in the list form:
1160
+
1161
+ ```json
1162
+ {
1163
+ "readableTableFields": [
1164
+ { "table": "u_integration_log", "fields": [] },
1165
+ { "table": "sys_user", "fields": ["sys_id", "user_name", "name", "email"] }
1166
+ ],
1167
+ "writableTableFields": [
1168
+ { "table": "*", "fields": ["short_description", "description", "state", "work_notes"] },
1169
+ { "table": "incident", "fields": ["short_description", "description", "state", "assigned_to", "assignment_group", "work_notes"] },
1170
+ { "table": "u_integration_log", "fields": "*" },
1171
+ { "table": "sys_user", "fields": [] }
1172
+ ]
1173
+ }
1174
+ ```
1175
+
1176
+ **Which tables a `"*"` entry reaches.** Tables fall into four groups:
1177
+
1178
+ - **ITSM tables:** `incident`, `change_request`, `problem`, `sc_request`,
1179
+ `sc_req_item`, `sc_task`, `task`, `cmdb_ci`, `cmdb_ci_server`,
1180
+ `cmdb_ci_computer`, `kb_knowledge`.
1181
+ - **Every table without a built-in entry:** `u_*` and `x_*` tables, and
1182
+ platform tables such as `change_task` and `sys_properties`.
1183
+ - **The 23 system tables:** `sys_script`, `sys_script_include`,
1184
+ `sys_script_client`, `sys_ui_script`, `sys_ws_operation`, `sys_user`,
1185
+ `sys_user_group`, `sys_user_grmember`, `sys_db_object`, `sys_app`,
1186
+ `sys_store_app`, `v_plugin`, `sys_atf_test`, `sys_atf_test_suite`,
1187
+ `sys_atf_test_suite_test`, `sys_atf_test_result`, `sys_atf_step`,
1188
+ `sys_element_mapping`, `sys_variable_value`, `sys_atf_test_suite_result`,
1189
+ `sys_atf_test_result_step`, `sys_atf_agent`, `syslog`.
1190
+ - **The 6 named-only tables:** `sys_audit`, `sys_journal_field`,
1191
+ `sys_history_line`, `sys_audit_delete`, `sys_attachment_doc`, `sys_email`. A
1192
+ `"*"` entry reaches them once the profile names them in `tableAccess` (below).
1193
+
1194
+ On an ITSM table or a table without a built-in entry, named in the policy or
1195
+ not, `readable` and `writable` each resolve from the table's own entry, then
1196
+ the `"*"` entry, then every field. To keep one key open on such a table under
1197
+ a narrowing `"*"` entry, state it on the table, such as
1198
+ `"u_x": { "writable": "*" }`. The ITSM tables keep their built-in default
1199
+ projections, trimmed to the effective `readable` set.
1200
+
1201
+ A `"*"` entry never reaches a system table, named or not: each key comes from
1202
+ the table's own entry, or else covers every field. The system tables include
1203
+ the script tables (`sys_script`, `sys_script_include`, `sys_script_client`,
1204
+ `sys_ui_script`, `sys_ws_operation`), whose records hold server- or
1205
+ client-side code, and the user and group tables (`sys_user`,
1206
+ `sys_user_group`, `sys_user_grmember`). Name a system table to narrow it, and
1207
+ grant it in `tableAccess` only deliberately.
1208
+
1209
+ **Six tables are granted by name.** A `"*"` entry in `readTables` or
1210
+ `writeTables` covers every other table, but not `sys_audit`, `sys_journal_field`,
1211
+ `sys_history_line`, `sys_audit_delete`, `sys_attachment_doc` or `sys_email`.
1212
+ Their rows hold the old and new values of other tables' fields, comments and
1213
+ work notes, the history built from them, deleted records, attachment content
1214
+ and email bodies. A profile reaches one only when `tableAccess` names it, for
1215
+ example
1216
+ `servicenow-mcp-setup grant --profile <profile> --read sys_audit --tools sn_query`.
1217
+ Without that, every tool refuses it, `sn_query`, `sn_get`, `sn_aggregate`,
1218
+ `sn_schema` and `sn_batch` included, with the usual table-access denial. A `relatedTables` list that reaches one of them under a
1219
+ `"*"` grant stops the profile loading, and the message names the table and says
1220
+ to grant it by name.
1221
+
1222
+ Once named, these tables follow the profile's field policy like an ITSM table:
1223
+ a `"*"` field entry narrows them, and an entry for the table narrows or widens
1224
+ them. A read that names no `fields` leaves out the value columns, which are asked
1225
+ for by name: `oldvalue` and `newvalue` for `sys_audit`; `value` for
1226
+ `sys_journal_field`; `old`, `new`, `old_value` and `new_value` for
1227
+ `sys_history_line`; `payload` for `sys_audit_delete`; `data` for
1228
+ `sys_attachment_doc`; and `body`, `body_text`, `subject`, `recipients`,
1229
+ `copied`, `blind_copied`, `reply_to`, `headers` and `error_string` for
1230
+ `sys_email`. `sn_attach` is unchanged: it uses the Attachment API, under the
1231
+ grants for `sys_attachment` and the record's table, and never reads
1232
+ `sys_attachment_doc`.
1233
+
1234
+ **A `"*"` write grant does not cover three ATF tables.** `sys_atf_step`,
1235
+ `sys_variable_value` and `sys_element_mapping` hold the step types, input values
1236
+ and pill mappings that `sn_atf_author` checks when it adds a step. Under a `"*"`
1237
+ write grant they are written by `sn_atf_author` only; `sn_create`, `sn_update`, `sn_delete`, `sn_batch` and
1238
+ attachment uploads reach them only when `tableAccess` names the table for write,
1239
+ with the usual table-access denial otherwise. Reads are
1240
+ unchanged. `sys_variable_value` and `sys_element_mapping` also hold other
1241
+ variables' values and mappings (catalog variables, for example), so a profile
1242
+ that writes those with the generic tools needs to name them.
1243
+
1244
+ **Database views and extension tables are not covered by the name list.** The
1245
+ six tables are matched by table name. A database view built over one of them (a
1246
+ `sys_db_view` that joins any of the six) has a different name, so a `"*"` grant
1247
+ reaches the view and, through it, the columns of the joined table. The same holds
1248
+ for a custom table that extends one of the six. Do not grant such a view or table
1249
+ unless you mean to expose those rows, and on a profile with a `"*"` grant ask
1250
+ your instance administrator to review database views first; a profile with an
1251
+ explicit table list never reaches a view it does not name. To have the loader
1252
+ check it, declare the view as a `view` target with every table it reads in
1253
+ `relatedTables`: the profile then fails to load unless it also names each of
1254
+ those tables (for a named-only table, by name).
1255
+
1256
+ **Read-only profiles.** A `"*"` entry with `writable: []` does not make a
1257
+ profile read-only, because it never reaches the system tables. To make a
1258
+ profile read-only, grant no writes: `tableAccess.writeTables: []`, or
1259
+ `SN_ALLOWED_WRITE_TABLES=''` for the environment profile.
1260
+
1261
+ **Class and domain fields.** `sys_class_name`, `sys_class_path`, `sys_domain`
1262
+ and `sys_domain_path` move a record to another class or domain, so no
1263
+ writable wildcard covers them, including the open default of a profile with
1264
+ no field policy. Each is written only where it is named in the table's
1265
+ `writable`, or in a `"*"` entry's `writable` on a table that entry reaches.
1266
+ Listing `sys_domain` does not list `sys_domain_path`, and the reverse.
1267
+ Otherwise the write is denied with:
1268
+
1269
+ ```text
1270
+ Write denied by policy: field "sys_domain" on "incident" changes the record's class or domain, so a writable wildcard never covers it. List it explicitly in fieldPolicy.incident.writable to allow this write.
1271
+ ```
1272
+
1273
+ **`readable: []` and `writable: []`.** `readable: []` makes a table
1274
+ write-only: writes succeed and return only `sys_id`, reads are denied, and
1275
+ `sn_batch` cannot run there. `writable: []` blocks writes. To make a table
1276
+ unreachable, leave it out of `tableAccess`. Every write response includes the
1277
+ written record's `sys_id`; every other field, `number` included, follows the
1278
+ readable set.
1279
+
1280
+ **Parent tables.** Field policy is evaluated against the table a call names.
1281
+ If a profile may write a parent table such as `task`, a write addressed to
1282
+ `task` is checked against `task`'s policy, whatever the class of the record.
1283
+ When you narrow a field such as `comments` on `incident`, narrow it on every
1284
+ write-granted parent table too, or do not grant writes on the parent. A
1285
+ `"*"` entry covers `incident` and `task` alike. The same holds for a platform
1286
+ table that stores journal entries directly, such as `sys_journal_field`: if a
1287
+ profile may write it, per-table narrowing on `incident` does not reach a
1288
+ write addressed to it, so either leave it out of the write grant or narrow
1289
+ with a `"*"` entry, which reaches it.
1290
+
1291
+ **Schema metadata.** `sn_schema` describes the fields the profile can read on
1292
+ the table it names. It needs `tableAccess` read on `sys_dictionary`,
1293
+ `sys_db_object`, `sys_documentation` and `sys_choice`, but a field policy on
1294
+ those metadata tables does not trim the labels, types, choices and help it
1295
+ returns for the readable fields. The exception is `inherited_from`, the
1296
+ ancestor table a field comes from: it appears only where the profile can read
1297
+ `super_class` on `sys_db_object`.
1298
+
1299
+ **Role and group-membership tables.** Nothing built in blocks
1300
+ `sys_user_role`, `sys_user_has_role`, `sys_group_has_role` or
1301
+ `sys_user_grmember`. This is deliberate: profile configuration alone decides,
1302
+ with `tableAccess` granting the table, field policy narrowing it, and the
1303
+ integration account's ServiceNow roles bounding what is left. Grant these
1304
+ tables only deliberately. `sys_user_grmember` is a system table; the other
1305
+ three have no built-in entry, so a `"*"` entry reaches them.
1306
+
1307
+ **Validation.** Field policy is checked when profiles load, and any error
1308
+ stops the server from starting. Table keys must be unique ignoring case, a
1309
+ table may appear once in each list, and a field may appear once in each set.
1310
+ Unknown keys are rejected, including comment keys such as `_comment`: a
1311
+ `fieldPolicy` entry accepts only `defaults`, `readable` and `writable`, and a
1312
+ list entry only `table` and `fields`. Every error and its message is listed in
1313
+ [Field-policy load errors](docs/V2-MIGRATION.md#field-policy-load-errors).
1314
+
1315
+ #### Journal fields
1316
+
1317
+ `comments` (customer-visible) and `work_notes` (internal) are written like any
1318
+ other field through `sn_create`, `sn_update` and `sn_batch`, on any table
1319
+ granted for writes: `incident`, `change_request`, `problem`, `sc_task`, custom
1320
+ task tables. A Table API write to a journal field appends one entry; it never
1321
+ edits or removes earlier entries. Each entry is 1-8,000 characters of
1322
+ non-blank text, at most 16,384 UTF-8 bytes, without control or format
1323
+ characters other than newline, carriage return and tab.
1324
+
1325
+ Field policy decides who may write them, and with no field policy every
1326
+ write-granted table accepts both. To keep a profile from posting
1327
+ customer-visible comments, set `writable` to an explicit list that leaves
1328
+ `comments` out: on each table, or on the `"*"` entry, and on write-granted
1329
+ parent tables such as `task` (see [Field policy](#field-policy)). On
1330
+ `incident` the same setting also denies `sn_incident_add_comment`, so both
1331
+ routes to the field agree. Leaving the dedicated tools off a target does not
1332
+ withhold journals from `sn_create`, `sn_update` or `sn_batch`.
1333
+
1334
+ The dedicated incident tools take exactly `profile`, incident `sys_id` and
1335
+ bounded `content`, and need write access to `incident`.
1336
+ `servicenow-mcp-setup grant --write incident` binds both to the incident
1337
+ target unless you pass `--tools`.
1338
+
1339
+ Journal handling is keyed by field name. Only `comments` and `work_notes` get
1340
+ the journal bounds and are never re-sent; a custom journal field gets the
1341
+ generic bounds. See
1342
+ [Production security boundaries](docs/PRODUCTION-SECURITY.md#journal-content).
1343
+
1344
+ #### Write values
1345
+
1346
+ A field approved by the field policy accepts:
1347
+
1348
+ - a string, a boolean, a safe integer, or a finite decimal such as `12.5`
1349
+ (not exponent forms such as `1e21`);
1350
+ - `""` or `null` to clear the field;
1351
+ - an array of scalars for a list field such as `watch_list`, sent as one
1352
+ comma-separated value, so no element may contain a comma;
1353
+ - a `{"value": ..., "display_value": ..., "link": ...}` object, the shape
1354
+ reads return with display values, which is written as its `value`.
1355
+
1356
+ Values cannot contain control or format characters (newline, carriage return
1357
+ and tab are allowed) and are bounded to 100,000 characters and 400,000 UTF-8
1358
+ bytes. On `incident`,
1359
+ `short_description`, `description`, `close_notes`, the reference fields
1360
+ `caller_id`, `assignment_group` and `assigned_to`, and the choice fields keep
1361
+ typed checks: a reference takes a 32-character `sys_id` or `""`, a choice
1362
+ cannot contain `^`, `=` or `,`, and `short_description` is required on create
1363
+ and cannot be cleared. Every other incident field gets the generic bounds.
1364
+
1365
+ #### Bulk writes
1366
+
1367
+ `sn_batch` sends confirmed updates and deletes through the ServiceNow REST
1368
+ Batch API (`/api/now/v1/batch`), up to 50 records per request and fewer when
1369
+ field values are large, so a request body stays under 4 MiB unless one
1370
+ record's fields alone exceed about 3 MiB of JSON; such a record is sent one
1371
+ per request. Each request gets its own 1 MiB response budget, so a run can reach the 10,000-record cap
1372
+ (`limit` defaults to 200). The lookup's `sys_id`s are de-duplicated, so each
1373
+ matched record is targeted once per run.
1374
+
1375
+ A batch request that may have reached the instance is never sent again:
1376
+
1377
+ - If the instance refuses a batch request outright (401, 403 or 404), nothing
1378
+ in it ran, so the run switches to one Table API call per record, for that
1379
+ batch and the rest. Batches already confirmed are not sent again.
1380
+ - A rate limit (429) stops the run. The remaining records are reported as not
1381
+ sent, with the `Retry-After` hint, because serial calls would only add load.
1382
+ - A record whose sub-request returns a server error (5xx or 408) is
1383
+ unconfirmed: it may have been changed, so it is reported and never retried,
1384
+ and the run continues.
1385
+ - The run stops, and reports the remaining records as not sent, when a batch
1386
+ request fails or its response cannot be read or matched to the records
1387
+ sent, when every serviced record in one batch returns a server error, or
1388
+ when more than 10 records in the run are unconfirmed.
1389
+
1390
+ The result's `message` says how many records were unconfirmed or not sent,
1391
+ and why a run stopped. Unconfirmed records count as neither processed nor
1392
+ failed; records not sent count as failed.
1393
+
1394
+ The serial fallback follows the HTTP client's retry rules. A journal write
1395
+ (`comments` or `work_notes`) is never re-sent on any path. An ordinary
1396
+ `PATCH` is retried up to twice after a 502, 503, 504 or connection error, the
1397
+ same rule `sn_update` follows. The fallback stops at the first record whose
1398
+ outcome it cannot confirm, at a 429, and at a 401.
1399
+
1400
+ **Re-running a batch appends again.** A journal-only update does not change
1401
+ which records the filter matches, so running the same `sn_batch` again
1402
+ appends another entry to every matched record, not only to the records
1403
+ reported as unconfirmed or not sent. Check the unconfirmed records and
1404
+ narrow the filter to the records still to do before you re-run it.
1405
+
1406
+ **Practical size per call.** Each batch request must finish within the
1407
+ profile's request timeout (`timeoutMs`, or `SN_TIMEOUT_MS`; 30 seconds by
1408
+ default), and its duration grows with the server-side time each record's
1409
+ business rules take. As a rough guide, at 50-100 ms per record a 50-record
1410
+ batch takes a few seconds; at about 600 ms per record a single batch can
1411
+ reach the timeout, and its records are then reported as unconfirmed and the
1412
+ run stops. Over stdio the server sets no overall deadline on a call; the
1413
+ dormant HTTP transport ends a call after 120 seconds by default, which at
1414
+ those rates is roughly 1,200-2,400 records. For tables with heavy business
1415
+ rules, use a lower `limit` and split the work across calls with narrower
1416
+ filters. While the fields being set come to less than about 62 KB of JSON,
1417
+ each batch holds 50 records, so journal fields alone never make a batch
1418
+ smaller.
943
1419
 
944
1420
  ### ServiceNow profiles
945
1421
 
@@ -1010,10 +1486,10 @@ exact `profile`; no prior call creates default, active, or switch-profile state.
1010
1486
  This server is designed for production use with multiple safety layers:
1011
1487
 
1012
1488
  - **Delete operations** require explicit `confirm: true`
1013
- - **Batch operations** run in dry-run mode by default — shows match count without making changes
1489
+ - **Batch operations** run in dry-run mode by default — shows the match count, a sample of up to 5 records and the fields it would write, without making changes (`confirm` re-runs the query and can match different records)
1014
1490
  - **Bulk operations** require `confirm: true` to leave dry-run mode
1015
1491
  - **Unclassified composition is denied** — `sn_nl` requires a complete typed access plan; ATF suite execution requires a separate explicit `atf.execute` grant
1016
- - **Table access is deny-by-default** with independent exact read/write allowlists and non-configurable sensitive-table denials
1492
+ - **Table access is deny-by-default** with independent exact read/write allowlists; sensitive field names are denied and no configuration can grant them
1017
1493
  - **User input is neutralized** before interpolation into encoded queries (`^` is stripped from filter values — ServiceNow's query syntax has no escape sequence)
1018
1494
 
1019
1495
  ---