@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
package/dist/utils.js CHANGED
@@ -5,18 +5,47 @@
5
5
  * @module utils
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.MAX_RESPONSE_BYTES_MAX = exports.MAX_RESPONSE_BYTES_MIN = exports.MAX_RESPONSE_BYTES_DEFAULT = void 0;
8
9
  exports.ok = ok;
10
+ exports.stripEmpty = stripEmpty;
9
11
  exports.err = err;
10
12
  exports.formatError = formatError;
13
+ exports.withWarnings = withWarnings;
11
14
  exports.buildTableParams = buildTableParams;
15
+ exports.escapeQueryValue = escapeQueryValue;
12
16
  exports.truncate = truncate;
17
+ exports.serializedBytes = serializedBytes;
18
+ const encoded_query_policy_js_1 = require("./encoded-query-policy.js");
19
+ const tool_error_js_1 = require("./tool-error.js");
13
20
  /**
14
21
  * Format a successful tool result as MCP text content.
22
+ * Objects are serialized as compact JSON (no pretty-print indent).
15
23
  */
16
24
  function ok(data) {
17
- const text = typeof data === "string" ? data : JSON.stringify(data, null, 2);
25
+ const text = typeof data === "string" ? data : JSON.stringify(data);
18
26
  return { content: [{ type: "text", text }] };
19
27
  }
28
+ /**
29
+ * Deep-strip empty values from record payloads: removes object entries
30
+ * whose value is "" or null. Keeps false, 0, and empty arrays. Recurses
31
+ * into nested objects and arrays. ServiceNow records are full of empty
32
+ * strings -- stripping them cuts serialized size substantially.
33
+ */
34
+ function stripEmpty(value) {
35
+ if (Array.isArray(value)) {
36
+ return value.map((item) => stripEmpty(item));
37
+ }
38
+ if (value !== null && typeof value === "object") {
39
+ const out = {};
40
+ for (const [key, entry] of Object.entries(value)) {
41
+ if (entry === "" || entry === null)
42
+ continue;
43
+ out[key] = stripEmpty(entry);
44
+ }
45
+ return out;
46
+ }
47
+ return value;
48
+ }
20
49
  /**
21
50
  * Format an error tool result as MCP text content.
22
51
  */
@@ -24,29 +53,49 @@ function err(message) {
24
53
  return { content: [{ type: "text", text: `ERROR: ${message}` }], isError: true };
25
54
  }
26
55
  /**
27
- * Safely format a ServiceNow error for display.
56
+ * Convert an untrusted exception into a fixed, caller-safe failure category.
57
+ *
58
+ * Exception messages, details, causes, response bodies, URLs, headers, and
59
+ * stack text are deliberately ignored. Upstream libraries commonly embed
60
+ * credentials and query values in those fields, and incomplete regex
61
+ * redaction cannot make arbitrary text safe. Only module-private trusted
62
+ * provenance can retain a category; every other value becomes `internal`.
28
63
  */
29
64
  function formatError(error) {
30
- if (error && typeof error === "object") {
31
- const e = error;
32
- if (e.message) {
33
- let msg = String(e.message);
34
- if (e.detail)
35
- msg += `\nDetail: ${e.detail}`;
36
- if (e.status)
37
- msg += ` (HTTP ${e.status})`;
38
- return msg;
39
- }
65
+ if ((0, encoded_query_policy_js_1.isEncodedQueryPolicyError)(error)) {
66
+ return encoded_query_policy_js_1.ENCODED_QUERY_MIGRATION_MESSAGE;
67
+ }
68
+ return (0, tool_error_js_1.formatToolError)(error);
69
+ }
70
+ /**
71
+ * Attach a list of per-request failure warnings to a success payload.
72
+ *
73
+ * No-op when there are no warnings -- the success shape is unchanged.
74
+ * With warnings, plain objects gain a `warnings` key; arrays are wrapped
75
+ * as `{ results, warnings }` and scalars as `{ result, warnings }` since
76
+ * neither can carry extra keys. This lets tools that fan out over several
77
+ * sub-requests report partial failures (e.g. an ACL-denied table) instead
78
+ * of silently returning fewer results.
79
+ */
80
+ function withWarnings(data, warnings) {
81
+ if (warnings.length === 0)
82
+ return data;
83
+ if (Array.isArray(data))
84
+ return { results: data, warnings };
85
+ if (data !== null && typeof data === "object") {
86
+ return { ...data, warnings };
40
87
  }
41
- if (error instanceof Error)
42
- return error.message;
43
- return String(error);
88
+ return { result: data, warnings };
44
89
  }
45
90
  /**
46
91
  * Build a query parameter map for table API requests.
92
+ * Always excludes reference links (link+value objects are pure URL noise
93
+ * in tool output).
47
94
  */
48
95
  function buildTableParams(opts) {
49
- const params = {};
96
+ const params = {
97
+ sysparm_exclude_reference_link: "true",
98
+ };
50
99
  if (opts.limit !== undefined)
51
100
  params.sysparm_limit = String(opts.limit);
52
101
  if (opts.query)
@@ -59,8 +108,42 @@ function buildTableParams(opts) {
59
108
  params.sysparm_orderby = opts.orderby;
60
109
  if (opts.displayValue)
61
110
  params.sysparm_display_value = opts.displayValue;
111
+ if (opts.noCount)
112
+ params.sysparm_no_count = "true";
62
113
  return params;
63
114
  }
115
+ /**
116
+ * Neutralize encoded-query metacharacters in a user-supplied VALUE that
117
+ * is interpolated into a sysparm_query string.
118
+ *
119
+ * ServiceNow's encoded-query syntax has NO escape sequence: `^` always
120
+ * terminates the current condition, and `^OR` / `^NQ` / `^EQ` chain new
121
+ * ones, so a literal `^` inside a value cannot be represented at all.
122
+ * The only fail-closed strategy is to strip `^` before interpolation:
123
+ * a stripped value can no longer inject extra conditions (e.g. a ci_name
124
+ * of "x^ORactive=false" becomes the harmless literal "xORactive=false"),
125
+ * at the cost that field values genuinely containing `^` cannot be
126
+ * matched through the convenience filters -- a platform limitation, not
127
+ * a tool one.
128
+ *
129
+ * ServiceNow additionally EVALUATES a value that starts with
130
+ * "javascript:" server-side (the same mechanism the tools use
131
+ * deliberately, e.g. sys_created_on>=javascript:gs.minutesAgoStart()),
132
+ * so a leading javascript: prefix would let an interpolated value alter
133
+ * query semantics without any `^`. No legitimate literal field-value
134
+ * filter starts with it, so the prefix is stripped (repeatedly, to
135
+ * defeat javascript:javascript: nesting) -- also fail-closed.
136
+ *
137
+ * Raw `query` parameters that accept a full encoded query are
138
+ * intentionally passed through untouched.
139
+ */
140
+ function escapeQueryValue(value) {
141
+ let v = value.replace(/\^/g, "");
142
+ while (/^\s*javascript:/i.test(v)) {
143
+ v = v.replace(/^\s*javascript:/i, "");
144
+ }
145
+ return v;
146
+ }
64
147
  /**
65
148
  * Truncate a string if it exceeds maxLen, appending "...".
66
149
  */
@@ -69,4 +152,19 @@ function truncate(str, maxLen) {
69
152
  return str;
70
153
  return str.slice(0, maxLen) + "...";
71
154
  }
155
+ /**
156
+ * Bounds for the max_response_bytes guard shared by sn_query / sn_get.
157
+ * Referenced from both the hand-written JSON schemas and the zod schemas
158
+ * so the two cannot drift.
159
+ */
160
+ exports.MAX_RESPONSE_BYTES_DEFAULT = 100000;
161
+ exports.MAX_RESPONSE_BYTES_MIN = 1000;
162
+ exports.MAX_RESPONSE_BYTES_MAX = 1000000;
163
+ /**
164
+ * UTF-8 byte length of a value's compact-JSON serialization -- the exact
165
+ * size `ok()` would emit for it.
166
+ */
167
+ function serializedBytes(data) {
168
+ return Buffer.byteLength(JSON.stringify(data), "utf8");
169
+ }
72
170
  //# sourceMappingURL=utils.js.map
package/dist/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils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ChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,SAAgB,gBAAgB,CAAC,KAAa;IAC5C,IAAI,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjC,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAClC,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,MAAc;IAClD,IAAI,GAAG,CAAC,MAAM,IAAI,MAAM;QAAE,OAAO,GAAG,CAAC;IACrC,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACU,QAAA,0BAA0B,GAAG,MAAM,CAAC;AACpC,QAAA,sBAAsB,GAAG,IAAI,CAAC;AAC9B,QAAA,sBAAsB,GAAG,OAAO,CAAC;AAE9C;;;GAGG;AACH,SAAgB,eAAe,CAAC,IAAa;IAC3C,OAAO,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Single source of truth for the package version at runtime.
3
+ *
4
+ * Keep in sync with package.json "version" -- test/version.test.ts
5
+ * asserts the two match, so a release bump cannot silently drift.
6
+ *
7
+ * @module version
8
+ */
9
+ export declare const VERSION = "2.0.0";
10
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Single source of truth for the package version at runtime.
4
+ *
5
+ * Keep in sync with package.json "version" -- test/version.test.ts
6
+ * asserts the two match, so a release bump cannot silently drift.
7
+ *
8
+ * @module version
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.VERSION = void 0;
12
+ exports.VERSION = "2.0.0";
13
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEU,QAAA,OAAO,GAAG,OAAO,CAAC"}
@@ -0,0 +1,227 @@
1
+ # Adding ServiceNow MCP tools
2
+
3
+ `defineServiceNowToolModule` is the canonical extension contract. A tool is a
4
+ single provider-neutral module: MCP metadata and Zod schemas, explicit security
5
+ and ServiceNow dependencies, one access preflight, and a handler that receives
6
+ only profile-resolved runtime services. Do not register tools directly with the
7
+ MCP SDK.
8
+
9
+ ## Canonical module
10
+
11
+ `sn_schema` is the production reference module. Its complete implementation is
12
+ in `src/tools/schema-module.ts`; `src/tools/schema.ts` is only a compatibility
13
+ facade for existing source consumers. The excerpt below shows the contract
14
+ shape. Production modules live beside their domain implementation and are
15
+ added once to `allToolModules` in `src/tools/catalog.ts`.
16
+
17
+ ```ts
18
+ import { z } from "zod";
19
+
20
+ import {
21
+ filterSchemaEntries,
22
+ MAX_FIELDS_PER_OPERATION,
23
+ preparedReadableFields,
24
+ resolveReadableFields,
25
+ } from "../field-policy.js";
26
+ import { resolveToolTableAccess } from "../tool-table-access.js";
27
+ import { escapeQueryValue, ok } from "../utils.js";
28
+ import {
29
+ envelopeCompatibilityResult,
30
+ productionToolOutputSchemas,
31
+ } from "./result-envelope.js";
32
+ import {
33
+ defineServiceNowToolModule,
34
+ withRequiredProfile,
35
+ } from "./tool-module.js";
36
+
37
+ const inputSchema = withRequiredProfile(
38
+ z.object({
39
+ table: z.string(),
40
+ fields_only: z.boolean().default(false),
41
+ limit: z.number().int().min(1).max(500).default(500),
42
+ offset: z.number().int().min(0).max(10_000).default(0),
43
+ })
44
+ );
45
+
46
+ export const schemaToolModule = defineServiceNowToolModule({
47
+ runtime: "servicenow",
48
+ definition: {
49
+ name: "sn_schema",
50
+ description: "Get policy-approved field metadata for a ServiceNow table.",
51
+ annotations: {
52
+ title: "Get table schema",
53
+ readOnlyHint: true,
54
+ destructiveHint: false,
55
+ idempotentHint: true,
56
+ openWorldHint: true,
57
+ },
58
+ },
59
+ inputSchema,
60
+ outputSchema: productionToolOutputSchemas.sn_schema,
61
+ requirements: {
62
+ permissions: ["read"],
63
+ tables: {
64
+ kind: "dynamic",
65
+ names: ["sys_dictionary"],
66
+ description: "Policy-approved target plus dictionary metadata.",
67
+ },
68
+ apis: ["table"],
69
+ fieldPolicies: ["read"],
70
+ capabilities: ["metadata:schema"],
71
+ },
72
+ resolveAccess: (args, policy) =>
73
+ resolveToolTableAccess("sn_schema", args, policy.encodedQueryAccess),
74
+ handler: async (args, services) => {
75
+ const readableFields =
76
+ preparedReadableFields(args, args.table) ??
77
+ resolveReadableFields(args.table, { fields: "all" });
78
+ const response = await services.serviceNow.get(
79
+ "/api/now/table/sys_dictionary",
80
+ {
81
+ sysparm_query:
82
+ `name=${escapeQueryValue(args.table)}^internal_type!=collection` +
83
+ `^elementIN${readableFields.map(escapeQueryValue).join(",")}` +
84
+ "^ORDERBYelement^ORDERBYsys_id",
85
+ sysparm_fields:
86
+ "sys_id,element,column_label,internal_type,max_length,mandatory,reference",
87
+ sysparm_offset: "0",
88
+ sysparm_limit: String(MAX_FIELDS_PER_OPERATION + 1),
89
+ }
90
+ );
91
+ const safeRows = filterSchemaEntries(response.result, readableFields);
92
+ const page = safeRows.slice(args.offset, args.offset + args.limit);
93
+ return schemaEnvelopeResult(args, page, args.offset + page.length < safeRows.length);
94
+ },
95
+ });
96
+ ```
97
+
98
+ The real handler additionally escapes the table identifier, applies the issued
99
+ field-policy marker before and after the request, maps dictionary records to a
100
+ stable public shape, and converts upstream failures to safe errors. Its stable
101
+ ServiceNow order is `element, sys_id`; the public envelope describes the mapped
102
+ order as `field, sys_id`. The issued policy contains at most 32 exact field
103
+ names, so the handler pushes that bounded set into `elementIN`, fetches the
104
+ complete set once at upstream offset zero, filters it again, and applies public
105
+ `limit` and `offset` locally. Denied or ACL-hidden dictionary rows therefore
106
+ cannot consume a caller page and hide later approved fields. The local page
107
+ helper uses the shared envelope adapter, then records authoritative `has_more`
108
+ and `next_offset` from the complete filtered set.
109
+
110
+ For a smaller fixed-table tool, the same registration pattern can use a static
111
+ table declaration and a fixed access request:
112
+
113
+ ```ts
114
+ requirements: {
115
+ permissions: ["read"],
116
+ tables: { kind: "static", names: ["incident"] },
117
+ apis: ["table"],
118
+ fieldPolicies: ["read"],
119
+ capabilities: ["incident:read"],
120
+ },
121
+ resolveAccess: (args) => ({
122
+ args: Object.freeze(inputSchema.parse(args)),
123
+ requests: Object.freeze([
124
+ Object.freeze({ operation: "read" as const, table: "incident" }),
125
+ ]),
126
+ }),
127
+ ```
128
+
129
+ The handler intentionally does not add `profile`. The shared dispatcher adds
130
+ the canonical resolved name to `structuredContent` after a successful handler
131
+ return, then validates that enriched object against the module's strict output
132
+ schema before either raw JSON-RPC or an SDK client can receive it. Therefore the
133
+ declared output schema must include it through `withResolvedProfileOutput`, and
134
+ handlers must return every declared local field without undeclared extras.
135
+
136
+ Both composition helpers treat their source Zod objects as untrusted shape
137
+ containers. They snapshot a bounded plain data-field map once, validate that
138
+ the fields can be parsed, and rebuild a fresh contract-owned `z.object(...)`.
139
+ The top-level source object's prototype, bound methods, descriptors, and
140
+ identity are not used as proof of provenance and are not retained. Only the
141
+ normalized instances issued by these helpers may enter a module catalog.
142
+
143
+ Composition also hardens the complete reachable schema graph with cycle,
144
+ depth, node, property, and container-size bounds. Every nested Zod node gets a
145
+ contract-owned definition; object shapes and lazy targets are materialized
146
+ once; checks, arrays, plain objects, maps, sets, and regular expressions are
147
+ copied into parse-stable containers; Zod parse caches are initialized; and
148
+ schema definitions, methods, prototype behavior, and nodes are locked. Map,
149
+ set, and regular-expression mutation methods are disabled. References to an
150
+ older definition or collection therefore cannot change parsing or discovery.
151
+ Field schema nodes supplied to a composition helper become immutable and must
152
+ not be configured or reused for further schema construction afterward.
153
+
154
+ ## Contract checklist
155
+
156
+ Every module must declare all of the following:
157
+
158
+ - an `sn_*` name, non-empty description, and all five MCP annotation fields;
159
+ - input composed with `withRequiredProfile` and output composed with
160
+ `withResolvedProfileOutput`—local schemas cannot redefine `profile`;
161
+ - explicit read/write permissions;
162
+ - every ServiceNow API family (`table`, `aggregate`, `attachment`, or `atf`),
163
+ including an explicit empty list when none is used;
164
+ - read/write field-policy dependencies and at least one reviewable capability;
165
+ - an access resolver that canonicalizes inputs and returns the complete table
166
+ plan before client construction; and
167
+ - a handler using only the injected opaque ServiceNow operation facade, non-secret settings,
168
+ immutable execution context and resolved policy, and provider-neutral logger.
169
+
170
+ The contract rejects missing fields, duplicate dependency entries,
171
+ permission/annotation conflicts, invalid or unnormalized schemas, missing
172
+ shared profile schemas, and duplicate tool names. It does not claim that
173
+ JavaScript prototype inspection can prove where a source object was
174
+ constructed. `registerServiceNowToolModules` snapshots the issued catalog and
175
+ preflights every configuration against the official SDK before the first
176
+ target registration call, so a late mutation or bad catalog cannot partially
177
+ register.
178
+
179
+ Use `runtime: "context-only"` only for a client-free diagnostic such as
180
+ `sn_profile`. Context-only modules cannot declare ServiceNow tables or APIs and
181
+ never receive a ServiceNow operation facade or configuration.
182
+
183
+ ## Security and portability rules
184
+
185
+ - The access resolver is mandatory even when it returns an empty plan. A
186
+ dynamic/composed operation must fail closed if it cannot determine the full
187
+ plan before handler entry.
188
+ - Table declarations are review metadata; `resolveAccess` is the authoritative
189
+ invocation-specific authorization input. Declare both accurately.
190
+ - Never put credentials, credential references, or the full resolved
191
+ configuration in handler services. `settings` contains only the canonical
192
+ instance origin, display-value preference, and relationship-depth bound.
193
+ `serviceNow` is a frozen null-prototype facade of closure-bound operations;
194
+ it exposes neither the underlying client nor authentication/configuration
195
+ state.
196
+ - Do not import ChatGPT, Claude, OpenAI, Anthropic, tunnel, browser, or other
197
+ AI-client integration code into a tool module. MCP transport and client
198
+ compatibility remain outside the domain contract.
199
+ - Treat all ServiceNow content as untrusted. Apply field policy before requests
200
+ and after responses, keep output bounded, and return safe errors.
201
+ - A write needs write permission, accurate non-read-only annotations, bounded
202
+ scope, dedicated mutation tests, and a complete preflight before the first
203
+ side effect.
204
+
205
+ ## Required tests
206
+
207
+ Add evidence at three levels:
208
+
209
+ 1. Unit-test the schema, access plan, handler, error paths, output bounds, and
210
+ read/write behavior with fake injected services.
211
+ 2. Contract-test registration failures, discovery metadata, required profile,
212
+ output schema, resolved-profile envelope, and pre-handler rejection for a
213
+ missing or unknown profile.
214
+ 3. Extend `test/http-cross-client.test.ts` so both the official MCP SDK client
215
+ and independent Fetch JSON-RPC fixture discover and invoke the same module
216
+ over Streamable HTTP.
217
+
218
+ Run the focused module tests, then `npm run typecheck`, `npm run lint`,
219
+ `npm run build`, and `npm test`.
220
+
221
+ ## Registration performance evidence
222
+
223
+ `test/tool-module.test.ts` validates the complete 20-module production catalog
224
+ 2,000 times (40,000 module validations) under a one-second bound. This guards
225
+ against accidental network, credential, client, or other super-linear work in
226
+ startup preflight. The bound is deliberately much wider than local execution
227
+ for shared CI hosts.