@onlyflows/servicenow-mcp 1.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 (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +267 -0
  3. package/dist/client.d.ts +40 -0
  4. package/dist/client.d.ts.map +1 -0
  5. package/dist/client.js +145 -0
  6. package/dist/client.js.map +1 -0
  7. package/dist/config.d.ts +18 -0
  8. package/dist/config.d.ts.map +1 -0
  9. package/dist/config.js +46 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/index.d.ts +13 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +52 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/tools/aggregate.d.ts +67 -0
  16. package/dist/tools/aggregate.d.ts.map +1 -0
  17. package/dist/tools/aggregate.js +77 -0
  18. package/dist/tools/aggregate.js.map +1 -0
  19. package/dist/tools/atf.d.ts +95 -0
  20. package/dist/tools/atf.d.ts.map +1 -0
  21. package/dist/tools/atf.js +357 -0
  22. package/dist/tools/atf.js.map +1 -0
  23. package/dist/tools/attach.d.ts +74 -0
  24. package/dist/tools/attach.d.ts.map +1 -0
  25. package/dist/tools/attach.js +156 -0
  26. package/dist/tools/attach.js.map +1 -0
  27. package/dist/tools/batch.d.ts +68 -0
  28. package/dist/tools/batch.d.ts.map +1 -0
  29. package/dist/tools/batch.js +120 -0
  30. package/dist/tools/batch.js.map +1 -0
  31. package/dist/tools/codesearch.d.ts +52 -0
  32. package/dist/tools/codesearch.d.ts.map +1 -0
  33. package/dist/tools/codesearch.js +87 -0
  34. package/dist/tools/codesearch.js.map +1 -0
  35. package/dist/tools/create.d.ts +39 -0
  36. package/dist/tools/create.d.ts.map +1 -0
  37. package/dist/tools/create.js +44 -0
  38. package/dist/tools/create.js.map +1 -0
  39. package/dist/tools/delete.d.ts +45 -0
  40. package/dist/tools/delete.d.ts.map +1 -0
  41. package/dist/tools/delete.js +53 -0
  42. package/dist/tools/delete.js.map +1 -0
  43. package/dist/tools/discover.d.ts +53 -0
  44. package/dist/tools/discover.d.ts.map +1 -0
  45. package/dist/tools/discover.js +137 -0
  46. package/dist/tools/discover.js.map +1 -0
  47. package/dist/tools/get.d.ts +52 -0
  48. package/dist/tools/get.d.ts.map +1 -0
  49. package/dist/tools/get.js +52 -0
  50. package/dist/tools/get.js.map +1 -0
  51. package/dist/tools/health.d.ts +32 -0
  52. package/dist/tools/health.d.ts.map +1 -0
  53. package/dist/tools/health.js +172 -0
  54. package/dist/tools/health.js.map +1 -0
  55. package/dist/tools/index.d.ts +43 -0
  56. package/dist/tools/index.d.ts.map +1 -0
  57. package/dist/tools/index.js +110 -0
  58. package/dist/tools/index.js.map +1 -0
  59. package/dist/tools/nl.d.ts +52 -0
  60. package/dist/tools/nl.d.ts.map +1 -0
  61. package/dist/tools/nl.js +433 -0
  62. package/dist/tools/nl.js.map +1 -0
  63. package/dist/tools/query.d.ts +73 -0
  64. package/dist/tools/query.d.ts.map +1 -0
  65. package/dist/tools/query.js +75 -0
  66. package/dist/tools/query.js.map +1 -0
  67. package/dist/tools/relationships.d.ts +74 -0
  68. package/dist/tools/relationships.d.ts.map +1 -0
  69. package/dist/tools/relationships.js +228 -0
  70. package/dist/tools/relationships.js.map +1 -0
  71. package/dist/tools/schema.d.ts +38 -0
  72. package/dist/tools/schema.d.ts.map +1 -0
  73. package/dist/tools/schema.js +60 -0
  74. package/dist/tools/schema.js.map +1 -0
  75. package/dist/tools/script.d.ts +52 -0
  76. package/dist/tools/script.d.ts.map +1 -0
  77. package/dist/tools/script.js +51 -0
  78. package/dist/tools/script.js.map +1 -0
  79. package/dist/tools/syslog.d.ts +74 -0
  80. package/dist/tools/syslog.d.ts.map +1 -0
  81. package/dist/tools/syslog.js +93 -0
  82. package/dist/tools/syslog.js.map +1 -0
  83. package/dist/tools/update.d.ts +46 -0
  84. package/dist/tools/update.d.ts.map +1 -0
  85. package/dist/tools/update.js +44 -0
  86. package/dist/tools/update.js.map +1 -0
  87. package/dist/utils.d.ts +44 -0
  88. package/dist/utils.d.ts.map +1 -0
  89. package/dist/utils.js +72 -0
  90. package/dist/utils.js.map +1 -0
  91. package/package.json +54 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OnlyFlows
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,267 @@
1
+ # @onlyflows/servicenow-mcp
2
+
3
+ <!-- Logo placeholder -->
4
+ <!-- ![ServiceNow MCP Server](banner.png) -->
5
+
6
+ **The most comprehensive ServiceNow MCP server.** 17 tools for full CRUD, CMDB graph traversal, background scripts, ATF testing, and more.
7
+
8
+ Built by [OnlyFlows](https://onlyflows.tech) · Published by [@onlyflowstech](https://github.com/onlyflowstech)
9
+
10
+ [![npm version](https://img.shields.io/npm/v/@onlyflows/servicenow-mcp)](https://www.npmjs.com/package/@onlyflows/servicenow-mcp)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
12
+
13
+ ---
14
+
15
+ ## Why This MCP Server?
16
+
17
+ Most ServiceNow MCP integrations are **read-only** and support a handful of tables. This one gives your AI assistant **full access** to the ServiceNow platform:
18
+
19
+ | Feature | Others | @onlyflows/servicenow-mcp |
20
+ |---------|--------|--------------------------|
21
+ | Query records | ✅ | ✅ |
22
+ | Create records | ❌ | ✅ |
23
+ | Update records | ❌ | ✅ |
24
+ | Delete records | ❌ | ✅ (with safety confirm) |
25
+ | Bulk operations | ❌ | ✅ (dry-run by default) |
26
+ | Aggregations (COUNT/AVG/MIN/MAX/SUM) | ❌ | ✅ |
27
+ | Table schema introspection | ❌ | ✅ |
28
+ | CMDB relationship traversal | ❌ | ✅ (recursive, configurable depth) |
29
+ | Instance health monitoring | ❌ | ✅ (version, nodes, jobs, stats) |
30
+ | Attachment management | ❌ | ✅ (list, upload, download) |
31
+ | System log queries | ❌ | ✅ |
32
+ | Code search across artifacts | ❌ | ✅ |
33
+ | Table/app/plugin discovery | ❌ | ✅ |
34
+ | ATF test execution | ❌ | ✅ |
35
+ | Natural language interface | ❌ | ✅ |
36
+ | Background scripts | ❌ | ✅ (with Playwright) |
37
+ | **Total tools** | **1–3** | **17** |
38
+
39
+ ---
40
+
41
+ ## Quick Start
42
+
43
+ ### Claude Desktop
44
+
45
+ Add to your `claude_desktop_config.json`:
46
+
47
+ ```json
48
+ {
49
+ "mcpServers": {
50
+ "servicenow": {
51
+ "command": "npx",
52
+ "args": ["-y", "@onlyflows/servicenow-mcp"],
53
+ "env": {
54
+ "SN_INSTANCE": "https://yourinstance.service-now.com",
55
+ "SN_USER": "your_username",
56
+ "SN_PASSWORD": "your_password"
57
+ }
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ ### Cursor
64
+
65
+ Add to your Cursor MCP settings (`.cursor/mcp.json`):
66
+
67
+ ```json
68
+ {
69
+ "mcpServers": {
70
+ "servicenow": {
71
+ "command": "npx",
72
+ "args": ["-y", "@onlyflows/servicenow-mcp"],
73
+ "env": {
74
+ "SN_INSTANCE": "https://yourinstance.service-now.com",
75
+ "SN_USER": "your_username",
76
+ "SN_PASSWORD": "your_password"
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### Windsurf
84
+
85
+ Add to your Windsurf MCP configuration:
86
+
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "servicenow": {
91
+ "command": "npx",
92
+ "args": ["-y", "@onlyflows/servicenow-mcp"],
93
+ "env": {
94
+ "SN_INSTANCE": "https://yourinstance.service-now.com",
95
+ "SN_USER": "your_username",
96
+ "SN_PASSWORD": "your_password"
97
+ }
98
+ }
99
+ }
100
+ }
101
+ ```
102
+
103
+ ### VS Code (Copilot)
104
+
105
+ Add to `.vscode/mcp.json`:
106
+
107
+ ```json
108
+ {
109
+ "servers": {
110
+ "servicenow": {
111
+ "command": "npx",
112
+ "args": ["-y", "@onlyflows/servicenow-mcp"],
113
+ "env": {
114
+ "SN_INSTANCE": "https://yourinstance.service-now.com",
115
+ "SN_USER": "your_username",
116
+ "SN_PASSWORD": "your_password"
117
+ }
118
+ }
119
+ }
120
+ }
121
+ ```
122
+
123
+ ---
124
+
125
+ ## Tools Reference
126
+
127
+ ### Core CRUD
128
+
129
+ | Tool | Description |
130
+ |------|-------------|
131
+ | `sn_query` | Query any table with encoded queries, field selection, pagination, sorting |
132
+ | `sn_get` | Get a single record by sys_id |
133
+ | `sn_create` | Create a new record on any table |
134
+ | `sn_update` | Update an existing record (PATCH) |
135
+ | `sn_delete` | Delete a record (requires `confirm: true`) |
136
+ | `sn_batch` | Bulk update/delete with dry-run safety (requires `confirm: true` to execute) |
137
+
138
+ ### Analytics & Schema
139
+
140
+ | Tool | Description |
141
+ |------|-------------|
142
+ | `sn_aggregate` | COUNT, AVG, MIN, MAX, SUM with grouping |
143
+ | `sn_schema` | Table field definitions, types, references |
144
+ | `sn_health` | Instance version, cluster nodes, stuck jobs, key stats |
145
+
146
+ ### CMDB & Operations
147
+
148
+ | Tool | Description |
149
+ |------|-------------|
150
+ | `sn_relationships` | CMDB CI graph traversal — upstream/downstream/both, configurable depth |
151
+ | `sn_attach` | List, download, upload attachments |
152
+ | `sn_syslog` | Query system logs with severity/source/time filters |
153
+ | `sn_codesearch` | Search business rules, script includes, client scripts, etc. |
154
+ | `sn_discover` | Discover tables, scoped apps, store apps, plugins |
155
+
156
+ ### Testing & Automation
157
+
158
+ | Tool | Description |
159
+ |------|-------------|
160
+ | `sn_atf` | Run ATF tests and suites, get results |
161
+ | `sn_nl` | Natural language → ServiceNow API calls |
162
+ | `sn_script` | Execute background scripts (requires Playwright) |
163
+
164
+ ---
165
+
166
+ ## Environment Variables
167
+
168
+ | Variable | Required | Default | Description |
169
+ |----------|----------|---------|-------------|
170
+ | `SN_INSTANCE` | ✅ | — | Instance URL (e.g. `https://yourinstance.service-now.com`) |
171
+ | `SN_USER` | ✅ | — | ServiceNow username |
172
+ | `SN_PASSWORD` | ✅ | — | ServiceNow password |
173
+ | `SN_DISPLAY_VALUE` | ❌ | `true` | Default display value mode (`true`, `false`, `all`) |
174
+ | `SN_REL_DEPTH` | ❌ | `3` | Default CMDB relationship traversal depth |
175
+
176
+ ---
177
+
178
+ ## Usage Examples
179
+
180
+ Once connected, your AI assistant can:
181
+
182
+ **Query incidents:**
183
+ > "Show me all P1 incidents assigned to the Network team"
184
+
185
+ **Create a record:**
186
+ > "Create an incident for VPN outage affecting 50 users, P2, assign to Network Operations"
187
+
188
+ **Aggregate data:**
189
+ > "How many incidents are there grouped by priority?"
190
+
191
+ **Check health:**
192
+ > "Run a health check on our ServiceNow instance"
193
+
194
+ **CMDB traversal:**
195
+ > "Show all upstream dependencies for the email-server-01 CI"
196
+
197
+ **Schema introspection:**
198
+ > "What fields are on the change_request table?"
199
+
200
+ **Code search:**
201
+ > "Find all business rules that reference GlideRecord('incident')"
202
+
203
+ **ATF testing:**
204
+ > "Run ATF test suite abc123 and wait for results"
205
+
206
+ ---
207
+
208
+ ## Safety Features
209
+
210
+ This server is designed for production use with multiple safety layers:
211
+
212
+ - **Delete operations** require explicit `confirm: true`
213
+ - **Batch operations** run in dry-run mode by default — shows match count without making changes
214
+ - **Bulk deletes** require both `confirm` and `force` flags
215
+ - **Background scripts** require `confirm` for destructive keywords (`deleteRecord`, `deleteMultiple`, etc.)
216
+ - **Natural language writes** require `execute: true` (reads execute immediately)
217
+
218
+ ---
219
+
220
+ ## Development
221
+
222
+ ```bash
223
+ # Clone
224
+ git clone https://github.com/onlyflowstech/servicenow-mcp.git
225
+ cd servicenow-mcp
226
+
227
+ # Install & build
228
+ npm install
229
+ npm run build
230
+
231
+ # Run locally
232
+ SN_INSTANCE=https://yourinstance.service-now.com \
233
+ SN_USER=your_user \
234
+ SN_PASSWORD=your_pass \
235
+ node dist/index.js
236
+
237
+ # Watch mode
238
+ npm run dev
239
+ ```
240
+
241
+ ### Testing with MCP Inspector
242
+
243
+ ```bash
244
+ npx @modelcontextprotocol/inspector node dist/index.js
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Roadmap
250
+
251
+ - [ ] **SSE transport** for remote hosting
252
+ - [ ] **OAuth 2.0** authentication support
253
+ - [ ] **sn_script** full implementation with Playwright (SNS-39)
254
+ - [ ] **Streaming** for large result sets
255
+ - [ ] **Caching** for schema and relationship lookups
256
+
257
+ ---
258
+
259
+ ## License
260
+
261
+ MIT © [OnlyFlows](https://onlyflows.tech)
262
+
263
+ ---
264
+
265
+ <p align="center">
266
+ Built with ❤️ by <a href="https://onlyflows.tech">OnlyFlows</a> · <a href="https://github.com/onlyflowstech">@onlyflowstech</a>
267
+ </p>
@@ -0,0 +1,40 @@
1
+ /**
2
+ * ServiceNow HTTP client — native fetch-based, zero external dependencies.
3
+ *
4
+ * @module client
5
+ */
6
+ import { ServiceNowConfig } from "./config.js";
7
+ export interface ServiceNowError {
8
+ message: string;
9
+ detail?: string;
10
+ status?: number;
11
+ }
12
+ export declare class ServiceNowClient {
13
+ private config;
14
+ private baseUrl;
15
+ private authHeader;
16
+ constructor(config: ServiceNowConfig);
17
+ get(path: string, params?: Record<string, string>): Promise<any>;
18
+ post(path: string, body?: unknown): Promise<any>;
19
+ patch(path: string, body?: unknown): Promise<any>;
20
+ put(path: string, body?: unknown): Promise<any>;
21
+ delete(path: string): Promise<{
22
+ status: number;
23
+ }>;
24
+ /**
25
+ * POST binary data (for attachment uploads).
26
+ */
27
+ postBinary(path: string, data: Buffer, contentType: string, params?: Record<string, string>): Promise<any>;
28
+ /**
29
+ * GET raw response (for attachment downloads).
30
+ */
31
+ getRaw(path: string): Promise<{
32
+ data: Buffer;
33
+ contentType: string;
34
+ }>;
35
+ private buildUrl;
36
+ private request;
37
+ private parseErrorBody;
38
+ private createError;
39
+ }
40
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,gBAAgB;IAIf,OAAO,CAAC,MAAM;IAH1B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,UAAU,CAAS;gBAEP,MAAM,EAAE,gBAAgB;IAStC,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAKhE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAKhD,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAKjD,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAK/C,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAsBvD;;OAEG;IACG,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC9B,OAAO,CAAC,GAAG,CAAC;IAwBf;;OAEG;IACG,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IAwB1E,OAAO,CAAC,QAAQ;YAYF,OAAO;YA8BP,cAAc;IAmB5B,OAAO,CAAC,WAAW;CAOpB"}
package/dist/client.js ADDED
@@ -0,0 +1,145 @@
1
+ "use strict";
2
+ /**
3
+ * ServiceNow HTTP client — native fetch-based, zero external dependencies.
4
+ *
5
+ * @module client
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ServiceNowClient = void 0;
9
+ class ServiceNowClient {
10
+ config;
11
+ baseUrl;
12
+ authHeader;
13
+ constructor(config) {
14
+ this.config = config;
15
+ this.baseUrl = config.instance;
16
+ this.authHeader =
17
+ "Basic " +
18
+ Buffer.from(`${config.user}:${config.password}`).toString("base64");
19
+ }
20
+ // ── Core HTTP methods ──────────────────────────────────────────
21
+ async get(path, params) {
22
+ const url = this.buildUrl(path, params);
23
+ return this.request("GET", url);
24
+ }
25
+ async post(path, body) {
26
+ const url = this.buildUrl(path);
27
+ return this.request("POST", url, body);
28
+ }
29
+ async patch(path, body) {
30
+ const url = this.buildUrl(path);
31
+ return this.request("PATCH", url, body);
32
+ }
33
+ async put(path, body) {
34
+ const url = this.buildUrl(path);
35
+ return this.request("PUT", url, body);
36
+ }
37
+ async delete(path) {
38
+ const url = this.buildUrl(path);
39
+ const response = await fetch(url, {
40
+ method: "DELETE",
41
+ headers: {
42
+ Authorization: this.authHeader,
43
+ Accept: "application/json",
44
+ },
45
+ });
46
+ if (!response.ok && response.status !== 204) {
47
+ const errorBody = await this.parseErrorBody(response);
48
+ throw this.createError(errorBody?.message || `Delete failed with HTTP ${response.status}`, errorBody?.detail, response.status);
49
+ }
50
+ return { status: response.status };
51
+ }
52
+ /**
53
+ * POST binary data (for attachment uploads).
54
+ */
55
+ async postBinary(path, data, contentType, params) {
56
+ const url = this.buildUrl(path, params);
57
+ const response = await fetch(url, {
58
+ method: "POST",
59
+ headers: {
60
+ Authorization: this.authHeader,
61
+ Accept: "application/json",
62
+ "Content-Type": contentType,
63
+ },
64
+ body: new Uint8Array(data),
65
+ });
66
+ if (!response.ok) {
67
+ const errorBody = await this.parseErrorBody(response);
68
+ throw this.createError(errorBody?.message || `Request failed with HTTP ${response.status}`, errorBody?.detail, response.status);
69
+ }
70
+ return response.json();
71
+ }
72
+ /**
73
+ * GET raw response (for attachment downloads).
74
+ */
75
+ async getRaw(path) {
76
+ const url = this.buildUrl(path);
77
+ const response = await fetch(url, {
78
+ method: "GET",
79
+ headers: {
80
+ Authorization: this.authHeader,
81
+ },
82
+ });
83
+ if (!response.ok) {
84
+ throw this.createError(`Download failed with HTTP ${response.status}`, undefined, response.status);
85
+ }
86
+ const buffer = Buffer.from(await response.arrayBuffer());
87
+ const contentType = response.headers.get("content-type") || "application/octet-stream";
88
+ return { data: buffer, contentType };
89
+ }
90
+ // ── Internal helpers ───────────────────────────────────────────
91
+ buildUrl(path, params) {
92
+ const url = new URL(path, this.baseUrl);
93
+ if (params) {
94
+ for (const [key, value] of Object.entries(params)) {
95
+ if (value !== undefined && value !== "") {
96
+ url.searchParams.set(key, value);
97
+ }
98
+ }
99
+ }
100
+ return url.toString();
101
+ }
102
+ async request(method, url, body) {
103
+ const headers = {
104
+ Authorization: this.authHeader,
105
+ Accept: "application/json",
106
+ "Content-Type": "application/json",
107
+ };
108
+ const response = await fetch(url, {
109
+ method,
110
+ headers,
111
+ body: body ? JSON.stringify(body) : undefined,
112
+ });
113
+ if (!response.ok) {
114
+ const errorBody = await this.parseErrorBody(response);
115
+ throw this.createError(errorBody?.message || `Request failed with HTTP ${response.status}`, errorBody?.detail, response.status);
116
+ }
117
+ // 204 No Content
118
+ if (response.status === 204) {
119
+ return null;
120
+ }
121
+ return response.json();
122
+ }
123
+ async parseErrorBody(response) {
124
+ try {
125
+ const text = await response.text();
126
+ const json = JSON.parse(text);
127
+ // ServiceNow error format
128
+ if (json.error) {
129
+ return {
130
+ message: json.error.message || json.error,
131
+ detail: json.error.detail,
132
+ };
133
+ }
134
+ return { message: text };
135
+ }
136
+ catch {
137
+ return null;
138
+ }
139
+ }
140
+ createError(message, detail, status) {
141
+ return { message, detail, status };
142
+ }
143
+ }
144
+ exports.ServiceNowClient = ServiceNowClient;
145
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAUH,MAAa,gBAAgB;IAIP;IAHZ,OAAO,CAAS;IAChB,UAAU,CAAS;IAE3B,YAAoB,MAAwB;QAAxB,WAAM,GAAN,MAAM,CAAkB;QAC1C,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,UAAU;YACb,QAAQ;gBACR,MAAM,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxE,CAAC;IAED,kEAAkE;IAElE,KAAK,CAAC,GAAG,CAAC,IAAY,EAAE,MAA+B;QACrD,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,E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ServiceNow credentials from environment variables.
3
+ *
4
+ * @module config
5
+ */
6
+ export interface ServiceNowConfig {
7
+ instance: string;
8
+ user: string;
9
+ password: string;
10
+ displayValue: string;
11
+ relDepth: number;
12
+ }
13
+ /**
14
+ * Load and validate configuration from environment variables.
15
+ * Throws descriptive errors when required variables are missing.
16
+ */
17
+ export declare function loadConfig(): ServiceNowConfig;
18
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAmC7C"}
package/dist/config.js ADDED
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration — reads ServiceNow credentials from environment variables.
4
+ *
5
+ * @module config
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.loadConfig = loadConfig;
9
+ /**
10
+ * Load and validate configuration from environment variables.
11
+ * Throws descriptive errors when required variables are missing.
12
+ */
13
+ function loadConfig() {
14
+ const instance = process.env.SN_INSTANCE;
15
+ const user = process.env.SN_USER;
16
+ const password = process.env.SN_PASSWORD;
17
+ const displayValue = process.env.SN_DISPLAY_VALUE ?? "true";
18
+ const relDepth = parseInt(process.env.SN_REL_DEPTH ?? "3", 10);
19
+ const missing = [];
20
+ if (!instance)
21
+ missing.push("SN_INSTANCE");
22
+ if (!user)
23
+ missing.push("SN_USER");
24
+ if (!password)
25
+ missing.push("SN_PASSWORD");
26
+ if (missing.length > 0) {
27
+ throw new Error(`Missing required environment variable(s): ${missing.join(", ")}\n\n` +
28
+ "Set them in your MCP client configuration:\n" +
29
+ ' SN_INSTANCE — ServiceNow instance URL (e.g. https://yourinstance.service-now.com)\n' +
30
+ ' SN_USER — ServiceNow username\n' +
31
+ ' SN_PASSWORD — ServiceNow password\n');
32
+ }
33
+ // Normalize instance URL: strip trailing slash, ensure https://
34
+ let normalizedInstance = instance.replace(/\/+$/, "");
35
+ if (!normalizedInstance.startsWith("http")) {
36
+ normalizedInstance = `https://${normalizedInstance}`;
37
+ }
38
+ return {
39
+ instance: normalizedInstance,
40
+ user: user,
41
+ password: password,
42
+ displayValue,
43
+ relDepth: isNaN(relDepth) ? 3 : relDepth,
44
+ };
45
+ }
46
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAcH,gCAmCC;AAvCD;;;GAGG;AACH,SAAgB,UAAU;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IACzC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IACjC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC;IACzC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,MAAM,CAAC;IAC5D,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;IAE/D,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC3C,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACnC,IAAI,CAAC,QAAQ;QAAE,OAAO,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAE3C,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,6CAA6C,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;YACnE,8CAA8C;YAC9C,wFAAwF;YACxF,wCAAwC;YACxC,wCAAwC,CAC3C,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,IAAI,kBAAkB,GAAG,QAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvD,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3C,kBAAkB,GAAG,WAAW,kBAAkB,EAAE,CAAC;IACvD,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,kBAAkB;QAC5B,IAAI,EAAE,IAAK;QACX,QAAQ,EAAE,QAAS;QACnB,YAAY;QACZ,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ;KACzC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * @onlyflows/servicenow-mcp — The most comprehensive ServiceNow MCP server.
4
+ *
5
+ * 17 tools for full CRUD, CMDB graph traversal, background scripts,
6
+ * ATF testing, and more.
7
+ *
8
+ * Published by OnlyFlows (https://onlyflows.tech)
9
+ *
10
+ * @module index
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;GASG"}
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * @onlyflows/servicenow-mcp — The most comprehensive ServiceNow MCP server.
5
+ *
6
+ * 17 tools for full CRUD, CMDB graph traversal, background scripts,
7
+ * ATF testing, and more.
8
+ *
9
+ * Published by OnlyFlows (https://onlyflows.tech)
10
+ *
11
+ * @module index
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js");
15
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
16
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
17
+ const config_js_1 = require("./config.js");
18
+ const client_js_1 = require("./client.js");
19
+ const index_js_2 = require("./tools/index.js");
20
+ async function main() {
21
+ // Load configuration
22
+ const config = (0, config_js_1.loadConfig)();
23
+ const client = new client_js_1.ServiceNowClient(config);
24
+ // Create MCP server
25
+ const server = new index_js_1.Server({
26
+ name: "@onlyflows/servicenow-mcp",
27
+ version: "1.0.0",
28
+ }, {
29
+ capabilities: {
30
+ tools: {},
31
+ },
32
+ });
33
+ // Register tool listing handler
34
+ server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => {
35
+ return { tools: (0, index_js_2.getToolDefinitions)() };
36
+ });
37
+ // Register tool execution handler
38
+ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
39
+ const { name, arguments: args } = request.params;
40
+ return (0, index_js_2.executeTool)(name, args ?? {}, client, config);
41
+ });
42
+ // Connect via stdio transport
43
+ const transport = new stdio_js_1.StdioServerTransport();
44
+ await server.connect(transport);
45
+ // Log to stderr (stdout is reserved for MCP protocol)
46
+ console.error(`@onlyflows/servicenow-mcp v1.0.0 started — ${config.instance} (${(0, index_js_2.getToolDefinitions)().length} tools)`);
47
+ }
48
+ main().catch((error) => {
49
+ console.error("Fatal error:", error);
50
+ process.exit(1);
51
+ });
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAEA;;;;;;;;;GASG;;AAEH,wEAAmE;AACnE,wEAAiF;AACjF,iEAG4C;AAE5C,2CAAyC;AACzC,2CAA+C;AAC/C,+CAAmE;AAEnE,KAAK,UAAU,IAAI;IACjB,qBAAqB;IACrB,MAAM,MAAM,GAAG,IAAA,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