servicenow-mcp-ai 1.1.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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +461 -0
  3. package/bin/servicenow-mcp-ai.cjs +20 -0
  4. package/build/api/aggregate.js +30 -0
  5. package/build/api/atf.js +110 -0
  6. package/build/api/attachment.js +104 -0
  7. package/build/api/batch.js +165 -0
  8. package/build/api/catalog.js +76 -0
  9. package/build/api/change.js +88 -0
  10. package/build/api/cmdb.js +75 -0
  11. package/build/api/codecheck.js +307 -0
  12. package/build/api/compare.js +305 -0
  13. package/build/api/diagnostics.js +42 -0
  14. package/build/api/diagrams.js +104 -0
  15. package/build/api/docs.js +154 -0
  16. package/build/api/email.js +33 -0
  17. package/build/api/flows.js +398 -0
  18. package/build/api/importset.js +23 -0
  19. package/build/api/knowledge.js +54 -0
  20. package/build/api/meta.js +114 -0
  21. package/build/api/plugin.js +81 -0
  22. package/build/api/scripts.js +332 -0
  23. package/build/api/shared.js +60 -0
  24. package/build/api/snapshot.js +248 -0
  25. package/build/api/table.js +136 -0
  26. package/build/core/auth.js +331 -0
  27. package/build/core/cache.js +19 -0
  28. package/build/core/config.js +268 -0
  29. package/build/core/errors.js +18 -0
  30. package/build/core/host.js +103 -0
  31. package/build/core/http.js +278 -0
  32. package/build/core/jwt.js +25 -0
  33. package/build/core/logging.js +42 -0
  34. package/build/core/mtls.js +51 -0
  35. package/build/core/oauth-login.js +139 -0
  36. package/build/core/pkce.js +27 -0
  37. package/build/core/policy.js +81 -0
  38. package/build/core/request-context.js +16 -0
  39. package/build/core/settings.js +126 -0
  40. package/build/index.js +103 -0
  41. package/build/mcp/context.js +13 -0
  42. package/build/mcp/define.js +57 -0
  43. package/build/mcp/prompts.js +97 -0
  44. package/build/mcp/registry.js +190 -0
  45. package/build/mcp/resources.js +157 -0
  46. package/build/mcp/result.js +107 -0
  47. package/build/mcp/status.js +55 -0
  48. package/build/tools/admin.js +230 -0
  49. package/build/tools/aggregate.js +69 -0
  50. package/build/tools/atf.js +91 -0
  51. package/build/tools/attachment.js +109 -0
  52. package/build/tools/batch.js +51 -0
  53. package/build/tools/catalog.js +88 -0
  54. package/build/tools/change.js +107 -0
  55. package/build/tools/cmdb.js +110 -0
  56. package/build/tools/codecheck.js +65 -0
  57. package/build/tools/docs.js +99 -0
  58. package/build/tools/email.js +59 -0
  59. package/build/tools/flows.js +89 -0
  60. package/build/tools/importset.js +44 -0
  61. package/build/tools/instance.js +69 -0
  62. package/build/tools/knowledge.js +53 -0
  63. package/build/tools/meta.js +39 -0
  64. package/build/tools/scripts.js +102 -0
  65. package/build/tools/table.js +139 -0
  66. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Baev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,461 @@
1
+ # servicenow-mcp-ai โ€” ServiceNow MCP Server
2
+
3
+ ๐Ÿ“– **[Documentation site โ†’](https://leasstatt.github.io/servicenow-mcp-ai/)**
4
+
5
+ A [Model Context Protocol](https://modelcontextprotocol.io) server that lets an
6
+ MCP client (VS Code, Claude Desktop, etc.) run commands against a **ServiceNow**
7
+ instance through its REST APIs โ€” Table, Aggregate, Attachment, Import Set, Batch
8
+ and CMDB, plus the Service Catalog, Change Management and Knowledge plugin APIs.
9
+ Credentials are kept in a local env file and can be updated at runtime through a tool.
10
+
11
+ **Contents:** [Features](#features) ยท [Requirements](#requirements) ยท
12
+ [Setup](#setup) ยท [Configure credentials](#configure-credentials) ยท
13
+ [Run / debug](#run--debug) ยท [Develop](#develop) ยท [Tools](#tools) ยท
14
+ [Resources](#resources) ยท [Prompts](#prompts) ยท
15
+ [Project structure](#project-structure) ยท [Security notes](#security-notes) ยท
16
+ [Project documentation](#project-documentation)
17
+
18
+ ## Features
19
+
20
+ - Full **Table API**: query, read, create, update and delete records on **any**
21
+ table, with encoded queries, field selection and pagination.
22
+ - Extra ServiceNow APIs: **Aggregate** (Stats), **Attachment**
23
+ (list/upload/download/delete), **Import Set**, **Batch** (many REST calls in a
24
+ single request), plus table/column **metadata** (`sys_db_object`,
25
+ `sys_dictionary`).
26
+ - Process & plugin APIs: **CMDB** (class-aware CI CRUD + meta via IRE),
27
+ **Service Catalog** (browse/order items), **Change Management** (typed
28
+ creation + conflict detection) and **Knowledge** (article search).
29
+ Plugin-scoped APIs report clearly when not active on the instance.
30
+ - **Script intelligence**: read and search the instance's own code (business
31
+ rules, script includes, client scripts, UI policies/actions, scheduled jobs,
32
+ transform/REST scripts, ACLs) and get a table's full automation picture โ€” all
33
+ read-only over the Table API.
34
+ - **Flow tracing & code checking** (Phase 8): deterministically trace what a
35
+ table operation runs (`flows` package โ€” business rules, flows, workflows and
36
+ notifications, in order, with a Mermaid flowchart), read Flow Designer flows
37
+ and run history, and lint scripts against a local rule set with an aggregate
38
+ code-health report (`codecheck`). Run ATF tests via the CI/CD API (`atf`,
39
+ opt-in, non-default โ€” the run tools execute on the instance).
40
+ - **Self-documentation**: a local Markdown knowledge base (read/write/search) plus
41
+ deterministic Mermaid generators (ER diagrams from references, record-lifecycle
42
+ flowcharts from business rules) so the server builds durable, reusable context.
43
+ - **Prompts**: ready-made workflows (incident triage, change impact analysis,
44
+ document a table) that orchestrate the tools.
45
+ - **Tool packages**: load only the tool groups you need via `SN_TOOL_PACKAGES`
46
+ (default profile `core`; `all` enables everything).
47
+ - **Basic** or **OAuth 2.0** authentication over HTTPS; the password/token is
48
+ never echoed back.
49
+ - Least-privilege controls: table allow/deny lists and a global read-only mode.
50
+ - Resilience: per-request timeout, retry with backoff and `Retry-After`, SSRF
51
+ guard, and a result-size guard.
52
+ - MCP **tool annotations** and **resources**, structured error payloads, and
53
+ structured logging on stderr.
54
+ - Credentials in an env file (project, `~/.config`, or `SN_ENV_FILE`), updatable
55
+ at runtime via `servicenow_set_credentials`.
56
+
57
+ ## Requirements
58
+
59
+ - Node.js 20+ (enforced: `engines` + a runtime guard with a clear message;
60
+ the project targets the version in `.nvmrc`).
61
+
62
+ ## Setup
63
+
64
+ From source (for development):
65
+
66
+ ```bash
67
+ npm install
68
+ npm run build
69
+ ```
70
+
71
+ Or run the published package directly, without cloning:
72
+
73
+ ```bash
74
+ npx servicenow-mcp-ai
75
+ ```
76
+
77
+ Register it with an MCP client (Claude Desktop, VS Code Chat, the Inspectorโ€ฆ) by
78
+ pointing the server command at `npx`:
79
+
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "servicenow": {
84
+ "command": "npx",
85
+ "args": ["-y", "servicenow-mcp-ai"]
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Credentials are read from `~/.config/servicenow-mcp-ai/.env` (or real environment
92
+ variables) โ€” see below.
93
+
94
+ ## Configure credentials
95
+
96
+ Credentials live in `.env` at the project root (git-ignored):
97
+
98
+ ```dotenv
99
+ SN_INSTANCE=your-instance.service-now.com
100
+ SN_USER=your.username@example.com
101
+ SN_PASSWORD=your-password
102
+ ```
103
+
104
+ `SN_INSTANCE` accepts `dev12345`, `dev12345.service-now.com` or a full `https://` URL.
105
+
106
+ You can also set or change them at runtime by calling the
107
+ `servicenow_set_credentials` tool โ€” the new values are written straight back to the env file.
108
+
109
+ The env file is resolved in this order: `SN_ENV_FILE`, then
110
+ `~/.config/servicenow-mcp-ai/.env` (XDG) if present, then the project-root `.env`.
111
+ A global/`npx` install therefore writes to your user config rather than into
112
+ `node_modules`. Real environment variables always take precedence over the file.
113
+
114
+ ### OAuth 2.1 (Authorization Code + PKCE) โ€” recommended
115
+
116
+ Register an **Authorization Code** OAuth API endpoint in ServiceNow with a
117
+ loopback redirect URL (e.g. `http://localhost:53682/callback`), set
118
+ `SN_OAUTH_CLIENT_ID` (and `SN_OAUTH_CLIENT_SECRET` for a confidential client),
119
+ then run the one-time interactive login:
120
+
121
+ ```bash
122
+ npx servicenow-mcp-ai login
123
+ ```
124
+
125
+ It opens the browser, you approve, and the obtained **refresh token** is stored
126
+ in your env file. The server then runs non-interactively (refresh_token grant) โ€”
127
+ no password is ever stored. PKCE (S256) is always used.
128
+
129
+ > The OAuth 2.0 **password grant (ROPC) is deprecated** in OAuth 2.1 and disabled
130
+ > on many instances; prefer `login`. `client_credentials` and `refresh_token`
131
+ > grants remain supported for service accounts. See [.env.example](.env.example).
132
+
133
+ ### Supported authentication methods
134
+
135
+ Every inbound REST auth method ServiceNow offers is covered:
136
+
137
+ | Method | `SN_AUTH` | Set | Notes |
138
+ | ------ | --------- | --- | ----- |
139
+ | Basic | `basic` | `SN_USER` / `SN_PASSWORD` | Default. |
140
+ | OAuth 2.1 โ€” Authorization Code + PKCE | `oauth` | `npx servicenow-mcp-ai login` | **Recommended.** Interactive, stores a refresh token. |
141
+ | OAuth โ€” Client Credentials | `oauth` | `SN_OAUTH_GRANT=client_credentials` | Service-to-service. |
142
+ | OAuth โ€” Refresh Token | `oauth` | `SN_OAUTH_GRANT=refresh_token` + `SN_OAUTH_REFRESH_TOKEN` | Set by `login`. |
143
+ | OAuth โ€” JWT Bearer | `oauth` | `SN_OAUTH_GRANT=jwt_bearer` + `SN_OAUTH_JWT_KEY` | RS256 assertion; no password. |
144
+ | OAuth โ€” Password (ROPC) | `oauth` | `SN_OAUTH_GRANT=password` | **Deprecated.** |
145
+ | API Key | `apikey` | `SN_API_KEY` | `x-sn-apikey` header. |
146
+ | Bearer token | `token` | `SN_BEARER_TOKEN` | Pre-obtained token, used verbatim. |
147
+ | Mutual TLS (client cert) | `none` (or layered) | `SN_TLS_CLIENT_CERT` / `_KEY` | Cert maps to a user; needs optional `undici`. |
148
+
149
+ ### Environment variables
150
+
151
+ All settings are read from `.env` (or the real process environment, which takes
152
+ precedence). Only the first three are required; the rest are optional tuning knobs.
153
+ See [.env.example](.env.example) for a template.
154
+
155
+ | Variable | Required | Default | Description |
156
+ | ------------------------ | :------: | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
157
+ | `SN_INSTANCE` | yes | โ€” | Instance name, host, or `https://` URL (`dev12345`, `dev12345.service-now.com`). |
158
+ | `SN_USER` | yes | โ€” | ServiceNow username for Basic auth. |
159
+ | `SN_PASSWORD` | yes | โ€” | ServiceNow password. Never logged or returned by any tool. |
160
+ | `SN_TIMEOUT_MS` | no | `30000` | Per-request timeout in milliseconds. |
161
+ | `SN_MAX_RETRIES` | no | `2` | Retries for transient failures (429/5xx, network errors). Non-idempotent writes are only retried on connect errors. |
162
+ | `SN_MAX_RECORDS` | no | `10000` | Hard cap on records returned by a `fetchAll` query. |
163
+ | `SN_MAX_RESULT_CHARS` | no | `100000` | Character budget for a query result before it is truncated for the client. |
164
+ | `SN_ALLOWED_HOSTS` | no | โ€” | Comma-separated allow-list of permitted hosts (for custom or sovereign-cloud domains). When set, only matching hosts are contacted. When unset, only `*.service-now.com` instances are allowed and internal/loopback hosts are blocked (SSRF guard). |
165
+ | `SN_AUTH` | no | auto | Auth method: `basic`, `oauth`, `apikey`, `token` or `none` (cert-only mTLS). Auto-detected from the keys present (API key โ†’ bearer โ†’ OAuth โ†’ Basic). |
166
+ | `SN_API_KEY` | no | โ€” | ServiceNow Inbound API Key, sent as the `x-sn-apikey` header (enables `apikey` mode). |
167
+ | `SN_BEARER_TOKEN` | no | โ€” | A pre-obtained bearer token, sent verbatim as `Authorization: Bearer โ€ฆ` (enables `token` mode). |
168
+ | `SN_OAUTH_CLIENT_ID` | no | โ€” | OAuth client id (its presence enables OAuth). |
169
+ | `SN_OAUTH_CLIENT_SECRET` | no | โ€” | OAuth client secret. |
170
+ | `SN_OAUTH_GRANT` | no | `password` | OAuth grant: `password` (**deprecated** โ€” ROPC), `client_credentials`, `refresh_token` or `jwt_bearer`. The `login` command sets this to `refresh_token` for you. |
171
+ | `SN_OAUTH_JWT_KEY` | no | โ€” | PEM private key for the `jwt_bearer` grant (or `SN_OAUTH_JWT_KEY_FILE`). Optional claims: `SN_OAUTH_JWT_ISS` (default client id), `SN_OAUTH_JWT_SUB` (default `SN_USER`), `SN_OAUTH_JWT_AUD`, `SN_OAUTH_JWT_KID`, `SN_OAUTH_JWT_EXP_SEC` (default 300). |
172
+ | `SN_OAUTH_REFRESH_TOKEN` | no | โ€” | Refresh token for the `refresh_token` grant. Obtained automatically by `npx servicenow-mcp-ai login` (Authorization Code + PKCE). |
173
+ | `SN_OAUTH_REDIRECT_URI` | no | `http://localhost:53682/callback` | Loopback redirect URL for the PKCE `login` flow. Must match the redirect registered on the OAuth endpoint. |
174
+ | `SN_OAUTH_SCOPE` | no | โ€” | Optional OAuth scope requested during `login`. |
175
+ | `SN_TLS_CLIENT_CERT` | no | โ€” | Client certificate (PEM) for **mutual TLS** (or `SN_TLS_CLIENT_CERT_FILE`). With `SN_TLS_CLIENT_KEY` it presents a client cert; ServiceNow's mutual-auth profile maps it to a user. Needs the optional `undici` package (`npm i undici`). |
176
+ | `SN_TLS_CLIENT_KEY` | no | โ€” | Private key (PEM) for the client certificate (or `SN_TLS_CLIENT_KEY_FILE`). |
177
+ | `SN_TLS_CA` | no | โ€” | Optional CA bundle (PEM) to trust (or `SN_TLS_CA_FILE`). `SN_TLS_REJECT_UNAUTHORIZED=false` disables verification (not recommended). |
178
+ | `SN_TABLES_ALLOW` | no | โ€” | Comma-separated table allowlist; when set, only these tables are reachable. |
179
+ | `SN_TABLES_DENY` | no | โ€” | Comma-separated table denylist; always wins over the allowlist. |
180
+ | `SN_READONLY` | no | `false` | When truthy, refuse every create/update/delete. |
181
+ | `SN_LOG_LEVEL` | no | `info` | Log verbosity on stderr: `error`, `warn`, `info`, `debug`. |
182
+ | `SN_ENV_FILE` | no | โ€” | Explicit path to the env file to read/write. |
183
+ | `SN_TOOL_PACKAGES` | no | `core` | Comma/space-separated tool packages or profiles to enable. Profiles: `core` (default) and `all`. Packages: `table`, `schema`, `aggregate`, `attachment`, `importset`, `batch`, `catalog`, `change`, `knowledge`, `cmdb`, `scripts`, `flows`, `codecheck`, `docs`, `instance`, `email`, `atf`. The admin tools are always on. `atf` runs tests on the instance โ€” enable it only on a non-production instance. |
184
+ | `SN_PACKAGES_DENY` | no | โ€” | Comma/space-separated packages to exclude even if enabled by `SN_TOOL_PACKAGES`. The only way to block plugin APIs (catalog, change, knowledgeโ€ฆ) โ€” the table policy does not see them. |
185
+ | `SN_PACKAGES_READONLY` | no | โ€” | Comma/space-separated packages whose write tools are not registered; their read tools stay. Per-package complement to the global `SN_READONLY`. |
186
+ | `SN_SCHEMA_CACHE_TTL_SEC` | no | `300` | TTL for the near-static schema reads cache (`list_tables`, `describe_table`, `get_cmdb_meta`). `0` disables caching. |
187
+ | `SN_MAX_CONCURRENT` | no | `4` | Maximum parallel HTTP requests to the instance (simple in-process semaphore). |
188
+ | `SN_INCLUDE_REF_LINKS` | no | `false` | Reference fields come back without their `link` URLs by default (token savings). Set `true` to include them. |
189
+ | `SN_RESULT_PRETTY` | no | `false` | Tool results are compact JSON by default (pretty-printing ~doubles tokens). Set `true` for indented output. |
190
+ | `SN_DOCS_DIR` | no | `docs/instance` | Directory the `docs` package reads/writes Markdown in. Relative paths resolve against the working directory. |
191
+ | `SN_CODESEARCH` | no | `false` | Opt in to the Code Search API (`sn_codesearch`) for `servicenow_search_code` (FT-7). When `true` and the plugin is active it replaces the LIKE iteration; falls back to LIKE on any failure. |
192
+ | `SN_PROFILE_<NAME>_*` | no | โ€” | Named connection profiles: `SN_PROFILE_DEV_INSTANCE` / `_USER` / `_PASSWORD` define profile `dev`. The bare `SN_INSTANCE`/`SN_USER`/`SN_PASSWORD` keys are the `default` profile. |
193
+ | `SN_ACTIVE_PROFILE` | no | `default` | Which profile tools use. Switch at runtime with `servicenow_use_instance` (persisted to the env file). |
194
+
195
+ ## Run / debug
196
+
197
+ - **VS Code**: open the Command Palette and start the server defined in
198
+ [.vscode/mcp.json](.vscode/mcp.json), then use it from Chat.
199
+ - **MCP Inspector**: `npm run inspector`
200
+ - **Directly**: `npm start`
201
+
202
+ ## Develop
203
+
204
+ ```bash
205
+ npm run check # full gate: build, lint, format check, coverage-gated tests, prod audit
206
+ npm test # unit tests only (node:test; needs a prior npm run build)
207
+ npm run lint # ESLint (flat config + typescript-eslint)
208
+ npm run format # format with Prettier
209
+ ```
210
+
211
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the conventions (one commit per
212
+ task, tests ship with the change, generated docs).
213
+
214
+ ## Tools
215
+
216
+ <!-- GENERATED:TOOLS:BEGIN (npm run docs:readme) -->
217
+
218
+ _This table is generated from the tool registrations โ€” edit the tool
219
+ definitions in `src/tools/`, then run `npm run docs:readme`._
220
+
221
+ | Package | Tool | Read-only | Description |
222
+ | ------- | ---- | :-------: | ----------- |
223
+ | `table` | `servicenow_query_table` | yes | Read records from any ServiceNow table through the Table API |
224
+ | `table` | `servicenow_get_record` | yes | Read a single record from a table by its sys_id |
225
+ | `table` | `servicenow_create_record` | no | Create a new record in a table with the given field values |
226
+ | `table` | `servicenow_update_record` | no | Update fields on an existing record identified by its sys_id |
227
+ | `table` | `servicenow_delete_record` | no | Delete a record from a table by its sys_id |
228
+ | `schema` | `servicenow_list_tables` | yes | List tables from sys_db_object, optionally filtered by a name or label fragment |
229
+ | `schema` | `servicenow_describe_table` | yes | List a table's columns (name, label, type, mandatory, reference) from sys_dictionary |
230
+ | `aggregate` | `servicenow_aggregate` | yes | Compute server-side aggregates (count, avg, min, max, sum) over a table via the Stats API, with optional grโ€ฆ |
231
+ | `attachment` | `servicenow_list_attachments` | yes | List attachment metadata, optionally scoped to a specific record (table + sys_id) |
232
+ | `attachment` | `servicenow_get_attachment` | yes | Read a single attachment's metadata by its sys_id |
233
+ | `attachment` | `servicenow_download_attachment` | yes | Download an attachment's bytes, returned as base64 |
234
+ | `attachment` | `servicenow_upload_attachment` | no | Attach a file (provided as base64) to a record identified by table + sys_id |
235
+ | `attachment` | `servicenow_delete_attachment` | no | Delete an attachment by its sys_id |
236
+ | `importset` | `servicenow_insert_import_set_row` | no | Insert a single row into a staging table and run its transform map |
237
+ | `importset` | `servicenow_get_import_set_row` | yes | Read the transform outcome for a previously inserted staging row by its sys_id |
238
+ | `batch` | `servicenow_batch` | no | Execute several ServiceNow REST sub-requests in a single HTTP round-trip via the Batch API |
239
+ | `catalog` | `servicenow_list_catalogs` | yes | List the Service Catalogs available on the instance (Service Catalog API) |
240
+ | `catalog` | `servicenow_list_catalog_categories` | yes | List the categories within a service catalog |
241
+ | `catalog` | `servicenow_list_catalog_items` | yes | Search/list orderable catalog items, optionally by text or category |
242
+ | `catalog` | `servicenow_get_catalog_item` | yes | Get a catalog item, including its order variables, by sys_id |
243
+ | `catalog` | `servicenow_order_catalog_item` | no | Order a catalog item directly ('order now') |
244
+ | `change` | `servicenow_list_changes` | yes | List change requests through the Change Management API |
245
+ | `change` | `servicenow_get_change` | yes | Get a single change request by sys_id |
246
+ | `change` | `servicenow_create_change` | no | Create a normal, standard or emergency change |
247
+ | `change` | `servicenow_update_change` | no | Update fields on a change request by sys_id |
248
+ | `change` | `servicenow_change_conflicts` | no | Read schedule conflicts for a change, or recalculate them (calculate=true) |
249
+ | `knowledge` | `servicenow_search_knowledge` | yes | Full-text search of knowledge articles (Knowledge API), with optional encoded query and paging |
250
+ | `knowledge` | `servicenow_get_knowledge_article` | yes | Get a knowledge article (content and metadata) by sys_id |
251
+ | `knowledge` | `servicenow_knowledge_highlights` | yes | List featured or most-viewed knowledge articles for the current user |
252
+ | `cmdb` | `servicenow_list_cis` | yes | List configuration items of a CMDB class through the class-aware CMDB Instance API |
253
+ | `cmdb` | `servicenow_get_ci` | yes | Get a CI with its attributes and inbound/outbound relations by class and sys_id |
254
+ | `cmdb` | `servicenow_create_ci` | no | Create a CI via the CMDB Instance API (routed through Identification & Reconciliation) |
255
+ | `cmdb` | `servicenow_update_ci` | no | Update a CI's attributes via the CMDB Instance API (IRE) |
256
+ | `cmdb` | `servicenow_get_cmdb_meta` | yes | Get the schema/metadata of a CMDB class (attributes, relationship rules) from the CMDB Meta API |
257
+ | `scripts` | `servicenow_list_scripts` | yes | List script artefacts of one type as compact metadata (no source code) |
258
+ | `scripts` | `servicenow_get_script` | yes | Read one script artefact in full, including its source code and execution context |
259
+ | `scripts` | `servicenow_search_code` | yes | Search script source for a literal substring across one or all script types |
260
+ | `scripts` | `servicenow_table_logic` | yes | Assemble the automation that runs on a table: business rules (ordered by when+order), client scripts, UI poโ€ฆ |
261
+ | `flows` | `servicenow_trace_table_event` | yes | Deterministically trace what ServiceNow would run for a table operation, in execution order: display/beforeโ€ฆ |
262
+ | `flows` | `servicenow_list_flows` | yes | List Flow Designer flows (sys_hub_flow) or legacy workflows (kind: 'workflow') as compact metadata |
263
+ | `flows` | `servicenow_get_flow` | yes | Get a structured view of one flow or workflow: its trigger (table/condition/when) and ordered steps |
264
+ | `flows` | `servicenow_get_flow_runs` | yes | Read flow execution evidence from sys_flow_context โ€” by flow sys_id or by the record (document) it ran agaiโ€ฆ |
265
+ | `codecheck` | `servicenow_lint_script` | yes | Run deterministic code-quality rules over one script artefact (hard-coded sys_ids/URLs, unbounded or in-looโ€ฆ |
266
+ | `codecheck` | `servicenow_lint_table` | yes | Lint every active business rule, client script and UI policy of a table (via table_logic), returning per-scโ€ฆ |
267
+ | `codecheck` | `servicenow_code_health` | no | Aggregate code-health picture: script counts by type, and (when a table scope is given) the lint findings bโ€ฆ |
268
+ | `docs` | `servicenow_docs_list` | yes | List the Markdown documents in the local instance-documentation folder (SN_DOCS_DIR) |
269
+ | `docs` | `servicenow_docs_read` | yes | Read one Markdown document from the local instance-documentation folder |
270
+ | `docs` | `servicenow_docs_search` | yes | Search the local instance documentation for a substring; returns a snippet per match |
271
+ | `docs` | `servicenow_docs_write` | no | Create or overwrite a Markdown document in the local docs folder and refresh index.md |
272
+ | `docs` | `servicenow_generate_er_diagram` | yes | Build a Mermaid erDiagram from sys_dictionary: an entity per table plus a relationship for every reference โ€ฆ |
273
+ | `docs` | `servicenow_generate_table_flow` | yes | Build a Mermaid flowchart of a record's lifecycle on a table, grouping active business rules by phase (dispโ€ฆ |
274
+ | `instance` | `servicenow_snapshot_instance` | no | Download the instance's structural metadata into the local docs folder (SN_DOCS_DIR/<profile>/): tables.md+โ€ฆ |
275
+ | `instance` | `servicenow_compare_instances` | no | Diff two connection profiles: tables present in only one, common columns whose type/mandatory/reference difโ€ฆ |
276
+ | `email` | `servicenow_send_email` | no | Send an email through the instance's Email API, optionally associated with a record (table + sys_id) |
277
+ | `email` | `servicenow_get_email` | yes | Read a sent/received email record by its sys_id (Email API) |
278
+ | `atf` | `servicenow_list_atf_tests` | yes | List Automated Test Framework tests (sys_atf_test) as metadata: name, active flag, description |
279
+ | `atf` | `servicenow_list_atf_suites` | yes | List Automated Test Framework test suites (sys_atf_test_suite) as metadata |
280
+ | `atf` | `servicenow_run_atf_test` | no | Run a single ATF test through the CI/CD API |
281
+ | `atf` | `servicenow_run_atf_suite` | no | Run an ATF test suite through the CI/CD API |
282
+ | `atf` | `servicenow_get_atf_result` | yes | Poll an ATF run by its execution id: status, percent complete and message (CI/CD progress API) |
283
+ | `admin` | `servicenow_set_credentials` | no | Save or update the ServiceNow connection credentials |
284
+ | `admin` | `servicenow_list_instances` | yes | List the configured ServiceNow connection profiles (instances): name, host, user, read-only flag and whetheโ€ฆ |
285
+ | `admin` | `servicenow_use_instance` | no | Switch the active ServiceNow connection profile (persisted to the env file) |
286
+ | `admin` | `servicenow_get_status` | yes | Show the configured instance, user, auth mode and access policy, and whether credentials are complete |
287
+ | `admin` | `servicenow_test_connection` | yes | Verify that the configured credentials actually work: reads one sys_user record and reports ok/status/latency |
288
+
289
+ <!-- GENERATED:TOOLS:END -->
290
+
291
+ All tools carry MCP annotations (`readOnlyHint`, `destructiveHint`,
292
+ `idempotentHint`) so clients can apply the right confirmation UX.
293
+
294
+ ### Tool packages
295
+
296
+ Tools are grouped into packages so you can expose only what a given client needs
297
+ (fewer tools keep the model focused). Set `SN_TOOL_PACKAGES` to a comma/space
298
+ separated list of profiles or package names:
299
+
300
+ - `core` (default) โ€” `table`, `schema`, `aggregate`, `attachment`.
301
+ - `all` โ€” every package below.
302
+ - Individual packages: `table`, `schema`, `aggregate`, `attachment`,
303
+ `importset`, `batch`, `catalog`, `change`, `knowledge`, `cmdb`, `scripts`,
304
+ `flows`, `codecheck`, `docs`, `instance`, `email`, `atf`.
305
+
306
+ The admin tools (`servicenow_set_credentials`, `servicenow_get_status`) are
307
+ always registered, regardless of the active packages. Unknown names are ignored.
308
+ `servicenow_get_status` reports the resolved `enabledPackages`.
309
+
310
+ ```dotenv
311
+ # Only table + batch tools (plus the always-on admin tools)
312
+ SN_TOOL_PACKAGES=table,batch
313
+ ```
314
+
315
+ ### Examples
316
+
317
+ Query the 5 most recent active incidents:
318
+
319
+ ```jsonc
320
+ // servicenow_query_table
321
+ {
322
+ "table": "incident",
323
+ "query": "active=true^ORDERBYDESCsys_created_on",
324
+ "fields": ["number", "short_description", "priority", "state"],
325
+ "limit": 5,
326
+ }
327
+ ```
328
+
329
+ Create an incident:
330
+
331
+ ```jsonc
332
+ // servicenow_create_record
333
+ {
334
+ "table": "incident",
335
+ "fields": {
336
+ "short_description": "Printer on 3rd floor is down",
337
+ "urgency": "2",
338
+ "impact": "2",
339
+ },
340
+ }
341
+ ```
342
+
343
+ Update credentials at runtime:
344
+
345
+ ```jsonc
346
+ // servicenow_set_credentials
347
+ {
348
+ "instance": "dev98765.service-now.com",
349
+ "user": "admin",
350
+ "password": "โ€ขโ€ขโ€ขโ€ขโ€ขโ€ข",
351
+ }
352
+ ```
353
+
354
+ ## Resources
355
+
356
+ Read-only metadata is also exposed as MCP resources, so clients can attach it
357
+ declaratively instead of calling a tool:
358
+
359
+ | URI | Description |
360
+ | ----------------------------- | ---------------------------------------------- |
361
+ | `servicenow://status` | Connection status, auth mode, access policy. |
362
+ | `servicenow://tables` | List of tables from `sys_db_object`. |
363
+ | `servicenow://schema/{table}` | Columns of a table from `sys_dictionary`. |
364
+ | `servicenow://docs/{path}` | A Markdown document from the local docs store. |
365
+
366
+ ## Prompts
367
+
368
+ Ready-made workflows are exposed as MCP prompts; they orchestrate the tools and
369
+ insist on reading real values from the instance:
370
+
371
+ | Prompt | Argument | Purpose |
372
+ | ----------------------------------- | ---------- | ---------------------------------------------------------------- |
373
+ | `servicenow_incident_triage` | `incident` | Summarize, assess priority, categorize and recommend next steps. |
374
+ | `servicenow_change_impact_analysis` | `change` | Affected CIs, schedule conflicts and a go/no-go call. |
375
+ | `servicenow_document_table` | `table` | Schema + automation + diagrams โ†’ saved Markdown doc. |
376
+
377
+ ## Project structure
378
+
379
+ ```
380
+ .
381
+ โ”œโ”€โ”€ .env # credentials (git-ignored; or ~/.config/servicenow-mcp-ai/.env)
382
+ โ”œโ”€โ”€ .env.example # template
383
+ โ”œโ”€โ”€ .github/workflows/ # CI: build + lint + test
384
+ โ”œโ”€โ”€ .vscode/mcp.json # VS Code MCP server registration
385
+ โ”œโ”€โ”€ eslint.config.js # ESLint flat config
386
+ โ”œโ”€โ”€ .prettierrc.json # Prettier config
387
+ โ”œโ”€โ”€ src/
388
+ โ”‚ โ”œโ”€โ”€ index.ts # bootstrap: load env, register, connect stdio
389
+ โ”‚ โ”œโ”€โ”€ registry.ts # registers all tool groups
390
+ โ”‚ โ”œโ”€โ”€ resources.ts # MCP resources (status, tables, schema, docs)
391
+ โ”‚ โ”œโ”€โ”€ prompts.ts # MCP prompts (triage, change impact, document table)
392
+ โ”‚ โ”œโ”€โ”€ http.ts # shared REST client (auth, retry, SSRF)
393
+ โ”‚ โ”œโ”€โ”€ auth.ts # Basic + OAuth 2.0 providers
394
+ โ”‚ โ”œโ”€โ”€ host.ts # host resolution + SSRF guard
395
+ โ”‚ โ”œโ”€โ”€ policy.ts # table allow/deny + read-only guards
396
+ โ”‚ โ”œโ”€โ”€ settings.ts # numeric env settings
397
+ โ”‚ โ”œโ”€โ”€ logging.ts # structured stderr logger
398
+ โ”‚ โ”œโ”€โ”€ result.ts # tool results + structured errors
399
+ โ”‚ โ”œโ”€โ”€ servicenow.ts # Table API client
400
+ โ”‚ โ”œโ”€โ”€ config.ts # env file read/write + location
401
+ โ”‚ โ”œโ”€โ”€ api/ # aggregate, attachment, import set, batch, catalog, change, knowledge, cmdb, scripts, diagrams, docs, meta
402
+ โ”‚ โ””โ”€โ”€ tools/ # tool registration per API group
403
+ โ”œโ”€โ”€ test/ # node:test unit + mock-fetch tests
404
+ โ””โ”€โ”€ build/ # compiled output (after npm run build)
405
+ ```
406
+
407
+ > **Note on names:** the npm package is `servicenow-mcp-ai` (the unscoped
408
+ > `servicenow-mcp` was already taken); the GitHub repository is
409
+ > [`servicenow-mcp`](https://github.com/LeassTaTT/servicenow-mcp); the local
410
+ > working folder is `sincronia-mpc` (a historical `mpc`/`mcp` typo). All three
411
+ > differences are cosmetic and do not affect the build or runtime.
412
+
413
+ ## Security notes
414
+
415
+ - The env file is git-ignored โ€” do not commit real credentials.
416
+ - The env file is written **owner-only (`0600`)** โ€” it holds a plaintext password.
417
+ - The server uses the stdio transport and only logs to `stderr`; secrets and raw
418
+ encoded queries are never logged.
419
+ - The password/token is never returned by any tool.
420
+ - Hosts are restricted: without `SN_ALLOWED_HOSTS`, only `*.service-now.com`
421
+ instances are contacted (internal/loopback always blocked), so a redirected or
422
+ mistyped host cannot silently receive credentials. Set `SN_ALLOWED_HOSTS` to
423
+ opt in a custom or sovereign-cloud domain.
424
+ - Prefer **OAuth 2.0** over Basic where possible (`SN_OAUTH_CLIENT_ID`).
425
+ - Apply least privilege with `SN_TABLES_ALLOW` / `SN_TABLES_DENY` and
426
+ `SN_READONLY=true` for read-only deployments.
427
+ - **Table policy does not cover plugin APIs.** `SN_TABLES_DENY=change_request`
428
+ blocks the Table API path, but the Change Management API (`sn_chg_rest`) can
429
+ still read/write changes. To restrict the plugin-backed surfaces use
430
+ `SN_PACKAGES_DENY` (drop the whole package) or `SN_PACKAGES_READONLY`
431
+ (register only its read tools). The Batch API obeys both axes too: a
432
+ sub-request to a denied package's path is refused, and writes to a read-only
433
+ package are blocked โ€” a batch cannot be used to bypass the package policy.
434
+
435
+ ## Project documentation
436
+
437
+ | Document | Contents |
438
+ | -------- | -------- |
439
+ | [ARCHITECTURE.md](ARCHITECTURE.md) | Layered architecture, Mermaid diagrams (modules, request lifecycle, security model, auth, packages), condensed ADRs |
440
+ | [PRODUCT-STATE.md](PRODUCT-STATE.md) | Current product state: API coverage map, quality status, history timeline, roadmap |
441
+ | [ROADMAP.md](ROADMAP.md) | Forward plan: ship 1.0.0, Phase 8 (flow testing + code analysis), Phase 9 (competitive differentiators), optional and deferred items |
442
+ | [COMPETITIVE-ANALYSIS.md](COMPETITIVE-ANALYSIS.md) | Positioning vs the official ServiceNow MCP Server Console: comparison, where it structurally lags, the Phase 9 boost plan, and platform risks |
443
+ | [IMPLEMENTATION-PLAN.md](IMPLEMENTATION-PLAN.md) | Detailed specs for the upcoming phases (harness 2.0, multi-instance, flow testing) |
444
+ | [DONE.md](DONE.md) / [TODO.md](TODO.md) | Completed work with commit refs / remaining decisions |
445
+ | [WORKLOG.md](WORKLOG.md) / [CHANGELOG.md](CHANGELOG.md) | Detailed work journal / user-facing changelog |
446
+ | [CONTRIBUTING.md](CONTRIBUTING.md) / [SECURITY.md](SECURITY.md) | Dev setup, gates and conventions / security model and reporting |
447
+
448
+ ## Trademark
449
+
450
+ `servicenow-mcp-ai` is an independent, community-built project. It is **not
451
+ affiliated with, endorsed by, or sponsored by ServiceNow, Inc.**
452
+
453
+ "ServiceNow", the ServiceNow logo, "Now", and related marks are trademarks or
454
+ registered trademarks of ServiceNow, Inc. in the United States and other
455
+ countries. They are used in this project's name and documentation **only
456
+ nominatively** โ€” to identify the platform this software interoperates with โ€” and
457
+ no affiliation or endorsement is implied. All other product names and marks are
458
+ the property of their respective owners.
459
+
460
+ This project is licensed under the [MIT License](LICENSE); that license covers
461
+ the source code and does not grant any rights to use the ServiceNow trademarks.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ // CommonJS launcher whose only job is the Node version guard. It must stay
3
+ // parseable by ancient Node (no ?., ??, ESM syntax): the real entry is an ESM
4
+ // graph that old Node fails to *parse*, so a guard inside it can never run.
5
+ "use strict";
6
+
7
+ var major = parseInt(process.versions.node.split(".")[0], 10);
8
+ if (major < 20) {
9
+ console.error(
10
+ "servicenow-mcp-ai requires Node.js >= 20, but this is " +
11
+ process.versions.node +
12
+ ".\nUse a newer runtime, e.g.: nvm install 22 && nvm use 22",
13
+ );
14
+ process.exit(1);
15
+ }
16
+
17
+ import("../build/index.js").catch(function (err) {
18
+ console.error(err && err.stack ? err.stack : String(err));
19
+ process.exit(1);
20
+ });
@@ -0,0 +1,30 @@
1
+ import { snRequest } from "../core/http.js";
2
+ import { assertTableAllowed } from "../core/policy.js";
3
+ import { expectResult } from "./shared.js";
4
+ export async function aggregate(opts) {
5
+ assertTableAllowed(opts.table);
6
+ const params = new URLSearchParams();
7
+ if (opts.query)
8
+ params.set("sysparm_query", opts.query);
9
+ if (opts.count)
10
+ params.set("sysparm_count", "true");
11
+ if (opts.avgFields?.length)
12
+ params.set("sysparm_avg_fields", opts.avgFields.join(","));
13
+ if (opts.minFields?.length)
14
+ params.set("sysparm_min_fields", opts.minFields.join(","));
15
+ if (opts.maxFields?.length)
16
+ params.set("sysparm_max_fields", opts.maxFields.join(","));
17
+ if (opts.sumFields?.length)
18
+ params.set("sysparm_sum_fields", opts.sumFields.join(","));
19
+ if (opts.groupBy?.length)
20
+ params.set("sysparm_group_by", opts.groupBy.join(","));
21
+ if (opts.having)
22
+ params.set("sysparm_having", opts.having);
23
+ const { data } = await snRequest({
24
+ method: "GET",
25
+ path: `/api/now/stats/${encodeURIComponent(opts.table)}`,
26
+ params,
27
+ });
28
+ return expectResult(data, "Aggregate API");
29
+ }
30
+ //# sourceMappingURL=aggregate.js.map