@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,255 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Dormant HTTP composition for @onlyflows/servicenow-mcp.
5
+ *
6
+ * **This is not the transport the product exposes.** stdio is — see
7
+ * `src/index.ts`. Nothing on the CLI path reaches this module: it is not a
8
+ * `bin` entry, `servicenow-mcp` never imports it, and setup never registers a
9
+ * client against a URL.
10
+ *
11
+ * It stays in the tree, compiling and under test, because a listening service
12
+ * is a planned enterprise deployment shape (shared host, reverse proxy, bearer
13
+ * or delegated identity) that is deliberately out of scope for the
14
+ * single-owner release. Deleting it would mean rebuilding the admission,
15
+ * rate-limiting, Host/Origin, and per-request-server work it already carries.
16
+ * See `docs/ENTERPRISE-RELEASE-BOUNDARY.md`.
17
+ *
18
+ * To re-expose it, give it its own `bin` entry in `package.json` pointing at
19
+ * `dist/http-entrypoint.js`, or dispatch to {@link runHttpService} from
20
+ * `src/index.ts` behind an explicit operator choice. Running this file
21
+ * directly starts it today, which is how its tests drive it.
22
+ *
23
+ * @module http-entrypoint
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.runHttpService = runHttpService;
27
+ const encoded_query_policy_js_1 = require("./encoded-query-policy.js");
28
+ const http_auth_js_1 = require("./http-auth.js");
29
+ const http_runtime_js_1 = require("./http-runtime.js");
30
+ const http_observability_js_1 = require("./http-observability.js");
31
+ const http_request_policy_js_1 = require("./http-request-policy.js");
32
+ const profile_manager_js_1 = require("./profile-manager.js");
33
+ const setup_prompts_js_1 = require("./setup-prompts.js");
34
+ const server_js_1 = require("./server.js");
35
+ const startup_js_1 = require("./startup.js");
36
+ const table_policy_js_1 = require("./table-policy.js");
37
+ const runtime_environment_js_1 = require("./runtime-environment.js");
38
+ const index_js_1 = require("./tools/index.js");
39
+ const version_js_1 = require("./version.js");
40
+ function createRestrictedPolicyProvider(profileManager, encodedQueryAccess) {
41
+ return Object.freeze({
42
+ resolve: ({ profile }) => {
43
+ const configuredProfile = profileManager.getProfile(profile.name);
44
+ const tableAccess = configuredProfile.tableAccess ?? Object.freeze({});
45
+ return Object.freeze({
46
+ id: `restricted-table-policy:${profile.name}`,
47
+ revision: "snsdk-32-v2-profile-scoped",
48
+ tableAccess: (0, table_policy_js_1.createTableAccessPolicy)(tableAccess),
49
+ // Only keys the profile actually states are materialized. A key
50
+ // present with an `undefined` value is not the same input as an
51
+ // absent key to consumers that branch on key presence.
52
+ fieldPolicy: {
53
+ ...(configuredProfile.fieldPolicy === undefined
54
+ ? {}
55
+ : { fieldPolicy: configuredProfile.fieldPolicy }),
56
+ ...(configuredProfile.readableTableFields === undefined
57
+ ? {}
58
+ : { readableTableFields: configuredProfile.readableTableFields }),
59
+ ...(configuredProfile.writableTableFields === undefined
60
+ ? {}
61
+ : { writableTableFields: configuredProfile.writableTableFields }),
62
+ },
63
+ encodedQueryAccess,
64
+ });
65
+ },
66
+ });
67
+ }
68
+ /**
69
+ * A startup failure caused by configuration, safe to show the operator.
70
+ *
71
+ * The entrypoint deliberately swallows unexpected startup errors so nothing
72
+ * from a credential path can reach the log. A misconfiguration is different:
73
+ * its message is authored here, contains no secret, and is useless unless the
74
+ * operator can read it. Only these are printed.
75
+ */
76
+ class ServiceConfigurationError extends Error {
77
+ name = "ServiceConfigurationError";
78
+ }
79
+ /**
80
+ * Loopback addresses, where "any process on this machine" is the whole reach.
81
+ *
82
+ * An unset host means the runtime's own loopback default, so absence is safe.
83
+ */
84
+ const LOOPBACK_HOSTS = new Set([
85
+ "127.0.0.1",
86
+ "localhost",
87
+ "::1",
88
+ "[::1]",
89
+ ]);
90
+ function isLoopbackHost(host) {
91
+ return host === undefined || LOOPBACK_HOSTS.has(host.trim().toLowerCase());
92
+ }
93
+ /**
94
+ * Select the HTTP authentication boundary.
95
+ *
96
+ * Authentication is opt-in. `MCP_BEARER_TOKEN` turns it on and the service then
97
+ * requires and verifies that token on every request. With the variable absent
98
+ * the service serves unauthenticated: any process on this machine that can
99
+ * reach the listening socket is admitted, and the `Host`/`Origin` allowlists,
100
+ * loopback binding, admission and rate limits, and the per-profile table policy
101
+ * are what remain. The warning below is deliberately loud and unconditional;
102
+ * this is a property of the deployment an operator must be able to see in the
103
+ * service log.
104
+ *
105
+ * Setting `MCP_BEARER_TOKEN` to the empty string is a configuration error
106
+ * rather than a way to disable authentication, so a half-applied env file fails
107
+ * to start instead of silently opening the port.
108
+ */
109
+ function createAuthenticationProvider() {
110
+ const identity = Object.freeze({
111
+ ownerId: (0, runtime_environment_js_1.optionalEnvironmentVariable)("MCP_OWNER_ID") ?? runtime_environment_js_1.DEFAULT_OWNER_ID,
112
+ clientId: (0, runtime_environment_js_1.optionalEnvironmentVariable)("MCP_CLIENT_ID") ?? runtime_environment_js_1.DEFAULT_CLIENT_ID,
113
+ });
114
+ const token = (0, runtime_environment_js_1.optionalEnvironmentVariable)("MCP_BEARER_TOKEN");
115
+ if (token === undefined) {
116
+ // Unauthenticated is a deliberate local convenience: on loopback the reach
117
+ // is this machine, which already holds the credential file. Off loopback it
118
+ // is a ServiceNow proxy open to the network, and the failure mode is a
119
+ // *working* deployment rather than a broken one, so refuse rather than warn.
120
+ // The container image sets MCP_HOST=0.0.0.0, which is exactly this case.
121
+ const host = (0, runtime_environment_js_1.optionalEnvironmentVariable)("MCP_HOST");
122
+ if (!isLoopbackHost(host)) {
123
+ throw new ServiceConfigurationError(`MCP_HOST is "${host}", which is not loopback, and MCP_BEARER_TOKEN is not set. ` +
124
+ "That would expose every table these profiles grant to anything that can " +
125
+ "reach the port, with no authentication. Set MCP_BEARER_TOKEN to a random " +
126
+ "value of 32 characters or more, or set MCP_HOST=127.0.0.1 to serve only " +
127
+ "this machine.");
128
+ }
129
+ process.stderr.write("[servicenow-mcp] WARNING: MCP_BEARER_TOKEN is not set, so this endpoint " +
130
+ "is UNAUTHENTICATED. Any process on this machine that can reach it may " +
131
+ "use every table these profiles grant. Host/Origin allowlists and the " +
132
+ "listening address are the only remaining boundary. Set " +
133
+ "MCP_BEARER_TOKEN to require a bearer token.\n");
134
+ return new http_auth_js_1.UnauthenticatedIdentityProvider(identity);
135
+ }
136
+ return new http_auth_js_1.StaticBearerAuthenticationProvider([{ token, ...identity }]);
137
+ }
138
+ /** Start the listening service. Reachable only by running this module. */
139
+ async function runHttpService() {
140
+ const authenticationProvider = createAuthenticationProvider();
141
+ const host = (0, runtime_environment_js_1.optionalEnvironmentVariable)("MCP_HOST");
142
+ const port = (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_PORT", 0, 65_535);
143
+ const maxConcurrentRequests = (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_MAX_CONCURRENT_REQUESTS", 1, 1_024);
144
+ const maxConnections = (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_MAX_CONNECTIONS", 1, http_runtime_js_1.MAX_HTTP_CONNECTIONS);
145
+ const gracePeriodMs = (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_SHUTDOWN_GRACE_MS", 1, 300_000) ??
146
+ startup_js_1.DEFAULT_SHUTDOWN_GRACE_PERIOD_MS;
147
+ const profileManager = new profile_manager_js_1.ProfileManager();
148
+ const effectivePolicyProvider = createRestrictedPolicyProvider(profileManager, (0, encoded_query_policy_js_1.encodedQueryAccessPolicyFromEnvironment)());
149
+ const httpObservability = (0, http_observability_js_1.createHttpObservability)({
150
+ sink: (0, http_observability_js_1.createBoundedJsonLinesEventSink)({
151
+ writeLine: (line) => process.stderr.write(line),
152
+ onDrain: (listener) => process.stderr.once("drain", listener),
153
+ maxPendingLines: 256,
154
+ }),
155
+ });
156
+ const httpRateLimiter = (0, http_observability_js_1.createHttpRateLimiter)({
157
+ preAuthentication: {
158
+ capacity: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_PRE_AUTH_RATE_CAPACITY", 1, http_observability_js_1.MAX_RATE_LIMIT_CAPACITY) ?? 240,
159
+ refillPeriodMs: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_PRE_AUTH_RATE_REFILL_MS", 1, http_observability_js_1.MAX_RATE_LIMIT_PERIOD_MS) ?? 60_000,
160
+ maxEntries: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_PRE_AUTH_RATE_MAX_ENTRIES", 1, http_observability_js_1.MAX_RATE_LIMIT_ENTRIES) ?? 4_096,
161
+ },
162
+ authenticatedIdentity: {
163
+ capacity: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_IDENTITY_RATE_CAPACITY", 1, http_observability_js_1.MAX_RATE_LIMIT_CAPACITY) ?? 120,
164
+ refillPeriodMs: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_IDENTITY_RATE_REFILL_MS", 1, http_observability_js_1.MAX_RATE_LIMIT_PERIOD_MS) ?? 60_000,
165
+ maxEntries: (0, runtime_environment_js_1.optionalIntegerEnvironmentVariable)("MCP_IDENTITY_RATE_MAX_ENTRIES", 1, http_observability_js_1.MAX_RATE_LIMIT_ENTRIES) ?? 128,
166
+ },
167
+ });
168
+ const readiness = (0, startup_js_1.createReadinessGate)();
169
+ const allowedHosts = (0, runtime_environment_js_1.optionalCommaSeparatedEnvironmentVariable)("MCP_ALLOWED_HOSTS");
170
+ const allowedOrigins = (0, runtime_environment_js_1.optionalCommaSeparatedEnvironmentVariable)("MCP_ALLOWED_ORIGINS");
171
+ const requestPolicy = (0, http_request_policy_js_1.createHttpRequestPolicy)({
172
+ ...(allowedHosts === undefined ? {} : { allowedHosts }),
173
+ ...(allowedOrigins === undefined ? {} : { allowedOrigins }),
174
+ });
175
+ const basicProfiles = profileManager.getBasicAuthProfileNames();
176
+ if (basicProfiles.length > 0) {
177
+ process.stderr.write(`[servicenow-mcp] WARNING: ${basicProfiles.length} configured profile(s) use ` +
178
+ `ServiceNow basic authentication, which is being phased out (KB3096078).\n`);
179
+ }
180
+ const runtime = (0, http_runtime_js_1.createHttpRuntime)({
181
+ ...(host === undefined ? {} : { host }),
182
+ ...(port === undefined ? {} : { port }),
183
+ ...(maxConcurrentRequests === undefined ? {} : { maxConcurrentRequests }),
184
+ ...(maxConnections === undefined ? {} : { maxConnections }),
185
+ authenticationProvider,
186
+ readinessCheck: readiness.check,
187
+ observability: httpObservability,
188
+ rateLimiter: httpRateLimiter,
189
+ requestPolicy,
190
+ createServer: (requestContext) => createApplicationServer(profileManager, requestContext, effectivePolicyProvider, httpObservability),
191
+ });
192
+ const shutdown = (0, startup_js_1.installShutdownCoordinator)({
193
+ runtime,
194
+ gracePeriodMs,
195
+ onComplete: (signal) => {
196
+ readiness.markNotReady();
197
+ process.stderr.write(`[servicenow-mcp] HTTP shutdown complete (${signal}).\n`);
198
+ process.exit(0);
199
+ },
200
+ onError: (signal) => {
201
+ readiness.markNotReady();
202
+ process.stderr.write(`[servicenow-mcp] HTTP shutdown failed (${signal}).\n`);
203
+ process.exit(1);
204
+ },
205
+ });
206
+ try {
207
+ const address = await runtime.start();
208
+ readiness.markReady();
209
+ process.stderr.write(`@onlyflows/servicenow-mcp v${version_js_1.VERSION} listening on ${address.url.href} -- ` +
210
+ `${index_js_1.REGISTERED_TOOL_COUNT} tools; explicit profile required\n`);
211
+ }
212
+ catch {
213
+ readiness.markNotReady();
214
+ shutdown.dispose();
215
+ await runtime.close({ gracePeriodMs: 0 }).catch(() => { });
216
+ throw new Error("HTTP service startup failed");
217
+ }
218
+ }
219
+ function createApplicationServer(profileManager, requestContext, effectivePolicyProvider, httpObservability) {
220
+ const executionContext = Object.freeze({
221
+ requestMetadataProvider: requestContext.requestMetadataProvider,
222
+ requestSignal: requestContext.signal,
223
+ effectivePolicyProvider,
224
+ auditSink: createHttpAuditSink(requestContext),
225
+ toolAuditObserver: Object.freeze({
226
+ begin: () => httpObservability.beginTool(),
227
+ }),
228
+ });
229
+ return (0, server_js_1.createMcpServer)({
230
+ dependencies: { profileManager, executionContext },
231
+ register: async (surface, dependencies) => {
232
+ (0, setup_prompts_js_1.registerSetupPrompts)(surface);
233
+ await (0, index_js_1.registerServiceNowTools)(surface, dependencies.profileManager, dependencies.executionContext);
234
+ },
235
+ });
236
+ }
237
+ function createHttpAuditSink(requestContext) {
238
+ return Object.freeze({
239
+ write(_record) {
240
+ requestContext.markToolAuditObserved();
241
+ },
242
+ writePreContext(_record) {
243
+ requestContext.markToolAuditObserved();
244
+ },
245
+ });
246
+ }
247
+ if (require.main === module) {
248
+ void runHttpService().catch((error) => {
249
+ process.stderr.write(error instanceof ServiceConfigurationError
250
+ ? `[servicenow-mcp] Refusing to start: ${error.message}\n`
251
+ : "[servicenow-mcp] Fatal HTTP service startup error.\n");
252
+ process.exitCode = 1;
253
+ });
254
+ }
255
+ //# sourceMappingURL=http-entrypoint.js.map
@@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AAE,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE;YACxC,IAAA,uCAAoB,EAAC,OAAO,CAAC,CAAC;YAC9B,MAAM,IAAA,kCAAuB,EAC3B,OAAO,EACP,YAAY,CAAC,cAAc,EAC3B,YAAY,CAAC,gBAAgB,CAC9B,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAC1B,cAA+C;IAE/C,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,KAAK,CAAC,OAAwB;YAC5B,cAAc,CAAC,qBAAqB,EAAE,CAAC;QACzC,CAAC;QACD,eAAe,CAAC,OAA8B;YAC5C,cAAc,CAAC,qBAAqB,EAAE,CAAC;QACzC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,KAAK,cAAc,EAAE,CAAC,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QAC7C,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,KAAK,YAAY,yBAAyB;YACxC,CAAC,CAAC,uCAAuC,KAAK,CAAC,OAAO,IAAI;YAC1D,CAAC,CAAC,sDAAsD,CAC3D,CAAC;QACF,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Bounded, provider-neutral HTTP observability and rate-limit primitives.
3
+ *
4
+ * The public event inputs deliberately contain no request headers, URL/query,
5
+ * body, exception, credential, or token field. Identity values are represented
6
+ * by one-way digests in emitted events and rate-limit keys are retained only as
7
+ * digests. This makes accidental serialization of the HTTP authentication or
8
+ * ServiceNow credential surfaces structurally unavailable here.
9
+ *
10
+ * @module http-observability
11
+ */
12
+ import type { OwnerClientIdentity, PreContextAuditRecord, ToolAuditRecord } from "./execution-context.js";
13
+ import { type ToolErrorCategory, type ToolErrorRetry } from "./tool-error.js";
14
+ declare const EVENT_SCHEMA_VERSION = 1;
15
+ export declare const MAX_RATE_LIMIT_CAPACITY = 1000000;
16
+ export declare const MAX_RATE_LIMIT_PERIOD_MS: number;
17
+ export declare const MAX_RATE_LIMIT_ENTRIES = 100000;
18
+ /** Injectable wall/monotonic clock. Tests can advance it deterministically. */
19
+ export interface HttpObservabilityClock {
20
+ now(): number;
21
+ }
22
+ /** Synchronous, bounded event destination. Delivery failures are isolated. */
23
+ export interface StructuredHttpEventSink {
24
+ write(event: StructuredHttpEvent): void;
25
+ }
26
+ export type HttpRequestOutcome = "success" | "rejected" | "error";
27
+ /** Finite request reasons; arbitrary exception or request text is impossible. */
28
+ export type HttpRequestReason = "not_found" | "method_not_allowed" | "unauthorized" | "forbidden" | "pre_auth_rate_limited" | "identity_rate_limited" | "invalid_content_type" | "invalid_protocol" | "malformed_request" | "request_too_large" | "request_timeout" | "client_disconnected" | "concurrency_limited" | "tool_input_rejected" | "service_unavailable" | "internal_error";
29
+ interface StructuredEventBase {
30
+ readonly schemaVersion: typeof EVENT_SCHEMA_VERSION;
31
+ readonly observedAtMs: number;
32
+ readonly latencyMs: number;
33
+ readonly correlationId: string | null;
34
+ /** SHA-256 pseudonyms, never raw configured identifiers. */
35
+ readonly ownerIdHash: string | null;
36
+ readonly clientIdHash: string | null;
37
+ }
38
+ /** Safe, bounded completion event for one HTTP request. */
39
+ export interface StructuredHttpRequestEvent extends StructuredEventBase {
40
+ readonly type: "http_request";
41
+ readonly outcome: HttpRequestOutcome;
42
+ readonly reason: HttpRequestReason | null;
43
+ readonly statusCode: number;
44
+ }
45
+ export type StructuredToolOutcome = ToolAuditRecord["outcome"] | PreContextAuditRecord["outcome"];
46
+ export type StructuredToolReason = ToolAuditRecord["reason"] | PreContextAuditRecord["reason"];
47
+ /** Safe, bounded completion event derived from an issued tool audit record. */
48
+ export interface StructuredHttpToolEvent extends StructuredEventBase {
49
+ readonly type: "mcp_tool";
50
+ readonly tool: string;
51
+ readonly profile: string | null;
52
+ readonly instance: string | null;
53
+ readonly outcome: StructuredToolOutcome;
54
+ readonly reason: StructuredToolReason;
55
+ readonly errorCategory: ToolErrorCategory | null;
56
+ readonly retry: ToolErrorRetry | null;
57
+ readonly retryAfterSeconds: number | null;
58
+ }
59
+ export type StructuredHttpEvent = StructuredHttpRequestEvent | StructuredHttpToolEvent;
60
+ export interface HttpRequestObservationCompletion {
61
+ readonly correlationId?: string;
62
+ readonly identity?: OwnerClientIdentity;
63
+ readonly outcome: HttpRequestOutcome;
64
+ readonly reason: HttpRequestReason | null;
65
+ readonly statusCode: number;
66
+ }
67
+ export interface HttpRequestObservation {
68
+ /** Emits at most once. Invalid/hostile inputs fail closed without throwing. */
69
+ finish(completion: HttpRequestObservationCompletion): StructuredHttpRequestEvent | undefined;
70
+ }
71
+ export interface HttpToolObservation {
72
+ /** Emits at most once. Invalid/hostile records fail closed without throwing. */
73
+ finish(record: ToolAuditRecord | PreContextAuditRecord): StructuredHttpToolEvent | undefined;
74
+ }
75
+ /**
76
+ * Request/tool span factory. Spans own their start time and emit exactly one
77
+ * deeply frozen event through the supplied non-blocking sink.
78
+ */
79
+ export interface HttpObservability {
80
+ beginRequest(): HttpRequestObservation;
81
+ beginTool(): HttpToolObservation;
82
+ }
83
+ export interface CreateHttpObservabilityOptions {
84
+ readonly sink: StructuredHttpEventSink;
85
+ readonly clock?: HttpObservabilityClock;
86
+ }
87
+ /** Create an observability boundary with deterministic, failure-isolated spans. */
88
+ export declare function createHttpObservability(options: CreateHttpObservabilityOptions): HttpObservability;
89
+ /** A small JSON-lines adapter; only structured events can enter this port. */
90
+ export declare function createJsonLinesEventSink(writeLine: (line: string) => unknown): StructuredHttpEventSink;
91
+ export interface BoundedJsonLinesEventSinkOptions {
92
+ readonly writeLine: (line: string) => boolean;
93
+ readonly onDrain: (listener: () => void) => void;
94
+ readonly maxPendingLines?: number;
95
+ }
96
+ /**
97
+ * Drop-aware nonblocking JSONL sink for streams such as stderr. Node already
98
+ * owns the line whose write returned false; later lines are retained only up
99
+ * to a fixed bound and excess volume is coalesced into one count record.
100
+ */
101
+ export declare function createBoundedJsonLinesEventSink(options: BoundedJsonLinesEventSinkOptions): StructuredHttpEventSink;
102
+ export interface TokenBucketRateLimitPolicy {
103
+ /** Maximum burst and tokens replenished during one refill period. */
104
+ readonly capacity: number;
105
+ readonly refillPeriodMs: number;
106
+ /** Hard bound on retained digested principals/sources. */
107
+ readonly maxEntries: number;
108
+ }
109
+ export interface CreateHttpRateLimiterOptions {
110
+ readonly preAuthentication: TokenBucketRateLimitPolicy;
111
+ readonly authenticatedIdentity: TokenBucketRateLimitPolicy;
112
+ readonly clock?: HttpObservabilityClock;
113
+ }
114
+ export type HttpRateLimitScope = "pre_auth_source" | "authenticated_identity";
115
+ export type HttpRateLimitRejectionReason = "rate_limited" | "key_capacity_exhausted" | "invalid_key" | "clock_unavailable";
116
+ export type HttpRateLimitDecision = {
117
+ readonly allowed: true;
118
+ readonly scope: HttpRateLimitScope;
119
+ readonly limit: number;
120
+ readonly remaining: number;
121
+ readonly reason: null;
122
+ readonly retryAfterSeconds: null;
123
+ } | {
124
+ readonly allowed: false;
125
+ readonly scope: HttpRateLimitScope;
126
+ readonly limit: number;
127
+ readonly remaining: 0;
128
+ readonly reason: HttpRateLimitRejectionReason;
129
+ readonly retryAfterSeconds: number;
130
+ };
131
+ export interface HttpRateLimiter {
132
+ /** Call before authentication; raw keys are digested and never retained. */
133
+ checkPreAuthentication(sourceKey: string): HttpRateLimitDecision;
134
+ /** Call after authentication; raw owner/client identifiers are never retained. */
135
+ checkAuthenticated(identity: OwnerClientIdentity): HttpRateLimitDecision;
136
+ }
137
+ /** Independent, bounded token buckets for pre-auth sources and identities. */
138
+ export declare function createHttpRateLimiter(options: CreateHttpRateLimiterOptions): HttpRateLimiter;
139
+ export interface SafeHttpRateLimitRejection {
140
+ readonly status: 429;
141
+ readonly headers: Readonly<Record<string, string>>;
142
+ readonly body: string;
143
+ }
144
+ /** Convert only an issued rejection into a generic HTTP 429 response. */
145
+ export declare function safeHttpRateLimitRejection(decision: HttpRateLimitDecision): SafeHttpRateLimitRejection;
146
+ export {};
147
+ //# sourceMappingURL=http-observability.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-observability.d.ts","sourceRoot":"","sources":["../src/http-observability.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AAEzB,QAAA,MAAM,oBAAoB,IAAI,CAAC;AAI/B,eAAO,MAAM,uBAAuB,UAAY,CAAC;AACjD,eAAO,MAAM,wBAAwB,QAAuB,CAAC;AAC7D,eAAO,MAAM,sBAAsB,SAAU,CAAC;AAO9C,+EAA+E;AAC/E,MAAM,WAAW,sBAAsB;IACrC,GAAG,IAAI,MAAM,CAAC;CACf;AAED,8EAA8E;AAC9E,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACzC;AAED,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG,UAAU,GAAG,OAAO,CAAC;AAElE,iFAAiF;AACjF,MAAM,MAAM,iBAAiB,GACzB,WAAW,GACX,oBAAoB,GACpB,cAAc,GACd,WAAW,GACX,uBAAuB,GACvB,uBAAuB,GACvB,sBAAsB,GACtB,kBAAkB,GAClB,mBAAmB,GACnB,mBAAmB,GACnB,iBAAiB,GACjB,qBAAqB,GACrB,qBAAqB,GACrB,qBAAqB,GACrB,qBAAqB,GACrB,gBAAgB,CAAC;AAErB,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,aAAa,EAAE,OAAO,oBAAoB,CAAC;IACpD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,a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