@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.
- package/LICENSE +21 -0
- package/README.md +267 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +145 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +18 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +46 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/aggregate.d.ts +67 -0
- package/dist/tools/aggregate.d.ts.map +1 -0
- package/dist/tools/aggregate.js +77 -0
- package/dist/tools/aggregate.js.map +1 -0
- package/dist/tools/atf.d.ts +95 -0
- package/dist/tools/atf.d.ts.map +1 -0
- package/dist/tools/atf.js +357 -0
- package/dist/tools/atf.js.map +1 -0
- package/dist/tools/attach.d.ts +74 -0
- package/dist/tools/attach.d.ts.map +1 -0
- package/dist/tools/attach.js +156 -0
- package/dist/tools/attach.js.map +1 -0
- package/dist/tools/batch.d.ts +68 -0
- package/dist/tools/batch.d.ts.map +1 -0
- package/dist/tools/batch.js +120 -0
- package/dist/tools/batch.js.map +1 -0
- package/dist/tools/codesearch.d.ts +52 -0
- package/dist/tools/codesearch.d.ts.map +1 -0
- package/dist/tools/codesearch.js +87 -0
- package/dist/tools/codesearch.js.map +1 -0
- package/dist/tools/create.d.ts +39 -0
- package/dist/tools/create.d.ts.map +1 -0
- package/dist/tools/create.js +44 -0
- package/dist/tools/create.js.map +1 -0
- package/dist/tools/delete.d.ts +45 -0
- package/dist/tools/delete.d.ts.map +1 -0
- package/dist/tools/delete.js +53 -0
- package/dist/tools/delete.js.map +1 -0
- package/dist/tools/discover.d.ts +53 -0
- package/dist/tools/discover.d.ts.map +1 -0
- package/dist/tools/discover.js +137 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/get.d.ts +52 -0
- package/dist/tools/get.d.ts.map +1 -0
- package/dist/tools/get.js +52 -0
- package/dist/tools/get.js.map +1 -0
- package/dist/tools/health.d.ts +32 -0
- package/dist/tools/health.d.ts.map +1 -0
- package/dist/tools/health.js +172 -0
- package/dist/tools/health.js.map +1 -0
- package/dist/tools/index.d.ts +43 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +110 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/nl.d.ts +52 -0
- package/dist/tools/nl.d.ts.map +1 -0
- package/dist/tools/nl.js +433 -0
- package/dist/tools/nl.js.map +1 -0
- package/dist/tools/query.d.ts +73 -0
- package/dist/tools/query.d.ts.map +1 -0
- package/dist/tools/query.js +75 -0
- package/dist/tools/query.js.map +1 -0
- package/dist/tools/relationships.d.ts +74 -0
- package/dist/tools/relationships.d.ts.map +1 -0
- package/dist/tools/relationships.js +228 -0
- package/dist/tools/relationships.js.map +1 -0
- package/dist/tools/schema.d.ts +38 -0
- package/dist/tools/schema.d.ts.map +1 -0
- package/dist/tools/schema.js +60 -0
- package/dist/tools/schema.js.map +1 -0
- package/dist/tools/script.d.ts +52 -0
- package/dist/tools/script.d.ts.map +1 -0
- package/dist/tools/script.js +51 -0
- package/dist/tools/script.js.map +1 -0
- package/dist/tools/syslog.d.ts +74 -0
- package/dist/tools/syslog.d.ts.map +1 -0
- package/dist/tools/syslog.js +93 -0
- package/dist/tools/syslog.js.map +1 -0
- package/dist/tools/update.d.ts +46 -0
- package/dist/tools/update.d.ts.map +1 -0
- package/dist/tools/update.js +44 -0
- package/dist/tools/update.js.map +1 -0
- package/dist/utils.d.ts +44 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +72 -0
- package/dist/utils.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ServiceNowClient } from "../client.js";
|
|
3
|
+
import { ServiceNowConfig } from "../config.js";
|
|
4
|
+
export declare const definition: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: {
|
|
10
|
+
action: {
|
|
11
|
+
type: string;
|
|
12
|
+
enum: string[];
|
|
13
|
+
description: string;
|
|
14
|
+
};
|
|
15
|
+
table: {
|
|
16
|
+
type: string;
|
|
17
|
+
description: string;
|
|
18
|
+
};
|
|
19
|
+
sys_id: {
|
|
20
|
+
type: string;
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
attachment_sys_id: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
};
|
|
27
|
+
output_path: {
|
|
28
|
+
type: string;
|
|
29
|
+
description: string;
|
|
30
|
+
};
|
|
31
|
+
file_path: {
|
|
32
|
+
type: string;
|
|
33
|
+
description: string;
|
|
34
|
+
};
|
|
35
|
+
content_type: {
|
|
36
|
+
type: string;
|
|
37
|
+
description: string;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
required: string[];
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
export declare const schema: z.ZodObject<{
|
|
44
|
+
action: z.ZodEnum<["list", "download", "upload"]>;
|
|
45
|
+
table: z.ZodOptional<z.ZodString>;
|
|
46
|
+
sys_id: z.ZodOptional<z.ZodString>;
|
|
47
|
+
attachment_sys_id: z.ZodOptional<z.ZodString>;
|
|
48
|
+
output_path: z.ZodOptional<z.ZodString>;
|
|
49
|
+
file_path: z.ZodOptional<z.ZodString>;
|
|
50
|
+
content_type: z.ZodOptional<z.ZodString>;
|
|
51
|
+
}, "strip", z.ZodTypeAny, {
|
|
52
|
+
action: "list" | "download" | "upload";
|
|
53
|
+
table?: string | undefined;
|
|
54
|
+
sys_id?: string | undefined;
|
|
55
|
+
attachment_sys_id?: string | undefined;
|
|
56
|
+
output_path?: string | undefined;
|
|
57
|
+
file_path?: string | undefined;
|
|
58
|
+
content_type?: string | undefined;
|
|
59
|
+
}, {
|
|
60
|
+
action: "list" | "download" | "upload";
|
|
61
|
+
table?: string | undefined;
|
|
62
|
+
sys_id?: string | undefined;
|
|
63
|
+
attachment_sys_id?: string | undefined;
|
|
64
|
+
output_path?: string | undefined;
|
|
65
|
+
file_path?: string | undefined;
|
|
66
|
+
content_type?: string | undefined;
|
|
67
|
+
}>;
|
|
68
|
+
export declare function handler(args: z.infer<typeof schema>, client: ServiceNowClient, _config: ServiceNowConfig): Promise<{
|
|
69
|
+
content: Array<{
|
|
70
|
+
type: "text";
|
|
71
|
+
text: string;
|
|
72
|
+
}>;
|
|
73
|
+
}>;
|
|
74
|
+
//# sourceMappingURL=attach.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attach.d.ts","sourceRoot":"","sources":["../../src/tools/attach.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAKhD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCtB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;EAQjB,CAAC;AAEH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,EAC5B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,gBAAgB;;;;;GA8E1B"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.schema = exports.definition = void 0;
|
|
37
|
+
exports.handler = handler;
|
|
38
|
+
const zod_1 = require("zod");
|
|
39
|
+
const utils_js_1 = require("../utils.js");
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
exports.definition = {
|
|
43
|
+
name: "sn_attach",
|
|
44
|
+
description: "Manage attachments on ServiceNow records. List, download, or upload attachments.",
|
|
45
|
+
inputSchema: {
|
|
46
|
+
type: "object",
|
|
47
|
+
properties: {
|
|
48
|
+
action: {
|
|
49
|
+
type: "string",
|
|
50
|
+
enum: ["list", "download", "upload"],
|
|
51
|
+
description: "Attachment operation: list, download, or upload",
|
|
52
|
+
},
|
|
53
|
+
table: {
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Table name (required for list and upload)",
|
|
56
|
+
},
|
|
57
|
+
sys_id: {
|
|
58
|
+
type: "string",
|
|
59
|
+
description: "Record sys_id (required for list and upload)",
|
|
60
|
+
},
|
|
61
|
+
attachment_sys_id: {
|
|
62
|
+
type: "string",
|
|
63
|
+
description: "Attachment sys_id (required for download)",
|
|
64
|
+
},
|
|
65
|
+
output_path: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Local file path to save downloaded attachment",
|
|
68
|
+
},
|
|
69
|
+
file_path: {
|
|
70
|
+
type: "string",
|
|
71
|
+
description: "Local file path to upload",
|
|
72
|
+
},
|
|
73
|
+
content_type: {
|
|
74
|
+
type: "string",
|
|
75
|
+
description: "MIME type for upload (default: application/octet-stream)",
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
required: ["action"],
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
exports.schema = zod_1.z.object({
|
|
82
|
+
action: zod_1.z.enum(["list", "download", "upload"]),
|
|
83
|
+
table: zod_1.z.string().optional(),
|
|
84
|
+
sys_id: zod_1.z.string().optional(),
|
|
85
|
+
attachment_sys_id: zod_1.z.string().optional(),
|
|
86
|
+
output_path: zod_1.z.string().optional(),
|
|
87
|
+
file_path: zod_1.z.string().optional(),
|
|
88
|
+
content_type: zod_1.z.string().optional(),
|
|
89
|
+
});
|
|
90
|
+
async function handler(args, client, _config) {
|
|
91
|
+
try {
|
|
92
|
+
switch (args.action) {
|
|
93
|
+
case "list": {
|
|
94
|
+
if (!args.table || !args.sys_id) {
|
|
95
|
+
return (0, utils_js_1.err)("table and sys_id are required for listing attachments");
|
|
96
|
+
}
|
|
97
|
+
const resp = await client.get("/api/now/attachment", {
|
|
98
|
+
sysparm_query: `table_name=${args.table}^table_sys_id=${args.sys_id}`,
|
|
99
|
+
});
|
|
100
|
+
const attachments = (resp.result || []).map((a) => ({
|
|
101
|
+
sys_id: a.sys_id,
|
|
102
|
+
file_name: a.file_name,
|
|
103
|
+
size_bytes: a.size_bytes,
|
|
104
|
+
content_type: a.content_type,
|
|
105
|
+
download_link: a.download_link,
|
|
106
|
+
}));
|
|
107
|
+
return (0, utils_js_1.ok)(attachments);
|
|
108
|
+
}
|
|
109
|
+
case "download": {
|
|
110
|
+
if (!args.attachment_sys_id) {
|
|
111
|
+
return (0, utils_js_1.err)("attachment_sys_id is required for download");
|
|
112
|
+
}
|
|
113
|
+
if (!args.output_path) {
|
|
114
|
+
return (0, utils_js_1.err)("output_path is required for download");
|
|
115
|
+
}
|
|
116
|
+
const { data } = await client.getRaw(`/api/now/attachment/${args.attachment_sys_id}/file`);
|
|
117
|
+
fs.writeFileSync(args.output_path, data);
|
|
118
|
+
return (0, utils_js_1.ok)({
|
|
119
|
+
status: "downloaded",
|
|
120
|
+
path: args.output_path,
|
|
121
|
+
size_bytes: data.length,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
case "upload": {
|
|
125
|
+
if (!args.table || !args.sys_id || !args.file_path) {
|
|
126
|
+
return (0, utils_js_1.err)("table, sys_id, and file_path are required for upload");
|
|
127
|
+
}
|
|
128
|
+
if (!fs.existsSync(args.file_path)) {
|
|
129
|
+
return (0, utils_js_1.err)(`File not found: ${args.file_path}`);
|
|
130
|
+
}
|
|
131
|
+
const filename = path.basename(args.file_path);
|
|
132
|
+
const data = fs.readFileSync(args.file_path);
|
|
133
|
+
const contentType = args.content_type || "application/octet-stream";
|
|
134
|
+
const resp = await client.postBinary("/api/now/attachment/file", data, contentType, {
|
|
135
|
+
table_name: args.table,
|
|
136
|
+
table_sys_id: args.sys_id,
|
|
137
|
+
file_name: filename,
|
|
138
|
+
});
|
|
139
|
+
const result = resp.result || {};
|
|
140
|
+
return (0, utils_js_1.ok)({
|
|
141
|
+
sys_id: result.sys_id,
|
|
142
|
+
file_name: result.file_name,
|
|
143
|
+
size_bytes: result.size_bytes,
|
|
144
|
+
table_name: result.table_name,
|
|
145
|
+
table_sys_id: result.table_sys_id,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return (0, utils_js_1.err)(`Unknown attachment action: ${args.action}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
return (0, utils_js_1.err)((0, utils_js_1.formatError)(error));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=attach.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attach.js","sourceRoot":"","sources":["../../src/tools/attach.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,0BAiFC;AA3ID,6BAAwB;AAGxB,0CAAmD;AACnD,uCAAyB;AACzB,2CAA6B;AAEhB,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,WAAW;IACjB,WAAW,EACT,kFAAkF;IACpF,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC;gBACpC,WAAW,EAAE,iDAAiD;aAC/D;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,2CAA2C;aACzD;YACD,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,8CAA8C;aAC5D;YACD,iBAAiB,EAAE;gBACjB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,2CAA2C;aACzD;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+CAA+C;aAC7D;YACD,SAAS,EAAE;gBACT,IAAI,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AAC,EAAE,CAAC;oBACnC,OAAO,IAAA,cAAG,EAAC,mBAAmB,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;gBAClD,CAAC;gBACD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC/C,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,IAAI,0BAA0B,CAAC;gBAEpE,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,UAAU,CAClC,0BAA0B,EAC1B,IAAI,EACJ,WAAW,EACX;oBACE,UAAU,EAAE,IAAI,CAAC,KAAK;oBACtB,YAAY,EAAE,IAAI,CAAC,MAAM;oBACzB,SAAS,EAAE,QAAQ;iBACpB,CACF,CAAC;gBACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;gBACjC,OAAO,IAAA,aAAE,EAAC;oBACR,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,SAAS,EAAE,MAAM,CAAC,SAAS;oBAC3B,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,YAAY,EAAE,MAAM,CAAC,YAAY;iBAClC,CAAC,CAAC;YACL,CAAC;YAED;gBACE,OAAO,IAAA,cAAG,EAAC,8BAA8B,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5D,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAA,cAAG,EAAC,IAAA,sBAAW,EAAC,KAAK,CAAC,CAAC,CAAC;IACjC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ServiceNowClient } from "../client.js";
|
|
3
|
+
import { ServiceNowConfig } from "../config.js";
|
|
4
|
+
export declare const definition: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: {
|
|
10
|
+
table: {
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
query: {
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
action: {
|
|
19
|
+
type: string;
|
|
20
|
+
enum: string[];
|
|
21
|
+
description: string;
|
|
22
|
+
};
|
|
23
|
+
fields: {
|
|
24
|
+
type: string;
|
|
25
|
+
description: string;
|
|
26
|
+
additionalProperties: boolean;
|
|
27
|
+
};
|
|
28
|
+
limit: {
|
|
29
|
+
type: string;
|
|
30
|
+
description: string;
|
|
31
|
+
};
|
|
32
|
+
confirm: {
|
|
33
|
+
type: string;
|
|
34
|
+
description: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
required: string[];
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export declare const schema: z.ZodObject<{
|
|
41
|
+
table: z.ZodString;
|
|
42
|
+
query: z.ZodString;
|
|
43
|
+
action: z.ZodEnum<["update", "delete"]>;
|
|
44
|
+
fields: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
45
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
46
|
+
confirm: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
table: string;
|
|
49
|
+
query: string;
|
|
50
|
+
limit: number;
|
|
51
|
+
confirm: boolean;
|
|
52
|
+
action: "update" | "delete";
|
|
53
|
+
fields?: Record<string, unknown> | undefined;
|
|
54
|
+
}, {
|
|
55
|
+
table: string;
|
|
56
|
+
query: string;
|
|
57
|
+
action: "update" | "delete";
|
|
58
|
+
fields?: Record<string, unknown> | undefined;
|
|
59
|
+
limit?: number | undefined;
|
|
60
|
+
confirm?: boolean | undefined;
|
|
61
|
+
}>;
|
|
62
|
+
export declare function handler(args: z.infer<typeof schema>, client: ServiceNowClient, _config: ServiceNowConfig): Promise<{
|
|
63
|
+
content: Array<{
|
|
64
|
+
type: "text";
|
|
65
|
+
text: string;
|
|
66
|
+
}>;
|
|
67
|
+
}>;
|
|
68
|
+
//# sourceMappingURL=batch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"batch.d.ts","sourceRoot":"","sources":["../../src/tools/batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCtB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;EAOjB,CAAC;AAEH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,EAC5B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,gBAAgB;;;;;GA8E1B"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.definition = void 0;
|
|
4
|
+
exports.handler = handler;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
exports.definition = {
|
|
8
|
+
name: "sn_batch",
|
|
9
|
+
description: "Bulk update or delete records matching a query. Runs in dry-run mode by default — set confirm to true to execute. Safety cap at 10,000 records.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
table: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "ServiceNow table name",
|
|
16
|
+
},
|
|
17
|
+
query: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Encoded query to select records (required — refuses to operate on all records)",
|
|
20
|
+
},
|
|
21
|
+
action: {
|
|
22
|
+
type: "string",
|
|
23
|
+
enum: ["update", "delete"],
|
|
24
|
+
description: "Operation to perform: update or delete",
|
|
25
|
+
},
|
|
26
|
+
fields: {
|
|
27
|
+
type: "object",
|
|
28
|
+
description: 'JSON fields to set on each record (required for update action). e.g. {"state":"7","close_notes":"Bulk closed"}',
|
|
29
|
+
additionalProperties: true,
|
|
30
|
+
},
|
|
31
|
+
limit: {
|
|
32
|
+
type: "number",
|
|
33
|
+
description: "Max records to affect (default 200, safety cap 10000)",
|
|
34
|
+
},
|
|
35
|
+
confirm: {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
description: "Set to true to actually execute. Default is dry-run.",
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ["table", "query", "action"],
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
exports.schema = zod_1.z.object({
|
|
44
|
+
table: zod_1.z.string(),
|
|
45
|
+
query: zod_1.z.string(),
|
|
46
|
+
action: zod_1.z.enum(["update", "delete"]),
|
|
47
|
+
fields: zod_1.z.record(zod_1.z.unknown()).optional(),
|
|
48
|
+
limit: zod_1.z.number().optional().default(200),
|
|
49
|
+
confirm: zod_1.z.boolean().optional().default(false),
|
|
50
|
+
});
|
|
51
|
+
async function handler(args, client, _config) {
|
|
52
|
+
try {
|
|
53
|
+
if (args.action === "update" && !args.fields) {
|
|
54
|
+
return (0, utils_js_1.err)("--fields is required for update action");
|
|
55
|
+
}
|
|
56
|
+
const limit = Math.min(args.limit, 10000);
|
|
57
|
+
// Step 1: Query matching records (sys_id only)
|
|
58
|
+
const resp = await client.get(`/api/now/table/${args.table}`, {
|
|
59
|
+
sysparm_fields: "sys_id",
|
|
60
|
+
sysparm_limit: String(limit),
|
|
61
|
+
sysparm_query: args.query,
|
|
62
|
+
});
|
|
63
|
+
const results = resp.result || [];
|
|
64
|
+
const matched = results.length;
|
|
65
|
+
// Step 2: Dry-run?
|
|
66
|
+
if (!args.confirm) {
|
|
67
|
+
return (0, utils_js_1.ok)({
|
|
68
|
+
action: args.action,
|
|
69
|
+
table: args.table,
|
|
70
|
+
matched,
|
|
71
|
+
dry_run: true,
|
|
72
|
+
message: "Dry run — no changes made. Set confirm to true to execute.",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (matched === 0) {
|
|
76
|
+
return (0, utils_js_1.ok)({
|
|
77
|
+
action: args.action,
|
|
78
|
+
table: args.table,
|
|
79
|
+
matched: 0,
|
|
80
|
+
processed: 0,
|
|
81
|
+
failed: 0,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
// Step 3: Execute
|
|
85
|
+
let processed = 0;
|
|
86
|
+
let failed = 0;
|
|
87
|
+
for (const record of results) {
|
|
88
|
+
const sysId = record.sys_id;
|
|
89
|
+
try {
|
|
90
|
+
if (args.action === "update") {
|
|
91
|
+
await client.patch(`/api/now/table/${args.table}/${sysId}`, args.fields);
|
|
92
|
+
processed++;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
const delResp = await client.delete(`/api/now/table/${args.table}/${sysId}`);
|
|
96
|
+
if (delResp.status === 204 || delResp.status === 200) {
|
|
97
|
+
processed++;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
failed++;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
failed++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return (0, utils_js_1.ok)({
|
|
109
|
+
action: args.action,
|
|
110
|
+
table: args.table,
|
|
111
|
+
matched,
|
|
112
|
+
processed,
|
|
113
|
+
failed,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
return (0, utils_js_1.err)((0, utils_js_1.formatError)(error));
|
|
118
|
+
}
|
|
119
|
+
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C"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ServiceNowClient } from "../client.js";
|
|
3
|
+
import { ServiceNowConfig } from "../config.js";
|
|
4
|
+
export declare const definition: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: {
|
|
10
|
+
search_term: {
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
table: {
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
};
|
|
18
|
+
field: {
|
|
19
|
+
type: string;
|
|
20
|
+
description: string;
|
|
21
|
+
};
|
|
22
|
+
limit: {
|
|
23
|
+
type: string;
|
|
24
|
+
description: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
required: string[];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export declare const schema: z.ZodObject<{
|
|
31
|
+
search_term: z.ZodString;
|
|
32
|
+
table: z.ZodOptional<z.ZodString>;
|
|
33
|
+
field: z.ZodOptional<z.ZodString>;
|
|
34
|
+
limit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
limit: number;
|
|
37
|
+
search_term: string;
|
|
38
|
+
table?: string | undefined;
|
|
39
|
+
field?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
search_term: string;
|
|
42
|
+
table?: string | undefined;
|
|
43
|
+
limit?: number | undefined;
|
|
44
|
+
field?: string | undefined;
|
|
45
|
+
}>;
|
|
46
|
+
export declare function handler(args: z.infer<typeof schema>, client: ServiceNowClient, _config: ServiceNowConfig): Promise<{
|
|
47
|
+
content: Array<{
|
|
48
|
+
type: "text";
|
|
49
|
+
text: string;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=codesearch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codesearch.d.ts","sourceRoot":"","sources":["../../src/tools/codesearch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;CA2BtB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;EAKjB,CAAC;AAQH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,EAC5B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,gBAAgB;;;;;GAqD1B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = exports.definition = void 0;
|
|
4
|
+
exports.handler = handler;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const utils_js_1 = require("../utils.js");
|
|
7
|
+
exports.definition = {
|
|
8
|
+
name: "sn_codesearch",
|
|
9
|
+
description: "Search across ServiceNow code artifacts — business rules, script includes, UI scripts, client scripts, and scripted REST operations. Returns matching records with code snippets.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {
|
|
13
|
+
search_term: {
|
|
14
|
+
type: "string",
|
|
15
|
+
description: "Text to search for in script fields",
|
|
16
|
+
},
|
|
17
|
+
table: {
|
|
18
|
+
type: "string",
|
|
19
|
+
description: "Search a specific table only (default: searches all code tables). Options: sys_script, sys_script_include, sys_ui_script, sys_script_client, sys_ws_operation",
|
|
20
|
+
},
|
|
21
|
+
field: {
|
|
22
|
+
type: "string",
|
|
23
|
+
description: "Specific field to search (default: script)",
|
|
24
|
+
},
|
|
25
|
+
limit: {
|
|
26
|
+
type: "number",
|
|
27
|
+
description: "Max total results (default 20)",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ["search_term"],
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
exports.schema = zod_1.z.object({
|
|
34
|
+
search_term: zod_1.z.string(),
|
|
35
|
+
table: zod_1.z.string().optional(),
|
|
36
|
+
field: zod_1.z.string().optional(),
|
|
37
|
+
limit: zod_1.z.number().optional().default(20),
|
|
38
|
+
});
|
|
39
|
+
async function handler(args, client, _config) {
|
|
40
|
+
try {
|
|
41
|
+
const targets = args.table
|
|
42
|
+
? [{ table: args.table, field: args.field || "script", label: args.table }]
|
|
43
|
+
: [
|
|
44
|
+
{ table: "sys_script", field: "script", label: "Business Rules" },
|
|
45
|
+
{ table: "sys_script_include", field: "script", label: "Script Includes" },
|
|
46
|
+
{ table: "sys_ui_script", field: "script", label: "UI Scripts" },
|
|
47
|
+
{ table: "sys_script_client", field: "script", label: "Client Scripts" },
|
|
48
|
+
{ table: "sys_ws_operation", field: "operation_script", label: "Scripted REST" },
|
|
49
|
+
];
|
|
50
|
+
const numTargets = targets.length;
|
|
51
|
+
const perTableLimit = numTargets > 1
|
|
52
|
+
? Math.max(5, Math.ceil(args.limit / numTargets))
|
|
53
|
+
: args.limit;
|
|
54
|
+
let allResults = [];
|
|
55
|
+
for (const target of targets) {
|
|
56
|
+
try {
|
|
57
|
+
const resp = await client.get(`/api/now/table/${target.table}`, {
|
|
58
|
+
sysparm_query: `${target.field}LIKE${args.search_term}`,
|
|
59
|
+
sysparm_fields: `sys_id,name,${target.field}`,
|
|
60
|
+
sysparm_limit: String(perTableLimit),
|
|
61
|
+
});
|
|
62
|
+
const records = resp.result || [];
|
|
63
|
+
for (const r of records) {
|
|
64
|
+
allResults.push({
|
|
65
|
+
table: target.table,
|
|
66
|
+
table_label: target.label,
|
|
67
|
+
sys_id: r.sys_id,
|
|
68
|
+
name: r.name || "unnamed",
|
|
69
|
+
snippet: r[target.field]
|
|
70
|
+
? (0, utils_js_1.truncate)(String(r[target.field]), 200)
|
|
71
|
+
: "",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Skip tables that fail (ACL issues, etc.)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
// Trim to requested limit
|
|
80
|
+
allResults = allResults.slice(0, args.limit);
|
|
81
|
+
return (0, utils_js_1.ok)(allResults);
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
return (0, utils_js_1.err)((0, utils_js_1.formatError)(error));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=codesearch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codesearch.js","sourceRoot":"","sources":["../../src/tools/codesearch.ts"],"names":[],"mappings":";;;AA+CA,0BAwDC;AAvGD,6BAAwB;AAGxB,0CAA6D;AAEhD,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,eAAe;IACrB,WAAW,EACT,mLAAmL;IACrL,WAAW,EAAE;QACX,IAAI,EAAE,QAAiB;QACvB,UAAU,EAAE;YACV,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,qCAAqC;aACnD;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EACT,+JAA+J;aAClK;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,4CAA4C;aAC1D;YACD,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAC9C;SACF;QACD,QAAQ,EAAE,CAAC,aAAa,CAAC;KAC1B;CACF,CAAC;AAEW,QAAA,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC;IAC7B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAA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
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { ServiceNowClient } from "../client.js";
|
|
3
|
+
import { ServiceNowConfig } from "../config.js";
|
|
4
|
+
export declare const definition: {
|
|
5
|
+
name: string;
|
|
6
|
+
description: string;
|
|
7
|
+
inputSchema: {
|
|
8
|
+
type: "object";
|
|
9
|
+
properties: {
|
|
10
|
+
table: {
|
|
11
|
+
type: string;
|
|
12
|
+
description: string;
|
|
13
|
+
};
|
|
14
|
+
fields: {
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
additionalProperties: boolean;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
required: string[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
export declare const schema: z.ZodObject<{
|
|
24
|
+
table: z.ZodString;
|
|
25
|
+
fields: z.ZodRecord<z.ZodString, z.ZodUnknown>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
table: string;
|
|
28
|
+
fields: Record<string, unknown>;
|
|
29
|
+
}, {
|
|
30
|
+
table: string;
|
|
31
|
+
fields: Record<string, unknown>;
|
|
32
|
+
}>;
|
|
33
|
+
export declare function handler(args: z.infer<typeof schema>, client: ServiceNowClient, _config: ServiceNowConfig): Promise<{
|
|
34
|
+
content: Array<{
|
|
35
|
+
type: "text";
|
|
36
|
+
text: string;
|
|
37
|
+
}>;
|
|
38
|
+
}>;
|
|
39
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/tools/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAGhD,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;CAoBtB,CAAC;AAEF,eAAO,MAAM,MAAM;;;;;;;;;EAGjB,CAAC;AAEH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,EAC5B,MAAM,EAAE,gBAAgB,EACxB,OAAO,EAAE,gBAAgB;;;;;GAa1B"}
|