@onlyflows/servicenow-mcp 1.0.0 → 2.0.0

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 (281) hide show
  1. package/.env.example +56 -0
  2. package/CHANGELOG.md +153 -0
  3. package/README.md +939 -101
  4. package/dist/auth.d.ts +88 -0
  5. package/dist/auth.d.ts.map +1 -0
  6. package/dist/auth.js +396 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/client.d.ts +111 -17
  9. package/dist/client.d.ts.map +1 -1
  10. package/dist/client.js +554 -79
  11. package/dist/client.js.map +1 -1
  12. package/dist/config.d.ts +41 -4
  13. package/dist/config.d.ts.map +1 -1
  14. package/dist/config.js +44 -34
  15. package/dist/config.js.map +1 -1
  16. package/dist/encoded-query-policy.d.ts +72 -0
  17. package/dist/encoded-query-policy.d.ts.map +1 -0
  18. package/dist/encoded-query-policy.js +409 -0
  19. package/dist/encoded-query-policy.js.map +1 -0
  20. package/dist/execution-context.d.ts +235 -0
  21. package/dist/execution-context.d.ts.map +1 -0
  22. package/dist/execution-context.js +439 -0
  23. package/dist/execution-context.js.map +1 -0
  24. package/dist/field-policy.d.ts +117 -0
  25. package/dist/field-policy.d.ts.map +1 -0
  26. package/dist/field-policy.js +1684 -0
  27. package/dist/field-policy.js.map +1 -0
  28. package/dist/http-auth.d.ts +131 -0
  29. package/dist/http-auth.d.ts.map +1 -0
  30. package/dist/http-auth.js +347 -0
  31. package/dist/http-auth.js.map +1 -0
  32. package/dist/http-entrypoint.d.ts +26 -0
  33. package/dist/http-entrypoint.d.ts.map +1 -0
  34. package/dist/http-entrypoint.js +255 -0
  35. package/dist/http-entrypoint.js.map +1 -0
  36. package/dist/http-observability.d.ts +147 -0
  37. package/dist/http-observability.d.ts.map +1 -0
  38. package/dist/http-observability.js +703 -0
  39. package/dist/http-observability.js.map +1 -0
  40. package/dist/http-request-policy.d.ts +72 -0
  41. package/dist/http-request-policy.d.ts.map +1 -0
  42. package/dist/http-request-policy.js +463 -0
  43. package/dist/http-request-policy.js.map +1 -0
  44. package/dist/http-request-signal.d.ts +12 -0
  45. package/dist/http-request-signal.d.ts.map +1 -0
  46. package/dist/http-request-signal.js +39 -0
  47. package/dist/http-request-signal.js.map +1 -0
  48. package/dist/http-runtime.d.ts +77 -0
  49. package/dist/http-runtime.d.ts.map +1 -0
  50. package/dist/http-runtime.js +1321 -0
  51. package/dist/http-runtime.js.map +1 -0
  52. package/dist/incident-journal-policy.d.ts +22 -0
  53. package/dist/incident-journal-policy.d.ts.map +1 -0
  54. package/dist/incident-journal-policy.js +115 -0
  55. package/dist/incident-journal-policy.js.map +1 -0
  56. package/dist/incident-write-policy.d.ts +20 -0
  57. package/dist/incident-write-policy.d.ts.map +1 -0
  58. package/dist/incident-write-policy.js +196 -0
  59. package/dist/incident-write-policy.js.map +1 -0
  60. package/dist/index.d.ts +14 -4
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +140 -36
  63. package/dist/index.js.map +1 -1
  64. package/dist/metadata-cache.d.ts +71 -0
  65. package/dist/metadata-cache.d.ts.map +1 -0
  66. package/dist/metadata-cache.js +397 -0
  67. package/dist/metadata-cache.js.map +1 -0
  68. package/dist/profile-admin.d.ts +64 -0
  69. package/dist/profile-admin.d.ts.map +1 -0
  70. package/dist/profile-admin.js +351 -0
  71. package/dist/profile-admin.js.map +1 -0
  72. package/dist/profile-credentials.d.ts +68 -0
  73. package/dist/profile-credentials.d.ts.map +1 -0
  74. package/dist/profile-credentials.js +329 -0
  75. package/dist/profile-credentials.js.map +1 -0
  76. package/dist/profile-manager.d.ts +187 -0
  77. package/dist/profile-manager.d.ts.map +1 -0
  78. package/dist/profile-manager.js +1026 -0
  79. package/dist/profile-manager.js.map +1 -0
  80. package/dist/record-identifier-policy.d.ts +39 -0
  81. package/dist/record-identifier-policy.d.ts.map +1 -0
  82. package/dist/record-identifier-policy.js +203 -0
  83. package/dist/record-identifier-policy.js.map +1 -0
  84. package/dist/runtime-environment.d.ts +23 -0
  85. package/dist/runtime-environment.d.ts.map +1 -0
  86. package/dist/runtime-environment.js +58 -0
  87. package/dist/runtime-environment.js.map +1 -0
  88. package/dist/server.d.ts +33 -0
  89. package/dist/server.d.ts.map +1 -0
  90. package/dist/server.js +73 -0
  91. package/dist/server.js.map +1 -0
  92. package/dist/servicenow-identifiers.d.ts +8 -0
  93. package/dist/servicenow-identifiers.d.ts.map +1 -0
  94. package/dist/servicenow-identifiers.js +22 -0
  95. package/dist/servicenow-identifiers.js.map +1 -0
  96. package/dist/setup-prompts.d.ts +7 -0
  97. package/dist/setup-prompts.d.ts.map +1 -0
  98. package/dist/setup-prompts.js +123 -0
  99. package/dist/setup-prompts.js.map +1 -0
  100. package/dist/setup.d.ts +109 -0
  101. package/dist/setup.d.ts.map +1 -0
  102. package/dist/setup.js +1903 -0
  103. package/dist/setup.js.map +1 -0
  104. package/dist/startup.d.ts +43 -0
  105. package/dist/startup.d.ts.map +1 -0
  106. package/dist/startup.js +75 -0
  107. package/dist/startup.js.map +1 -0
  108. package/dist/stdio-runtime.d.ts +106 -0
  109. package/dist/stdio-runtime.d.ts.map +1 -0
  110. package/dist/stdio-runtime.js +231 -0
  111. package/dist/stdio-runtime.js.map +1 -0
  112. package/dist/structured-query.d.ts +187 -0
  113. package/dist/structured-query.d.ts.map +1 -0
  114. package/dist/structured-query.js +503 -0
  115. package/dist/structured-query.js.map +1 -0
  116. package/dist/table-defaults.d.ts +28 -0
  117. package/dist/table-defaults.d.ts.map +1 -0
  118. package/dist/table-defaults.js +85 -0
  119. package/dist/table-defaults.js.map +1 -0
  120. package/dist/table-policy.d.ts +71 -0
  121. package/dist/table-policy.d.ts.map +1 -0
  122. package/dist/table-policy.js +290 -0
  123. package/dist/table-policy.js.map +1 -0
  124. package/dist/tool-error.d.ts +48 -0
  125. package/dist/tool-error.d.ts.map +1 -0
  126. package/dist/tool-error.js +139 -0
  127. package/dist/tool-error.js.map +1 -0
  128. package/dist/tool-table-access.d.ts +19 -0
  129. package/dist/tool-table-access.d.ts.map +1 -0
  130. package/dist/tool-table-access.js +388 -0
  131. package/dist/tool-table-access.js.map +1 -0
  132. package/dist/tools/aggregate.d.ts +22 -42
  133. package/dist/tools/aggregate.d.ts.map +1 -1
  134. package/dist/tools/aggregate.js +103 -47
  135. package/dist/tools/aggregate.js.map +1 -1
  136. package/dist/tools/all-fields-cap.d.ts +45 -0
  137. package/dist/tools/all-fields-cap.d.ts.map +1 -0
  138. package/dist/tools/all-fields-cap.js +151 -0
  139. package/dist/tools/all-fields-cap.js.map +1 -0
  140. package/dist/tools/atf.d.ts +21 -60
  141. package/dist/tools/atf.d.ts.map +1 -1
  142. package/dist/tools/atf.js +180 -116
  143. package/dist/tools/atf.js.map +1 -1
  144. package/dist/tools/attach.d.ts +31 -45
  145. package/dist/tools/attach.d.ts.map +1 -1
  146. package/dist/tools/attach.js +175 -137
  147. package/dist/tools/attach.js.map +1 -1
  148. package/dist/tools/batch.d.ts +78 -42
  149. package/dist/tools/batch.d.ts.map +1 -1
  150. package/dist/tools/batch.js +172 -68
  151. package/dist/tools/batch.js.map +1 -1
  152. package/dist/tools/catalog.d.ts +6 -0
  153. package/dist/tools/catalog.d.ts.map +1 -0
  154. package/dist/tools/catalog.js +203 -0
  155. package/dist/tools/catalog.js.map +1 -0
  156. package/dist/tools/codesearch.d.ts +14 -25
  157. package/dist/tools/codesearch.d.ts.map +1 -1
  158. package/dist/tools/codesearch.js +60 -48
  159. package/dist/tools/codesearch.js.map +1 -1
  160. package/dist/tools/create-module.d.ts +48 -0
  161. package/dist/tools/create-module.d.ts.map +1 -0
  162. package/dist/tools/create-module.js +94 -0
  163. package/dist/tools/create-module.js.map +1 -0
  164. package/dist/tools/create.d.ts +2 -38
  165. package/dist/tools/create.d.ts.map +1 -1
  166. package/dist/tools/create.js +9 -41
  167. package/dist/tools/create.js.map +1 -1
  168. package/dist/tools/delete.d.ts +13 -23
  169. package/dist/tools/delete.d.ts.map +1 -1
  170. package/dist/tools/delete.js +30 -33
  171. package/dist/tools/delete.js.map +1 -1
  172. package/dist/tools/discover.d.ts +15 -27
  173. package/dist/tools/discover.d.ts.map +1 -1
  174. package/dist/tools/discover.js +103 -60
  175. package/dist/tools/discover.js.map +1 -1
  176. package/dist/tools/get-module.d.ts +85 -0
  177. package/dist/tools/get-module.d.ts.map +1 -0
  178. package/dist/tools/get-module.js +221 -0
  179. package/dist/tools/get-module.js.map +1 -0
  180. package/dist/tools/get.d.ts +2 -51
  181. package/dist/tools/get.d.ts.map +1 -1
  182. package/dist/tools/get.js +9 -49
  183. package/dist/tools/get.js.map +1 -1
  184. package/dist/tools/handler-result.d.ts +14 -0
  185. package/dist/tools/handler-result.d.ts.map +1 -0
  186. package/dist/tools/handler-result.js +177 -0
  187. package/dist/tools/handler-result.js.map +1 -0
  188. package/dist/tools/health.d.ts +12 -15
  189. package/dist/tools/health.d.ts.map +1 -1
  190. package/dist/tools/health.js +55 -36
  191. package/dist/tools/health.js.map +1 -1
  192. package/dist/tools/incident-journal-module.d.ts +12 -0
  193. package/dist/tools/incident-journal-module.d.ts.map +1 -0
  194. package/dist/tools/incident-journal-module.js +61 -0
  195. package/dist/tools/incident-journal-module.js.map +1 -0
  196. package/dist/tools/incident-write-shared.d.ts +6 -0
  197. package/dist/tools/incident-write-shared.d.ts.map +1 -0
  198. package/dist/tools/incident-write-shared.js +64 -0
  199. package/dist/tools/incident-write-shared.js.map +1 -0
  200. package/dist/tools/index.d.ts +47 -36
  201. package/dist/tools/index.d.ts.map +1 -1
  202. package/dist/tools/index.js +795 -35
  203. package/dist/tools/index.js.map +1 -1
  204. package/dist/tools/nl.d.ts +10 -24
  205. package/dist/tools/nl.d.ts.map +1 -1
  206. package/dist/tools/nl.js +37 -147
  207. package/dist/tools/nl.js.map +1 -1
  208. package/dist/tools/profile.d.ts +37 -0
  209. package/dist/tools/profile.d.ts.map +1 -0
  210. package/dist/tools/profile.js +39 -0
  211. package/dist/tools/profile.js.map +1 -0
  212. package/dist/tools/query-module.d.ts +119 -0
  213. package/dist/tools/query-module.d.ts.map +1 -0
  214. package/dist/tools/query-module.js +324 -0
  215. package/dist/tools/query-module.js.map +1 -0
  216. package/dist/tools/query.d.ts +2 -72
  217. package/dist/tools/query.d.ts.map +1 -1
  218. package/dist/tools/query.js +8 -72
  219. package/dist/tools/query.js.map +1 -1
  220. package/dist/tools/relationships.d.ts +21 -42
  221. package/dist/tools/relationships.d.ts.map +1 -1
  222. package/dist/tools/relationships.js +70 -56
  223. package/dist/tools/relationships.js.map +1 -1
  224. package/dist/tools/result-envelope.d.ts +603 -0
  225. package/dist/tools/result-envelope.d.ts.map +1 -0
  226. package/dist/tools/result-envelope.js +767 -0
  227. package/dist/tools/result-envelope.js.map +1 -0
  228. package/dist/tools/schema-module.d.ts +64 -0
  229. package/dist/tools/schema-module.d.ts.map +1 -0
  230. package/dist/tools/schema-module.js +367 -0
  231. package/dist/tools/schema-module.js.map +1 -0
  232. package/dist/tools/schema.d.ts +2 -37
  233. package/dist/tools/schema.d.ts.map +1 -1
  234. package/dist/tools/schema.js +6 -57
  235. package/dist/tools/schema.js.map +1 -1
  236. package/dist/tools/script.d.ts +33 -27
  237. package/dist/tools/script.d.ts.map +1 -1
  238. package/dist/tools/script.js +43 -37
  239. package/dist/tools/script.js.map +1 -1
  240. package/dist/tools/syslog.d.ts +19 -46
  241. package/dist/tools/syslog.d.ts.map +1 -1
  242. package/dist/tools/syslog.js +101 -67
  243. package/dist/tools/syslog.js.map +1 -1
  244. package/dist/tools/tool-module.d.ts +143 -0
  245. package/dist/tools/tool-module.d.ts.map +1 -0
  246. package/dist/tools/tool-module.js +1095 -0
  247. package/dist/tools/tool-module.js.map +1 -0
  248. package/dist/tools/update-module.d.ts +51 -0
  249. package/dist/tools/update-module.d.ts.map +1 -0
  250. package/dist/tools/update-module.js +107 -0
  251. package/dist/tools/update-module.js.map +1 -0
  252. package/dist/tools/update.d.ts +2 -45
  253. package/dist/tools/update.d.ts.map +1 -1
  254. package/dist/tools/update.js +9 -41
  255. package/dist/tools/update.js.map +1 -1
  256. package/dist/utils.d.ts +68 -1
  257. package/dist/utils.d.ts.map +1 -1
  258. package/dist/utils.js +114 -16
  259. package/dist/utils.js.map +1 -1
  260. package/dist/version.d.ts +10 -0
  261. package/dist/version.d.ts.map +1 -0
  262. package/dist/version.js +13 -0
  263. package/dist/version.js.map +1 -0
  264. package/docs/ADDING-TOOLS.md +227 -0
  265. package/docs/CLIENT-SETUP.md +914 -0
  266. package/docs/CONTAINER-DEPLOYMENT.md +310 -0
  267. package/docs/CROSS-CLIENT-RELEASE-MATRIX.md +63 -0
  268. package/docs/ENTERPRISE-RELEASE-BOUNDARY.md +149 -0
  269. package/docs/OPERATIONS-RUNBOOK.md +383 -0
  270. package/docs/PRIVATE-CHATGPT-CONNECTIVITY.md +347 -0
  271. package/docs/PRODUCTION-SECURITY.md +368 -0
  272. package/docs/PROFILE-CREDENTIALS.md +126 -0
  273. package/docs/RELEASE-VALIDATION.md +140 -0
  274. package/docs/TESTING-OAUTH.md +101 -0
  275. package/docs/V2-MIGRATION.md +493 -0
  276. package/package.json +60 -13
  277. package/scripts/inspector.mjs +140 -0
  278. package/scripts/release-validate.mjs +201 -0
  279. package/scripts/smoke-test.mjs +274 -0
  280. package/tools/inspector/package-lock.json +3812 -0
  281. package/tools/inspector/package.json +12 -0
@@ -0,0 +1,914 @@
1
+ # V2 service and client setup
2
+
3
+ > [!IMPORTANT]
4
+ > **This document describes the dormant HTTP transport, not the shipped one.**
5
+ > The product exposes stdio only: an MCP client spawns `servicenow-mcp` and
6
+ > speaks JSON-RPC over that process's stdin and stdout. There is no endpoint to
7
+ > configure, no service to start, and no bearer token to set, and
8
+ > `servicenow-mcp-setup` registers every client that way. The HTTP runtime this
9
+ > document assumes still compiles and is still tested, but nothing on the CLI
10
+ > path reaches it — see
11
+ > [the dormant HTTP transport](ENTERPRISE-RELEASE-BOUNDARY.md#the-dormant-http-transport).
12
+ > Sections about profiles, credentials, table access, field policy, and tool
13
+ > behavior are transport-independent and remain accurate.
14
+
15
+ This is the shortest complete path from a clean install to two
16
+ provider-neutral clients using the same ServiceNow MCP V2 service. The server
17
+ exposes Streamable HTTP at `/mcp`; it does not expose stdio and it does not
18
+ select a default or active ServiceNow profile.
19
+
20
+ ## Quickstart: zero to a working connection
21
+
22
+ Two commands. Nothing here puts a secret in argv or shell history.
23
+
24
+ ```sh
25
+ npm install -g @onlyflows/servicenow-mcp
26
+ servicenow-mcp-setup
27
+ ```
28
+
29
+ Run bare on a terminal, `servicenow-mcp-setup` is a guided wizard. It
30
+ generates the local auth material, prompts for the instance and credential,
31
+ verifies that credential against the instance with one bounded authenticated
32
+ read, prompts for table access, writes the profile with its grant already
33
+ attached, and registers any supported client whose CLI is installed.
34
+
35
+ Three properties are worth knowing:
36
+
37
+ - **The credential is entered at a hidden prompt.** Never an argument, never
38
+ shell history, never echoed.
39
+ - **Nothing is written to the profile until the instance accepts the
40
+ credential.** A wrong password, a hibernating instance, or an abort leaves no
41
+ half-written profile behind.
42
+ - **The profile and its table-access rules are written together**, so there is
43
+ never a window in which a profile exists that denies every call.
44
+
45
+ Then start the service and verify end to end:
46
+
47
+ ```sh
48
+ set -a; source ~/.servicenow-mcp/server.env; set +a; servicenow-mcp &
49
+ servicenow-mcp-setup doctor --profile dev
50
+ ```
51
+
52
+ ### Scripted setup
53
+
54
+ Pass any flag, or run without a terminal, and the wizard steps aside for the
55
+ non-interactive behavior, so CI and provisioning are unaffected.
56
+ `--non-interactive` forces it explicitly. The equivalent scripted sequence:
57
+
58
+ ```sh
59
+ servicenow-mcp-setup --non-interactive --clients none --json
60
+
61
+ servicenow-mcp-profile create \
62
+ --name dev \
63
+ --instance https://yourinstance.service-now.com \
64
+ --auth-type oauth \
65
+ --client-id <non-secret-oauth-client-id> \
66
+ --source reference \
67
+ --provider env
68
+
69
+ servicenow-mcp-setup grant --profile dev --read incident,problem --write incident
70
+ ```
71
+
72
+ Note that the scripted path does **not** verify the credential against the
73
+ instance — only the wizard does. `doctor` cannot either: it resolves a
74
+ credential locally and exercises the MCP endpoint, but never asks ServiceNow
75
+ whether the credential is accepted. After a scripted setup, the first real
76
+ proof is an `sn_profile` call followed by a bounded `sn_query`.
77
+
78
+ `doctor` checks the Node version, file ownership and modes, profile
79
+ completeness, credential resolution, table-access rules, and the live endpoint,
80
+ and prints the exact remedy for anything it finds. It never prints a secret and
81
+ exits non-zero when a check fails.
82
+
83
+ ### What the bootstrap writes
84
+
85
+ | File | Mode | Contents |
86
+ |------|------|----------|
87
+ | `~/.servicenow-mcp/server.env` | `0600` | `MCP_OWNER_ID`, `MCP_CLIENT_ID`, `MCP_HOST`, `MCP_PORT`, `SN_PROFILE_ENCRYPTION_KEY` |
88
+
89
+ The directory is `0700`. Modes are re-applied on every run, so a file that was
90
+ loosened by hand is tightened again rather than silently receiving a fresh
91
+ encryption key at the wrong permissions.
92
+
93
+ The bootstrap writes no credential for the MCP endpoint, and no client-side
94
+ credential file. **The endpoint is unauthenticated by default**: any process on
95
+ this machine that can reach it gets whatever ServiceNow access your profiles
96
+ grant. See [Authentication is opt-in](#authentication-is-opt-in) below.
97
+ Releases before 2.0 also wrote `~/.servicenow-mcp/client.env` and
98
+ `~/.servicenow-mcp/client-headers.txt`; nothing reads them now, and you can
99
+ delete them.
100
+
101
+ `--force` regenerates the owner/client identifiers. It deliberately
102
+ does **not** regenerate `SN_PROFILE_ENCRYPTION_KEY`: that key decrypts every
103
+ AES-256-GCM envelope in `config.json`, and replacing it would make those
104
+ credentials permanently unreadable. `--rotate-encryption-key` exists for a
105
+ clean machine and is refused outright while a profile file is present.
106
+
107
+ If you install globally first, `servicenow-mcp setup` and
108
+ `servicenow-mcp-setup` run the same bootstrap. `npx @onlyflows/servicenow-mcp@latest setup`
109
+ works without a global install.
110
+
111
+ ### Authentication is opt-in
112
+
113
+ The service checks a bearer token only when `MCP_BEARER_TOKEN` is present in
114
+ its environment. `servicenow-mcp-setup` does not generate one, so a default
115
+ install serves every request that reaches it.
116
+
117
+ That is safe against a remote attacker and against a web page you visit: the
118
+ listener is on `127.0.0.1`, and the `Host`/`Origin` allowlists are fail-closed,
119
+ so a browser cannot drive it. It is not safe against other software running as
120
+ you. A shell script, a build tool, or a compromised dependency in any project
121
+ on the machine can call `/mcp` and read or write every table your profiles
122
+ allow, recorded under your own owner and client identifiers.
123
+
124
+ To require a token, generate one — 32 to 4096 characters from
125
+ `A-Za-z0-9._~+/-` with optional `=` padding:
126
+
127
+ ```sh
128
+ openssl rand -base64 33 | tr '+/' '-_'
129
+ ```
130
+
131
+ Add it to `~/.servicenow-mcp/server.env` as an `MCP_BEARER_TOKEN` line, in the
132
+ same single-quoted form as the values already there, and confirm the file is
133
+ still mode `0600`. Restart the service, then add this header to every client —
134
+ the per-client sections in
135
+ [MCP client configuration](#7-mcp-client-configuration) show where:
136
+
137
+ ```text
138
+ Authorization: Bearer <the MCP_BEARER_TOKEN value>
139
+ ```
140
+
141
+ An empty `MCP_BEARER_TOKEN=` is refused at startup rather than treated as
142
+ "off", so a half-finished change stops the service instead of quietly opening
143
+ the port. `servicenow-mcp-setup doctor` reports which mode you are in under the
144
+ `http authentication` check, and its `/mcp` handshake probe sends the token
145
+ from `server.env` when there is one.
146
+
147
+ ### Granting table access
148
+
149
+ The server denies every table until the selected profile carries explicit
150
+ rules. For a **file-backed profile** — anything created with
151
+ `servicenow-mcp-profile` — those rules live in the profile itself, and
152
+ `SN_ALLOWED_READ_TABLES` / `SN_ALLOWED_WRITE_TABLES` / `SN_TABLE_ACCESS_TARGETS`
153
+ in the environment **do not apply**. This is the single most common reason a
154
+ freshly installed server answers every call with a policy denial.
155
+
156
+ ```sh
157
+ # Reads on two tables, writes on one.
158
+ servicenow-mcp-setup grant --profile dev --read incident,problem --write incident
159
+
160
+ # Narrow the tools permitted on a target.
161
+ servicenow-mcp-setup grant --profile dev --read cmdb_ci --tools sn_query,sn_relationships
162
+
163
+ # A table that extends another must declare the tables it reaches. Related
164
+ # tables join the allowlist but get no target of their own, so a caller cannot
165
+ # address them directly.
166
+ servicenow-mcp-setup grant --profile dev --read change_request --related change_request=task
167
+
168
+ # Inspect the result without writing it.
169
+ servicenow-mcp-setup grant --profile dev --read incident --dry-run
170
+ ```
171
+
172
+ Grants are additive; `--replace` discards the existing rules instead. Every
173
+ grant is validated with the same loader the server uses at request time, so a
174
+ rejected policy fails at the CLI rather than at the first tool call. Default
175
+ tools are `sn_query,sn_get,sn_aggregate,sn_schema` for a read grant and those
176
+ plus `sn_create,sn_update` for a write grant — `sn_delete`, `sn_batch`, and
177
+ `sn_atf` are never granted implicitly and must be named with `--tools`.
178
+
179
+ `grant` refuses `*` and rejects anything that is not a valid table name. It
180
+ does **not** refuse any particular table: `tableAccess` is the sole table-level
181
+ authority, so a grant of `sys_script`, `sys_user_role`, or a credential table is
182
+ honored and bounded only by the integration account's ServiceNow roles. Grant
183
+ the narrowest set that does the job. A wildcard allowlist additionally skips
184
+ both the per-tool binding and the related-table closure check; configure one
185
+ deliberately in the profile file after reading `PRODUCTION-SECURITY.md`.
186
+
187
+ Restart the service after changing a profile.
188
+
189
+ ## 1. Configure and start the HTTP service
190
+
191
+ Use Node.js 20 or newer. Review `.env.example` as a configuration inventory,
192
+ but do not put protected values in it or another repository file. Its password,
193
+ client-secret, API-key, and encryption-key assignments are intentionally empty,
194
+ and `MCP_BEARER_TOKEN` is commented out because an empty value is rejected at
195
+ startup rather than meaning "unauthenticated". Inject those values at process
196
+ start through the approved supervisor, orchestrator, OS keychain, or secret
197
+ manager.
198
+
199
+ For the one-profile environment compatibility path, set the non-secret values
200
+ from `.env.example`, inject the authentication-specific ServiceNow secret (and
201
+ `MCP_BEARER_TOKEN` if you are protecting the endpoint), and keep the explicit
202
+ `SN_PROFILE_NAME=example-dev`
203
+ mapping. Bare `SN_*` connection values without `SN_PROFILE_NAME` create no
204
+ profile. This path is not the recommended way to maintain two profiles; use
205
+ the protected configuration workflow below for that.
206
+
207
+ Then build and start the same HTTP-only entrypoint used by the production
208
+ container:
209
+
210
+ ```sh
211
+ npm ci
212
+ npm run build
213
+ npm start
214
+ ```
215
+
216
+ The default endpoint is `http://127.0.0.1:3000/mcp`. `MCP_OWNER_ID` and
217
+ `MCP_CLIENT_ID` default to `local-owner` and `local-client`; `MCP_BEARER_TOKEN`
218
+ is optional, and startup fails closed when it is present but empty or otherwise
219
+ invalid. Without it the service logs a warning to stderr and serves
220
+ unauthenticated. `/health/live` and `/health/ready` are unauthenticated
221
+ lifecycle probes; they are not ServiceNow health checks and do not grant `/mcp`
222
+ access.
223
+
224
+ Keep a loopback listener for local use. Before any non-loopback deployment,
225
+ put the process behind the private ingress and operator-managed TLS boundary
226
+ in `PRODUCTION-SECURITY.md`, configure exact Host/Origin admission, and set
227
+ `MCP_BEARER_TOKEN`. Off loopback, an unauthenticated endpoint publishes your
228
+ ServiceNow access to the network. The process does not terminate TLS itself. On SIGINT
229
+ or SIGTERM it stops admission, flips readiness false, drains accepted requests
230
+ up to `MCP_SHUTDOWN_GRACE_MS`, then closes remaining MCP and HTTP resources.
231
+
232
+ ## 2. Create two isolated named profiles out of band
233
+
234
+ The serving MCP surface cannot create, activate, switch, rotate, or remove a
235
+ profile. Use the protected operator CLI. Do not place a credential, secret
236
+ reference, ciphertext, or encryption key in tool arguments or command-line
237
+ arguments.
238
+
239
+ The following creates a development OAuth profile whose protected prompt reads
240
+ the environment-secret reference name. The reference value itself is supplied
241
+ through the prompt or bounded standard input, not `argv`:
242
+
243
+ ```sh
244
+ servicenow-mcp-profile create \
245
+ --name dev \
246
+ --instance https://dev.service-now.com \
247
+ --auth-type oauth \
248
+ --client-id dev-non-secret-client-id \
249
+ --source reference \
250
+ --provider env
251
+ ```
252
+
253
+ At the protected prompt, enter the name of the supervisor-injected environment
254
+ secret for this profile. The stored entry is a structured `secret_ref`; the
255
+ referenced secret is resolved only when a call explicitly selects `dev`.
256
+
257
+ The following creates a separate basic-auth staging profile with an encrypted
258
+ credential. First inject `SN_PROFILE_ENCRYPTION_KEY` from the secret manager
259
+ into the CLI process. The key is exactly 32 random bytes encoded as base64 or
260
+ base64url and remains separate from the profile file, MCP bearer, and
261
+ ServiceNow credentials. Then run:
262
+
263
+ ```sh
264
+ servicenow-mcp-profile create \
265
+ --name staging \
266
+ --instance https://staging.service-now.com \
267
+ --auth-type basic \
268
+ --username staging.integration \
269
+ --source encrypted
270
+ ```
271
+
272
+ Enter the staging credential only at the non-echoed prompt or bounded standard
273
+ input. The resulting owner-only `~/.servicenow-mcp/config.json` contains the
274
+ two non-secret instance definitions plus a structured secret reference for
275
+ `dev` and a versioned encrypted envelope for `staging`. It contains neither
276
+ plaintext secret nor encryption key. The commands
277
+ `servicenow-mcp-profile inspect --name dev` and
278
+ `servicenow-mcp-profile inspect --name staging` report only safe metadata and
279
+ source kinds.
280
+
281
+ One process accepts one `SN_PROFILE_ENCRYPTION_KEY` for encrypted envelopes in
282
+ its profile file. That key must be dedicated to this deployment and separated
283
+ from all bearer and ServiceNow secrets. If two profiles require independent
284
+ encryption-key trust domains, operate them as separate private service
285
+ deployments with separate profile files, keys, bearer credentials, and network
286
+ policy; do not weaken the single process key boundary.
287
+
288
+ ### Rotation, backup, and recovery
289
+
290
+ Rotate a referenced ServiceNow secret in its authoritative secret system,
291
+ update the reference through `servicenow-mcp-profile rotate` when the reference
292
+ name changes, roll the serving process, verify an explicit-profile bounded
293
+ read, and only then revoke the prior secret.
294
+
295
+ For an encryption-key rotation, prepare a protected working copy while the old
296
+ file/key pair remains active. Inject the new key only into the administration
297
+ job, re-enter and rotate every encrypted field in the working profile file,
298
+ then deploy the complete new file/key pair together. Verify both profiles
299
+ before retiring the old pair. Never serve a file containing a mixture of
300
+ envelopes that require different keys.
301
+
302
+ Back up only the owner-only encrypted/reference profile file and its
303
+ non-secret version metadata. Exclude plaintext values, environment dumps,
304
+ secret-manager exports, and the encryption key. Retain the matching key
305
+ version separately in the approved key system, with independent access and
306
+ retention controls. A backup without its approved key version or live secret
307
+ references is not a tested recovery point.
308
+
309
+ Recover into an isolated private environment: restore the file with owner-only
310
+ permissions, inject the matching key and resolver access separately, run safe
311
+ CLI inspection, start the service, and use the explicit `dev` and `staging`
312
+ calls below. Recovery is complete only when each selected profile performs its
313
+ own bounded read, the other profile's adapter is untouched, result/audit
314
+ bindings match, and no secret appears in output or logs. A missing/wrong key or
315
+ resolver failure must stop before ServiceNow client construction.
316
+
317
+ ## 3. Connect with the official MCP SDK
318
+
319
+ These two release-gate clients require an authenticated service, so run them
320
+ against a deployment with `MCP_BEARER_TOKEN` set. Inject it, set the non-secret
321
+ `MCP_URL` and `MCP_PROFILE`, and
322
+ run client code without placing any secret in a URL or command argument. Every
323
+ tool invocation includes the selected profile; initialization and discovery
324
+ naturally have no tool arguments.
325
+
326
+ ```ts
327
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
328
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
329
+
330
+ const endpoint = new URL(process.env.MCP_URL ?? "http://127.0.0.1:3000/mcp");
331
+ const bearer = process.env.MCP_BEARER_TOKEN;
332
+ const profile = process.env.MCP_PROFILE;
333
+ if (!bearer || !profile) throw new Error("injected client configuration missing");
334
+
335
+ const transport = new StreamableHTTPClientTransport(endpoint, {
336
+ requestInit: { headers: { authorization: `Bearer ${bearer}` } },
337
+ });
338
+ const client = new Client({ name: "official-sdk-example", version: "1.0.0" });
339
+ await client.connect(transport);
340
+ await client.listTools();
341
+ const result = await client.callTool({
342
+ name: "sn_query",
343
+ arguments: {
344
+ profile,
345
+ table: "incident",
346
+ fields: "sys_id,number,short_description",
347
+ limit: 5,
348
+ },
349
+ });
350
+ if (result.structuredContent?.profile !== profile) {
351
+ throw new Error("resolved profile mismatch");
352
+ }
353
+ await client.close();
354
+ ```
355
+
356
+ ## 4. Connect with independent Fetch JSON-RPC
357
+
358
+ This client uses the same `MCP_URL`, bearer injection, and `/mcp` artifact. It
359
+ initializes, sends the initialized notification, discovers the same tools, and
360
+ invokes a read with an explicit profile.
361
+
362
+ ```js
363
+ const endpoint = process.env.MCP_URL ?? "http://127.0.0.1:3000/mcp";
364
+ const bearer = process.env.MCP_BEARER_TOKEN;
365
+ const profile = process.env.MCP_PROFILE;
366
+ if (!bearer || !profile) throw new Error("injected client configuration missing");
367
+
368
+ let id = 0;
369
+ let protocolVersion;
370
+ const headers = () => ({
371
+ accept: "application/json, text/event-stream",
372
+ authorization: `Bearer ${bearer}`,
373
+ "content-type": "application/json",
374
+ ...(protocolVersion ? { "mcp-protocol-version": protocolVersion } : {}),
375
+ });
376
+ const rpc = async (method, params) => {
377
+ const response = await fetch(endpoint, {
378
+ method: "POST",
379
+ headers: headers(),
380
+ body: JSON.stringify({ jsonrpc: "2.0", id: ++id, method, params }),
381
+ });
382
+ const message = await response.json();
383
+ if (!response.ok || message.error) throw new Error("MCP request failed");
384
+ return message.result;
385
+ };
386
+
387
+ const initialized = await rpc("initialize", {
388
+ protocolVersion: "2025-06-18",
389
+ capabilities: {},
390
+ clientInfo: { name: "fetch-example", version: "1.0.0" },
391
+ });
392
+ protocolVersion = initialized.protocolVersion;
393
+ await fetch(endpoint, {
394
+ method: "POST",
395
+ headers: headers(),
396
+ body: JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }),
397
+ });
398
+ await rpc("tools/list", {});
399
+ const result = await rpc("tools/call", {
400
+ name: "sn_query",
401
+ arguments: {
402
+ profile,
403
+ table: "incident",
404
+ fields: "sys_id,number,short_description",
405
+ limit: 5,
406
+ },
407
+ });
408
+ if (result.structuredContent?.profile !== profile) {
409
+ throw new Error("resolved profile mismatch");
410
+ }
411
+ ```
412
+
413
+ The repository release gate runs these two client families against the same
414
+ runtime and immutable image. See `CROSS-CLIENT-RELEASE-MATRIX.md`.
415
+
416
+ ## 5. Profile selection, results, and audit evidence
417
+
418
+ All 19 tools require a non-empty `profile`. Missing, empty, unknown, or invalid
419
+ names fail before credentials or a ServiceNow client. There is no default,
420
+ active, current, selected-session, or switch-profile operation. To work across
421
+ instances, make separate calls and include the intended name each time:
422
+
423
+ ```ts
424
+ const devResult = await client.callTool({
425
+ name: "sn_query",
426
+ arguments: { profile: "dev", table: "incident", limit: 1 },
427
+ });
428
+ const stagingResult = await client.callTool({
429
+ name: "sn_query",
430
+ arguments: { profile: "staging", table: "incident", limit: 1 },
431
+ });
432
+ ```
433
+
434
+ Verify `devResult.structuredContent.profile === "dev"` and
435
+ `stagingResult.structuredContent.profile === "staging"`. Their corresponding
436
+ bounded audit events must carry the same profile names, canonical instance
437
+ bindings, outcome, and correlation IDs. Treat profile and instance as
438
+ restricted operational metadata. Never copy credentials, secret references,
439
+ request/result bodies, or raw audit streams into evidence.
440
+
441
+ ## 6. Restricted reads and controlled writes
442
+
443
+ Table access is deny-by-default. A table needs the correct read/write allowlist
444
+ entry and a complete target entry naming the exact tool. For a file-backed
445
+ profile that is the profile's own `tableAccess` object, written by
446
+ `servicenow-mcp-setup grant`; the `SN_ALLOWED_*_TABLES` and
447
+ `SN_TABLE_ACCESS_TARGETS` environment variables apply only to the
448
+ `SN_PROFILE_NAME` environment profile, and only when no profile file exists.
449
+ Structured filters are the normal query interface; raw encoded reads remain
450
+ denied unless an explicit bounded read-only rule authorizes one exact
451
+ tool/table pair.
452
+
453
+ `servicenow-mcp-setup doctor` reports a profile whose rules are missing or
454
+ whose allowlist names a table with no target entry, which is the failure that
455
+ otherwise surfaces only as a generic policy denial at call time.
456
+
457
+ ### Unrestricted field selection
458
+
459
+ `fields=all` and `response_format: "detailed"` resolve to a wildcard selection
460
+ and are bounded to at most **100 columns**, resolved from `sys_dictionary`
461
+ including fields inherited through `super_class`. Ordering is the table's
462
+ default projection first in declared order, then the remainder alphabetically.
463
+ `sn_query` reports truncation in its `hint` field; `sn_get` will carry the same
464
+ notice shortly. The cap bounds the upstream request rather than the response,
465
+ because a wide table previously breached the 1 MiB cumulative upstream limit and
466
+ failed the call outright.
467
+
468
+ Two consequences for callers:
469
+
470
+ - **Journal fields are returned.** `comments` and `work_notes` are in the
471
+ resolved set for `fields=all` and `detailed`, as they are for an explicit
472
+ `fields=comments` and for `sn_schema`. The default projection still excludes
473
+ them. Journal content on real instances routinely contains customer PII, so
474
+ asking for all fields on `incident` returns customer-visible commentary.
475
+ - **Sensitive-looking names are never requested.** A field whose name matches
476
+ the sensitive pattern is excluded from the resolved set rather than requested
477
+ and scrubbed on arrival, so the value does not cross the wire at all.
478
+
479
+ ### Metadata caching prerequisites
480
+
481
+ Caching is per instance *and* credential identity, and it requires a resolvable
482
+ session timezone: the freshness probe compares `sys_updated_on`, which
483
+ ServiceNow evaluates in the session user's timezone rather than UTC. Resolving
484
+ it needs the authenticating account's `user_name` to read `sys_user.time_zone`,
485
+ falling back to the `glide.sys.default.tz` property. The profile therefore needs
486
+ read access to `sys_user` and `sys_properties` for the lookup to work.
487
+
488
+ When the zone cannot be resolved, **caching is disabled for that identity**
489
+ rather than falling back to a UTC assumption — a wrong assumption would serve
490
+ silently stale metadata for the length of the offset. Because OAuth
491
+ client_credentials and API-key profiles carry no username, metadata caching is
492
+ disabled for them entirely. Basic auth and the OAuth password grant are
493
+ unaffected.
494
+
495
+ The practical cost is small and worth stating: the cache only ever saved payload
496
+ bytes, never round trips, since a hit still performs one freshness probe. The
497
+ loss on an affected profile is bandwidth on `sys_dictionary` reads, not latency.
498
+
499
+ Deletions to a cached metadata table become visible within one TTL — 24 hours by
500
+ default. The probe detects updates, not deletes, so a deleted row stays served
501
+ until its entry expires. Lower the TTL or pass `force_recache: true` when a
502
+ deletion must be reflected sooner.
503
+
504
+ Incident `comments` and `work_notes` are append-only. Generic `sn_update`
505
+ rejects them before credentials/client construction. After separate human
506
+ authorization on a disposable non-production incident, use a dedicated tool:
507
+
508
+ ```ts
509
+ const writeResult = await client.callTool({
510
+ name: "sn_incident_add_comment",
511
+ arguments: {
512
+ profile: "staging",
513
+ sys_id: "0123456789abcdef0123456789abcdef",
514
+ content: "Approved bounded validation comment",
515
+ },
516
+ });
517
+ ```
518
+
519
+ The staging policy must grant write access to `incident` and list
520
+ `sn_incident_add_comment` on its exact target. A repeated call appends again;
521
+ the operation is intentionally non-idempotent. Do not substitute a generic
522
+ journal update, production record, unrestricted query, batch, ATF execution,
523
+ or script.
524
+
525
+ ## 7. MCP client configuration
526
+
527
+ The official SDK and independent Fetch paths above are the portable release
528
+ contract. Everything in this section is optional client configuration around
529
+ the same endpoint. `servicenow-mcp-setup client --client <name>` prints any of
530
+ these blocks with your own endpoint substituted, and
531
+ `servicenow-mcp-setup client --client all` prints all of them.
532
+
533
+ Two rules apply to every client:
534
+
535
+ - **No block below sends a credential**, because the service does not check
536
+ one. If you have set `MCP_BEARER_TOKEN`, add the `Authorization` header shown
537
+ for your client and make the token reach it **by reference** — an environment
538
+ variable, a `0600` header file, or the client's own secret storage. Never
539
+ paste it into a config file that is synced or version-controlled, and never
540
+ pass it as a command-line argument, where any other user on the machine can
541
+ read it from the process list.
542
+ - Every tool call must name a `profile`. There is no default, active, or
543
+ remembered profile.
544
+
545
+ The bearer column applies only after you have opted into authentication.
546
+
547
+ | Client | Native Streamable HTTP | How to hold a bearer, if you set one |
548
+ |--------|------------------------|--------------------------------------|
549
+ | Claude Code | yes | `${VAR}` expansion in `.mcp.json`, resolved at load |
550
+ | Codex | yes | `--bearer-token-env-var`, name only in config |
551
+ | Cursor | yes (1.0+) | `${env:VAR}` expansion in `headers` |
552
+ | VS Code | yes | `${input:id}`, stored in VS Code secret storage |
553
+ | Claude Desktop | no (stdio only) | `mcp-remote --header-file` |
554
+ | Windsurf | no (stdio only) | `mcp-remote --header-file` |
555
+
556
+ ### Client behavior requirements
557
+
558
+ **Keep at most two tool calls in flight per server.** The runtime admits
559
+ `MCP_MAX_CONCURRENT_REQUESTS` concurrent `/mcp` requests, which defaults to
560
+ `2` and cannot safely be raised: startup refuses any value whose combined body
561
+ estimate exceeds the 512 MiB admission ceiling, so `MCP_MAX_CONCURRENT_REQUESTS=3`
562
+ makes the server fail to start rather than degrade. There is **no admission
563
+ queue**. A third simultaneous request is answered immediately with HTTP `503`
564
+ and `retry-after: 1`, and the official `StreamableHTTPClientTransport` does not
565
+ retry it — the model sees a hard tool error. An agent that fans out five
566
+ parallel tool calls will therefore get three failures and may summarize from
567
+ partial results.
568
+
569
+ Configure the client, or the agent driving it, to issue ServiceNow tool calls
570
+ sequentially, or to cap its own parallelism at two. If a client cannot be
571
+ constrained, put a queueing reverse proxy in front of `/mcp`.
572
+
573
+ **Raising the request body limit costs you concurrency — and it is not an
574
+ operator knob.** The admission guard at `src/http-runtime.ts:232-240` enforces
575
+
576
+ ```
577
+ concurrency × ((maxBodyBytes + 1 MiB) × 64 + 80 MiB) ≤ 512 MiB
578
+ ```
579
+
580
+ where the 64× and 8× factors are safety allowances for JSON heap expansion and
581
+ the raw-attachment budget. The two settings trade directly against each other:
582
+
583
+ | `maxBodyBytes` | Highest concurrency that starts | Effect |
584
+ |---|---|---|
585
+ | 1 MiB (shipped default) | 2 | 416 MiB budgeted; the intended configuration |
586
+ | 1.75 MiB | 2 | 512 MiB — exactly at the ceiling |
587
+ | **2 MiB** | **1** | **Single-flight: one request at a time, serialized** |
588
+ | 5.75 MiB | 1 | 512 MiB — the last value that starts at all |
589
+ | above 5.75 MiB | none | **Startup fails at any concurrency** |
590
+
591
+ Two failure modes are worth knowing before you touch either value:
592
+
593
+ - **At 2 MiB and above, the server is single-flight.** Concurrency 2 no longer
594
+ fits the ceiling, so the runtime can only start at concurrency 1, and every
595
+ tool call queues behind every other one. There is no warning and no log line —
596
+ it presents as "the server got slow", and one large upload blocks every other
597
+ tool for its duration. This is the more dangerous of the two, because nothing
598
+ connects the cause to the effect.
599
+ - **Above 5.75 MiB the server refuses to start.** This is a `throw` in the
600
+ constructor, not a clamp and not a warning. The message reads *"HTTP
601
+ maxConcurrentRequests and maxBodyBytes exceed the estimated body-memory
602
+ ceiling"* — it names the two settings but gives neither the ceiling, the
603
+ arithmetic, nor a working value, so on its own it offers no way forward. The
604
+ table above is that way forward.
605
+
606
+ **In the shipped `servicenow-mcp` executable, `maxBodyBytes` cannot be changed.**
607
+ `src/index.ts:167-170` builds the request policy with only `allowedHosts` and
608
+ `allowedOrigins`, so the limit is always the 1 MiB default and there is no
609
+ environment variable for it. The two thresholds above therefore bind anyone
610
+ embedding this package and calling `createHttpRuntime` directly, not an
611
+ operator running the binary. For an operator the only reachable version of this
612
+ failure is `MCP_MAX_CONCURRENT_REQUESTS=3`, which needs 624 MiB against the
613
+ 512 MiB ceiling and so refuses to start.
614
+
615
+ **A 10 MiB attachment is unreachable over HTTP at any concurrency.** Base64
616
+ inflates 10 MiB to about 13.33 MiB on the wire, which budgets roughly 997 MiB —
617
+ nearly double the ceiling even at concurrency 1. No combination of settings
618
+ gets there, so "just raise the body limit" is not a path. At the shipped 1 MiB
619
+ body the usable payload is about 768 KiB of raw file before JSON envelope
620
+ overhead. Send large files through ServiceNow's own UI or a separate integration.
621
+
622
+ **Honor `Retry-After` on both `429` and `503`.**
623
+
624
+ | Status | Meaning | Client action |
625
+ |--------|---------|---------------|
626
+ | `429` | Rate limited. Body is `{"error":"rate_limited","message":"…","retry_after_seconds":N}` and the `Retry-After` header carries the same bounded value. Two buckets apply: 240 requests/60 s per direct socket source and 120 requests/60 s per owner/client identity. | Wait `retry_after_seconds`, then retry the same request. |
627
+ | `503` | Admission slots are full, or the runtime is starting or draining. `retry-after: 1`, `connection: close`. | Wait, then retry with reduced parallelism. |
628
+ | `401` | Only reachable when the service runs with `MCP_BEARER_TOKEN` set: the bearer is missing, malformed, duplicated, or not the one the service is running with. An unauthenticated service never returns it. | Do not retry. Re-source the bearer, or confirm which mode the service is in with `servicenow-mcp-setup doctor`. |
629
+ | `421` | `Host` authority not in `MCP_ALLOWED_HOSTS`. | Do not retry. Fix the configured URL or the allowlist. |
630
+ | `403` | `Origin` rejected. `MCP_ALLOWED_ORIGINS` is unset by default, which denies every request carrying an `Origin`. | Do not retry. Add the exact origin, or send no `Origin`. |
631
+ | `413` | Body exceeded 1 MiB. | Do not retry unchanged. Reduce `limit`, narrow `fields`, or split the batch. |
632
+
633
+ Rate-limit state is process-local and resets on restart. Health probes are
634
+ exempt from the source bucket, so a saturated client cannot change liveness or
635
+ readiness.
636
+
637
+ ### Per-client configuration
638
+
639
+ Every block below preserves the same Streamable HTTP `/mcp` endpoint, tool
640
+ schemas, and explicit-profile rule, and each shows where the `Authorization`
641
+ header goes for a deployment that has opted into `MCP_BEARER_TOKEN`. They
642
+ must not redefine the core server, image, profile schema, policy, handler, or
643
+ result/audit contract.
644
+
645
+ #### ChatGPT developer-mode app through Secure MCP Tunnel
646
+
647
+ Use this path only when the private deployment and OpenAI organization/workspace
648
+ have been separately authorized. The current official OpenAI flow is:
649
+
650
+ 1. Create or select the tunnel in
651
+ [OpenAI Platform tunnel settings](https://platform.openai.com/settings/organization/tunnels)
652
+ and associate the target ChatGPT workspace.
653
+ 2. Run `tunnel-client` inside the private boundary using the secret-backed
654
+ profile in `PRIVATE-CHATGPT-CONNECTIVITY.md`. Its `main` channel points to
655
+ this service's unchanged `/mcp` origin and its static Authorization header
656
+ reads `env:MCP_BEARER_TOKEN`; the approved supervisor injects both the
657
+ control-plane credential and MCP bearer directly into that process.
658
+ 3. In [ChatGPT Plugins](https://chatgpt.com/plugins), use the plus button to
659
+ create a developer-mode app, choose **Tunnel** under **Connection**, and
660
+ select the associated tunnel. Do not enter a public MCP URL or a second
661
+ Authorization value in the app.
662
+ 4. Scan tools and compare the 19 names, schemas, and annotations with the
663
+ frozen release manifest. Keep the app private and draft-only.
664
+ 5. On every use, name the profile in the request. For example, instruct the
665
+ app to invoke `sn_query` with these exact non-secret arguments:
666
+
667
+ ```json
668
+ {
669
+ "profile": "staging",
670
+ "table": "incident",
671
+ "fields": "sys_id,number,short_description",
672
+ "limit": 5
673
+ }
674
+ ```
675
+
676
+ Confirm the approval surface shows `profile: "staging"` before allowing the
677
+ call, then verify the structured result and bounded audit event bind to the
678
+ same profile. No chat or previous invocation creates active-profile state.
679
+ Follow the complete authorization, validation, evidence, and teardown procedure
680
+ in `PRIVATE-CHATGPT-CONNECTIVITY.md`. The authoritative product flow is the
681
+ [OpenAI Secure MCP Tunnel guide](https://developers.openai.com/api/docs/guides/secure-mcp-tunnels).
682
+
683
+ #### Claude Code over Streamable HTTP
684
+
685
+ `servicenow-mcp-setup` registers Claude Code automatically when the `claude`
686
+ CLI is on `PATH`. To do it by hand:
687
+
688
+ ```sh
689
+ claude mcp add --transport http --scope user \
690
+ servicenow-mcp http://127.0.0.1:3000/mcp
691
+ ```
692
+
693
+ `--scope user` makes the server available in every project; use
694
+ `--scope project` to write a checked-in `.mcp.json` instead.
695
+
696
+ If you have set `MCP_BEARER_TOKEN`, export it to Claude Code's environment as
697
+ `SERVICENOW_MCP_BEARER_TOKEN` and add the header by reference:
698
+
699
+ ```sh
700
+ claude mcp add --transport http --scope user \
701
+ --header 'Authorization: Bearer ${SERVICENOW_MCP_BEARER_TOKEN}' \
702
+ servicenow-mcp http://127.0.0.1:3000/mcp
703
+ ```
704
+
705
+ The single quotes matter: the literal `${SERVICENOW_MCP_BEARER_TOKEN}` text is
706
+ what gets stored, and Claude Code expands it when the config loads. The token
707
+ therefore never enters argv, the config file, or shell history — which is what
708
+ makes `--scope project` safe with a header configured.
709
+
710
+ The equivalent `.mcp.json` entry:
711
+
712
+ ```json
713
+ {
714
+ "mcpServers": {
715
+ "servicenow-mcp": {
716
+ "type": "http",
717
+ "url": "${SERVICENOW_MCP_URL}",
718
+ "headers": {
719
+ "Authorization": "Bearer ${SERVICENOW_MCP_BEARER_TOKEN}"
720
+ }
721
+ }
722
+ }
723
+ }
724
+ ```
725
+
726
+ Omit the `headers` block entirely for an unauthenticated service; a placeholder
727
+ that expands to nothing is worse than no header at all.
728
+ `SERVICENOW_MCP_URL` must resolve to the same reviewed `/mcp` origin used by
729
+ the SDK and Fetch release checks — HTTPS for any non-loopback route. When a
730
+ referenced variable is absent, Claude Code
731
+ logs a warning and leaves the `${VAR}` placeholder unexpanded;
732
+ the MCP configuration still loads, but the server receives the literal
733
+ placeholder. Against an authenticated service that is an HTTP `401`; against an
734
+ unauthenticated one it is accepted and the mistake stays hidden until you turn
735
+ authentication on. Treat that warning, or a disconnected `/mcp` status, as a
736
+ failed setup.
737
+
738
+ Start a new session, run `/mcp` to confirm `servicenow-mcp` is connected, and
739
+ ask Claude to invoke one tool with the profile stated explicitly. The expected
740
+ arguments for the first bounded read are:
741
+
742
+ ```json
743
+ {
744
+ "profile": "dev",
745
+ "table": "incident",
746
+ "fields": "sys_id,number,short_description",
747
+ "limit": 5
748
+ }
749
+ ```
750
+
751
+ Verify `structuredContent.profile` and the matching audit event both say
752
+ `dev`. Repeat with `profile: "staging"` as a separate call when cross-instance
753
+ work is authorized; never ask Claude to remember or switch an active profile.
754
+ The current configuration shape and environment-expansion behavior are in the
755
+ [official Claude Code MCP documentation](https://code.claude.com/docs/en/mcp#environment-variable-expansion-in-mcpjson).
756
+
757
+ #### Codex
758
+
759
+ `servicenow-mcp-setup` registers Codex automatically when the `codex` CLI is on
760
+ `PATH`. By hand:
761
+
762
+ ```sh
763
+ codex mcp add servicenow-mcp --url http://127.0.0.1:3000/mcp
764
+ ```
765
+
766
+ With `MCP_BEARER_TOKEN` set, export it as `SERVICENOW_MCP_BEARER_TOKEN` and
767
+ add `--bearer-token-env-var SERVICENOW_MCP_BEARER_TOKEN`. Only the variable
768
+ *name* is written to Codex's config, so Codex must then be launched from an
769
+ environment where that variable is set — otherwise every call gets `401`.
770
+
771
+ #### Claude Desktop and Windsurf
772
+
773
+ Neither client speaks Streamable HTTP; both speak stdio. Bridge them with
774
+ `mcp-remote`:
775
+
776
+ ```json
777
+ {
778
+ "mcpServers": {
779
+ "servicenow-mcp": {
780
+ "command": "npx",
781
+ "args": [
782
+ "-y",
783
+ "mcp-remote",
784
+ "http://127.0.0.1:3000/mcp",
785
+ "--transport", "http-only",
786
+ "--allow-http"
787
+ ]
788
+ }
789
+ }
790
+ }
791
+ ```
792
+
793
+ With `MCP_BEARER_TOKEN` set, append
794
+ `"--header-file", "/Users/you/.servicenow-mcp/client-headers.txt"` and create
795
+ that file yourself with mode `0600` holding a single
796
+ `Authorization: Bearer <token>` line — `--header-file` keeps the token out of
797
+ argv and out of the config file. Setup no longer writes it, so use an absolute
798
+ path of your own; `~` is not expanded.
799
+ Drop `--allow-http` once the endpoint is HTTPS. Config file locations:
800
+
801
+ - Claude Desktop, macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
802
+ - Claude Desktop, Windows: `%APPDATA%\Claude\claude_desktop_config.json`
803
+ - Windsurf: `~/.codeium/windsurf/mcp_config.json`
804
+
805
+ Restart the application completely after editing. Claude Desktop's MCP logs are
806
+ at `~/Library/Logs/Claude/mcp*.log` on macOS and `%APPDATA%\Claude\logs` on
807
+ Windows.
808
+
809
+ #### Cursor
810
+
811
+ Cursor 1.0 and newer addresses the endpoint directly and expands `${env:VAR}`
812
+ in `headers`. Put this in `~/.cursor/mcp.json` (global) or `.cursor/mcp.json`
813
+ (per project):
814
+
815
+ ```json
816
+ {
817
+ "mcpServers": {
818
+ "servicenow-mcp": {
819
+ "url": "http://127.0.0.1:3000/mcp"
820
+ }
821
+ }
822
+ }
823
+ ```
824
+
825
+ With `MCP_BEARER_TOKEN` set, add
826
+ `"headers": { "Authorization": "Bearer ${env:SERVICENOW_MCP_BEARER_TOKEN}" }`
827
+ and export that variable into Cursor's environment. On an older Cursor, use the
828
+ `mcp-remote` bridge above instead.
829
+
830
+ #### VS Code
831
+
832
+ VS Code supports HTTP servers natively. Put this in `.vscode/mcp.json` for a
833
+ workspace, or the user-level `mcp.json`:
834
+
835
+ ```json
836
+ {
837
+ "servers": {
838
+ "servicenow-mcp": {
839
+ "type": "http",
840
+ "url": "http://127.0.0.1:3000/mcp"
841
+ }
842
+ }
843
+ }
844
+ ```
845
+
846
+ With `MCP_BEARER_TOKEN` set, add an `inputs` prompt so VS Code holds the token
847
+ in its own secret storage and the file stays safe to commit:
848
+
849
+ ```json
850
+ {
851
+ "inputs": [
852
+ {
853
+ "type": "promptString",
854
+ "id": "servicenow-mcp-bearer",
855
+ "description": "ServiceNow MCP bearer token",
856
+ "password": true
857
+ }
858
+ ],
859
+ "servers": {
860
+ "servicenow-mcp": {
861
+ "type": "http",
862
+ "url": "http://127.0.0.1:3000/mcp",
863
+ "headers": {
864
+ "Authorization": "Bearer ${input:servicenow-mcp-bearer}"
865
+ }
866
+ }
867
+ }
868
+ }
869
+ ```
870
+
871
+ VS Code prompts once and stores the value itself. Read the token from
872
+ `~/.servicenow-mcp/server.env` when it prompts.
873
+
874
+ #### Any other Streamable HTTP client
875
+
876
+ The contract is: `POST` to the `/mcp` URL, `accept: application/json,
877
+ text/event-stream`, `Authorization: Bearer <token>` where the service is
878
+ configured with `MCP_BEARER_TOKEN`, one JSON-RPC message per request
879
+ in a body of at most 1 MiB. There is no `GET`/SSE stream, no session id, and no
880
+ `DELETE`; any method other than `POST` returns `405`. Follow the client-behavior
881
+ requirements above.
882
+
883
+ No platform path is a prerequisite for another or for the core
884
+ official-SDK/Fetch gates. Removing any client configuration leaves the same
885
+ server artifact and endpoint working unchanged.
886
+
887
+ ## 8. Migrating clients and extending tools
888
+
889
+ Remove V1 client entries that launch a local command or pass executable
890
+ arguments. V2 has no stdio fallback; configure the Streamable
891
+ HTTP URL and migrate every tool call to an explicit profile as described in
892
+ `V2-MIGRATION.md`.
893
+
894
+ New tools must use the provider-neutral module contract in `ADDING-TOOLS.md`:
895
+ compose required-profile input and resolved-profile output, declare all
896
+ permissions/tables/APIs/field policies/capabilities and annotations, authorize
897
+ the complete access plan before client construction, use only injected safe
898
+ services, and extend both-client HTTP contract coverage. Do not register a tool
899
+ directly with the MCP SDK or import provider/tunnel code into a module.
900
+
901
+ ## Related operator guides
902
+
903
+ - `CONTAINER-DEPLOYMENT.md`: immutable image, runtime injection, health, and
904
+ least-privilege container execution.
905
+ - `OPERATIONS-RUNBOOK.md`: deployment, rollback, rotation, monitoring,
906
+ incident response, and recovery verification.
907
+ - `PRODUCTION-SECURITY.md`: TLS, proxy, Host/Origin, secret, network, and DNS
908
+ boundaries.
909
+ - `PROFILE-CREDENTIALS.md`: exact out-of-band CLI and storage contract.
910
+ - `TESTING-OAUTH.md`: opt-in sub-production OAuth validation.
911
+ - `V2-MIGRATION.md`: complete V1-to-V2 transport, profile, policy, attachment,
912
+ and incident-journal changes.
913
+ - `PRIVATE-CHATGPT-CONNECTIVITY.md`: optional provider adapter workflow.
914
+ - `CROSS-CLIENT-RELEASE-MATRIX.md`: release-blocking protocol evidence.