snow-flow 8.41.1 → 8.41.2
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/package.json +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts +0 -15
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.js +0 -393
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.js.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.d.ts +0 -15
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.d.ts.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.js +0 -267
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.js.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts +0 -15
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.js +0 -311
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.js.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/deployment/snow_deploy.d.ts +0 -12
- package/dist/mcp/servicenow-mcp-unified/tools/deployment/snow_deploy.d.ts.map +0 -1
- package/dist/mcp/servicenow-mcp-unified/tools/deployment/snow_deploy.js +0 -375
- package/dist/mcp/servicenow-mcp-unified/tools/deployment/snow_deploy.js.map +0 -1
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* snow_execute_script_sync - Synchronous script execution
|
|
4
|
-
*
|
|
5
|
-
* Executes server-side JavaScript in ServiceNow using Fix Scripts.
|
|
6
|
-
* Creates a temporary Fix Script, runs it, captures output, and cleans up.
|
|
7
|
-
*
|
|
8
|
-
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
9
|
-
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.author = exports.version = exports.toolDefinition = void 0;
|
|
13
|
-
exports.execute = execute;
|
|
14
|
-
const auth_js_1 = require("../../shared/auth.js");
|
|
15
|
-
const error_handler_js_1 = require("../../shared/error-handler.js");
|
|
16
|
-
exports.toolDefinition = {
|
|
17
|
-
name: 'snow_execute_script_sync',
|
|
18
|
-
description: 'Execute script synchronously using Fix Scripts with output capture (ES5 only)',
|
|
19
|
-
// Metadata for tool discovery (not sent to LLM)
|
|
20
|
-
category: 'automation',
|
|
21
|
-
subcategory: 'script-execution',
|
|
22
|
-
use_cases: ['automation', 'scripts', 'synchronous'],
|
|
23
|
-
complexity: 'intermediate',
|
|
24
|
-
frequency: 'medium',
|
|
25
|
-
// Permission enforcement
|
|
26
|
-
// Classification: WRITE - Execution operation - can have side effects
|
|
27
|
-
permission: 'write',
|
|
28
|
-
allowedRoles: ['developer', 'admin'],
|
|
29
|
-
inputSchema: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
script: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
description: '🚨 ES5 ONLY! No const/let/arrows/templates. JavaScript code to execute synchronously.'
|
|
35
|
-
},
|
|
36
|
-
timeout: {
|
|
37
|
-
type: 'number',
|
|
38
|
-
description: 'Timeout in milliseconds (for polling)',
|
|
39
|
-
default: 30000
|
|
40
|
-
},
|
|
41
|
-
capture_output: {
|
|
42
|
-
type: 'boolean',
|
|
43
|
-
description: 'Capture and return output from gs.print/info/warn/error',
|
|
44
|
-
default: true
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
required: ['script']
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
async function execute(args, context) {
|
|
51
|
-
const { script, timeout = 30000, capture_output = true } = args;
|
|
52
|
-
try {
|
|
53
|
-
// ES5 validation first
|
|
54
|
-
const es5Validation = validateES5(script);
|
|
55
|
-
if (!es5Validation.valid) {
|
|
56
|
-
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.ES5_SYNTAX_ERROR, 'Script contains non-ES5 syntax', {
|
|
57
|
-
retryable: false,
|
|
58
|
-
details: {
|
|
59
|
-
violations: es5Validation.violations,
|
|
60
|
-
message: 'ServiceNow uses Rhino engine - ES6+ syntax will fail'
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
const client = await (0, auth_js_1.getAuthenticatedClient)(context);
|
|
65
|
-
// Create execution ID for tracking
|
|
66
|
-
const executionId = `sync_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
67
|
-
const outputMarker = `SNOW_FLOW_OUTPUT_${executionId}`;
|
|
68
|
-
// Wrap script with output capture
|
|
69
|
-
const wrappedScript = `
|
|
70
|
-
// Snow-Flow Script Execution - ID: ${executionId}
|
|
71
|
-
var __snowFlowOutput = [];
|
|
72
|
-
var __snowFlowStartTime = new GlideDateTime();
|
|
73
|
-
var __snowFlowResult = null;
|
|
74
|
-
var __snowFlowError = null;
|
|
75
|
-
|
|
76
|
-
// Capture gs output methods
|
|
77
|
-
var __origPrint = gs.print;
|
|
78
|
-
var __origInfo = gs.info;
|
|
79
|
-
var __origWarn = gs.warn;
|
|
80
|
-
var __origError = gs.error;
|
|
81
|
-
|
|
82
|
-
gs.print = function(msg) { __snowFlowOutput.push({level: 'print', msg: String(msg)}); __origPrint(msg); };
|
|
83
|
-
gs.info = function(msg) { __snowFlowOutput.push({level: 'info', msg: String(msg)}); __origInfo(msg); };
|
|
84
|
-
gs.warn = function(msg) { __snowFlowOutput.push({level: 'warn', msg: String(msg)}); __origWarn(msg); };
|
|
85
|
-
gs.error = function(msg) { __snowFlowOutput.push({level: 'error', msg: String(msg)}); __origError(msg); };
|
|
86
|
-
|
|
87
|
-
try {
|
|
88
|
-
__snowFlowResult = (function() {
|
|
89
|
-
${script}
|
|
90
|
-
})();
|
|
91
|
-
} catch(e) {
|
|
92
|
-
__snowFlowError = e.toString();
|
|
93
|
-
gs.error('Script Error: ' + e.toString());
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Restore original methods
|
|
97
|
-
gs.print = __origPrint;
|
|
98
|
-
gs.info = __origInfo;
|
|
99
|
-
gs.warn = __origWarn;
|
|
100
|
-
gs.error = __origError;
|
|
101
|
-
|
|
102
|
-
// Calculate execution time
|
|
103
|
-
var __snowFlowEndTime = new GlideDateTime();
|
|
104
|
-
var __snowFlowExecTime = GlideDateTime.subtract(__snowFlowStartTime, __snowFlowEndTime).getNumericValue();
|
|
105
|
-
|
|
106
|
-
// Store result in system property for retrieval
|
|
107
|
-
var __snowFlowResultObj = {
|
|
108
|
-
executionId: '${executionId}',
|
|
109
|
-
success: __snowFlowError === null,
|
|
110
|
-
result: __snowFlowResult,
|
|
111
|
-
error: __snowFlowError,
|
|
112
|
-
output: __snowFlowOutput,
|
|
113
|
-
executionTimeMs: Math.abs(__snowFlowExecTime)
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
gs.setProperty('${outputMarker}', JSON.stringify(__snowFlowResultObj));
|
|
117
|
-
gs.info('${outputMarker}:COMPLETE');
|
|
118
|
-
`;
|
|
119
|
-
// Step 1: Create a Scheduled Script Job (sysauto_script) record
|
|
120
|
-
const jobName = `Snow-Flow Exec - ${executionId}`;
|
|
121
|
-
const createResponse = await client.post('/api/now/table/sysauto_script', {
|
|
122
|
-
name: jobName,
|
|
123
|
-
script: wrappedScript,
|
|
124
|
-
active: true,
|
|
125
|
-
run_type: 'on_demand', // On-demand job type
|
|
126
|
-
conditional: false
|
|
127
|
-
});
|
|
128
|
-
if (!createResponse.data?.result?.sys_id) {
|
|
129
|
-
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.SERVICENOW_API_ERROR, 'Failed to create scheduled script job', { details: createResponse.data });
|
|
130
|
-
}
|
|
131
|
-
const jobSysId = createResponse.data.result.sys_id;
|
|
132
|
-
// Step 2: Create a sys_trigger record to execute the job immediately
|
|
133
|
-
// This is how ServiceNow executes scheduled jobs on demand
|
|
134
|
-
const now = new Date();
|
|
135
|
-
const triggerTime = new Date(now.getTime() + 2000); // 2 seconds from now
|
|
136
|
-
const triggerTimeStr = triggerTime.toISOString().replace('T', ' ').substring(0, 19);
|
|
137
|
-
try {
|
|
138
|
-
await client.post('/api/now/table/sys_trigger', {
|
|
139
|
-
name: jobName,
|
|
140
|
-
next_action: triggerTimeStr,
|
|
141
|
-
trigger_type: 0, // 0 = Run Once
|
|
142
|
-
state: 0, // 0 = Ready
|
|
143
|
-
document: 'sysauto_script',
|
|
144
|
-
document_key: jobSysId,
|
|
145
|
-
claimed_by: '',
|
|
146
|
-
system_id: 'snow-flow'
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
catch (triggerError) {
|
|
150
|
-
// If sys_trigger creation fails (permissions), the job won't auto-execute
|
|
151
|
-
// Continue anyway - we'll detect this in polling
|
|
152
|
-
}
|
|
153
|
-
// Step 3: Poll for completion by checking the system property
|
|
154
|
-
const startTime = Date.now();
|
|
155
|
-
let result = null;
|
|
156
|
-
let attempts = 0;
|
|
157
|
-
const maxAttempts = Math.ceil(timeout / 2000);
|
|
158
|
-
while (Date.now() - startTime < timeout && attempts < maxAttempts) {
|
|
159
|
-
attempts++;
|
|
160
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
161
|
-
try {
|
|
162
|
-
// Check sys_properties for our output marker
|
|
163
|
-
const propResponse = await client.get('/api/now/table/sys_properties', {
|
|
164
|
-
params: {
|
|
165
|
-
sysparm_query: `name=${outputMarker}`,
|
|
166
|
-
sysparm_fields: 'value',
|
|
167
|
-
sysparm_limit: 1
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
if (propResponse.data?.result?.[0]?.value) {
|
|
171
|
-
try {
|
|
172
|
-
result = JSON.parse(propResponse.data.result[0].value);
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
catch (parseErr) {
|
|
176
|
-
// Continue polling
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
catch (pollError) {
|
|
181
|
-
// Continue polling
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Step 4: Cleanup - delete the scheduled job and property
|
|
185
|
-
try {
|
|
186
|
-
await client.delete(`/api/now/table/sysauto_script/${jobSysId}`);
|
|
187
|
-
}
|
|
188
|
-
catch (cleanupError) {
|
|
189
|
-
// Ignore cleanup errors
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
// Delete the output property
|
|
193
|
-
const propDeleteResponse = await client.get('/api/now/table/sys_properties', {
|
|
194
|
-
params: {
|
|
195
|
-
sysparm_query: `name=${outputMarker}`,
|
|
196
|
-
sysparm_fields: 'sys_id',
|
|
197
|
-
sysparm_limit: 1
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
if (propDeleteResponse.data?.result?.[0]?.sys_id) {
|
|
201
|
-
await client.delete(`/api/now/table/sys_properties/${propDeleteResponse.data.result[0].sys_id}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
catch (propCleanupError) {
|
|
205
|
-
// Ignore cleanup errors
|
|
206
|
-
}
|
|
207
|
-
// Step 5: Return results
|
|
208
|
-
if (result) {
|
|
209
|
-
return (0, error_handler_js_1.createSuccessResult)({
|
|
210
|
-
execution_id: executionId,
|
|
211
|
-
success: result.success,
|
|
212
|
-
result: result.result,
|
|
213
|
-
error: result.error,
|
|
214
|
-
output: capture_output ? result.output : undefined,
|
|
215
|
-
execution_time_ms: result.executionTimeMs
|
|
216
|
-
}, {
|
|
217
|
-
operation: 'sync_script_execution',
|
|
218
|
-
method: 'sysauto_script_with_trigger'
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
else {
|
|
222
|
-
// Script may not have run or output wasn't captured
|
|
223
|
-
return (0, error_handler_js_1.createSuccessResult)({
|
|
224
|
-
execution_id: executionId,
|
|
225
|
-
success: true,
|
|
226
|
-
result: null,
|
|
227
|
-
message: 'Script was saved but execution could not be confirmed. The sys_trigger may not have been created (permissions) or the scheduler has not yet picked it up.',
|
|
228
|
-
scheduled_job_sys_id: jobSysId,
|
|
229
|
-
manual_run_url: `Navigate to System Scheduler > Scheduled Jobs and run: ${jobName}`
|
|
230
|
-
}, {
|
|
231
|
-
operation: 'sync_script_execution',
|
|
232
|
-
method: 'scheduled_job_pending'
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
catch (error) {
|
|
237
|
-
return (0, error_handler_js_1.createErrorResult)(error instanceof error_handler_js_1.SnowFlowError
|
|
238
|
-
? error
|
|
239
|
-
: new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.UNKNOWN_ERROR, error.message, { originalError: error }));
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
function validateES5(code) {
|
|
243
|
-
const violations = [];
|
|
244
|
-
const patterns = [
|
|
245
|
-
{ regex: /\b(const|let)\s+/g, type: 'const/let', fix: "Use 'var'" },
|
|
246
|
-
{ regex: /\([^)]*\)\s*=>/g, type: 'arrow_function', fix: 'Use function() {}' },
|
|
247
|
-
{ regex: /`[^`]*`/g, type: 'template_literal', fix: 'Use string concatenation' },
|
|
248
|
-
{ regex: /\{[^}]+\}\s*=\s*/g, type: 'destructuring', fix: 'Use explicit properties' },
|
|
249
|
-
{ regex: /for\s*\([^)]*\s+of\s+/g, type: 'for_of', fix: 'Use traditional for loop' },
|
|
250
|
-
{ regex: /class\s+\w+/g, type: 'class', fix: 'Use function constructor' }
|
|
251
|
-
];
|
|
252
|
-
patterns.forEach(({ regex, type, fix }) => {
|
|
253
|
-
let match;
|
|
254
|
-
while ((match = regex.exec(code)) !== null) {
|
|
255
|
-
violations.push({
|
|
256
|
-
type,
|
|
257
|
-
line: code.substring(0, match.index).split('\n').length,
|
|
258
|
-
code: match[0],
|
|
259
|
-
fix
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
return { valid: violations.length === 0, violations };
|
|
264
|
-
}
|
|
265
|
-
exports.version = '1.0.0';
|
|
266
|
-
exports.author = 'Snow-Flow SDK Migration';
|
|
267
|
-
//# sourceMappingURL=snow_execute_script_sync.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_script_sync.js","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AA0CH,0BAoNC;AA3PD,kDAA8D;AAC9D,oEAAiH;AAEpG,QAAA,cAAc,GAAsB;IAC/C,IAAI,EAAE,0BAA0B;IAChC,WAAW,EAAE,+EAA+E;IAC5F,gDAAgD;IAChD,QAAQ,EAAE,YAAY;IACtB,WAAW,EAAE,kBAAkB;IAC/B,SAAS,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,aAAa,CAAC;IACnD,UAAU,EAAE,cAAc;IAC1B,SAAS,EAAE,QAAQ;IAEnB,yBAAyB;IACzB,sEAAsE;IACtE,UAAU,EAAE,OAAO;IACnB,YAAY,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;IACpC,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uFAAuF;aACrG;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uCAAuC;gBACpD,OAAO,EAAE,KAAK;aACf;YACD,cAAc,EAAE;gBACd,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,yDAAyD;gBACtE,OAAO,EAAE,IAAI;aACd;SACF;QACD,QAAQ,EAAE,CAAC,QAAQ,CAAC;KACrB;CACF,CAAC;AAEK,KAA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,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;AACxD,CAAC;AAEY,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,MAAM,GAAG,yBAAyB,CAAC"}
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* snow_execute_script_with_output - Execute scripts with full output capture
|
|
3
|
-
*
|
|
4
|
-
* Execute server-side JavaScript in ServiceNow with comprehensive output capture
|
|
5
|
-
* using Fix Scripts. Captures gs.print, gs.info, gs.warn, gs.error.
|
|
6
|
-
*
|
|
7
|
-
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
8
|
-
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
9
|
-
*/
|
|
10
|
-
import { MCPToolDefinition, ServiceNowContext, ToolResult } from '../../shared/types.js';
|
|
11
|
-
export declare const toolDefinition: MCPToolDefinition;
|
|
12
|
-
export declare function execute(args: any, context: ServiceNowContext): Promise<ToolResult>;
|
|
13
|
-
export declare const version = "1.0.0";
|
|
14
|
-
export declare const author = "Snow-Flow SDK Migration";
|
|
15
|
-
//# sourceMappingURL=snow_execute_script_with_output.d.ts.map
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_script_with_output.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIzF,eAAO,MAAM,cAAc,EAAE,iBAwC5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CA4PxF;AA6BD,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* snow_execute_script_with_output - Execute scripts with full output capture
|
|
4
|
-
*
|
|
5
|
-
* Execute server-side JavaScript in ServiceNow with comprehensive output capture
|
|
6
|
-
* using Fix Scripts. Captures gs.print, gs.info, gs.warn, gs.error.
|
|
7
|
-
*
|
|
8
|
-
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
9
|
-
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.author = exports.version = exports.toolDefinition = void 0;
|
|
13
|
-
exports.execute = execute;
|
|
14
|
-
const auth_js_1 = require("../../shared/auth.js");
|
|
15
|
-
const error_handler_js_1 = require("../../shared/error-handler.js");
|
|
16
|
-
exports.toolDefinition = {
|
|
17
|
-
name: 'snow_execute_script_with_output',
|
|
18
|
-
description: 'Execute server-side JavaScript with full output capture using Fix Scripts (ES5 only)',
|
|
19
|
-
// Metadata for tool discovery (not sent to LLM)
|
|
20
|
-
category: 'automation',
|
|
21
|
-
subcategory: 'script-execution',
|
|
22
|
-
use_cases: ['automation', 'scripts', 'output-capture'],
|
|
23
|
-
complexity: 'advanced',
|
|
24
|
-
frequency: 'high',
|
|
25
|
-
// Permission enforcement
|
|
26
|
-
// Classification: WRITE - Execution operation - can have side effects
|
|
27
|
-
permission: 'write',
|
|
28
|
-
allowedRoles: ['developer', 'admin'],
|
|
29
|
-
inputSchema: {
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
script: {
|
|
33
|
-
type: 'string',
|
|
34
|
-
description: 'JavaScript code to execute (MUST be ES5 - no const/let/arrow functions/template literals)'
|
|
35
|
-
},
|
|
36
|
-
scope: {
|
|
37
|
-
type: 'string',
|
|
38
|
-
description: 'Scope to execute in (global or application scope)',
|
|
39
|
-
default: 'global',
|
|
40
|
-
enum: ['global', 'rhino']
|
|
41
|
-
},
|
|
42
|
-
validate_es5: {
|
|
43
|
-
type: 'boolean',
|
|
44
|
-
description: 'Validate ES5 syntax before execution',
|
|
45
|
-
default: true
|
|
46
|
-
},
|
|
47
|
-
timeout: {
|
|
48
|
-
type: 'number',
|
|
49
|
-
description: 'Timeout in milliseconds for polling execution results',
|
|
50
|
-
default: 30000
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
required: ['script']
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
async function execute(args, context) {
|
|
57
|
-
const { script, scope = 'global', validate_es5 = true, timeout = 30000 } = args;
|
|
58
|
-
try {
|
|
59
|
-
// ES5 validation
|
|
60
|
-
if (validate_es5) {
|
|
61
|
-
const es5Validation = validateES5(script);
|
|
62
|
-
if (!es5Validation.valid) {
|
|
63
|
-
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.ES5_SYNTAX_ERROR, 'Script contains non-ES5 syntax', {
|
|
64
|
-
retryable: false,
|
|
65
|
-
details: {
|
|
66
|
-
violations: es5Validation.violations,
|
|
67
|
-
message: 'ServiceNow uses Rhino engine - ES6+ syntax will fail'
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
const client = await (0, auth_js_1.getAuthenticatedClient)(context);
|
|
73
|
-
// Create unique execution ID for tracking
|
|
74
|
-
const executionId = `output_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
75
|
-
const outputMarker = `SNOW_FLOW_EXEC_${executionId}`;
|
|
76
|
-
// Wrap script with comprehensive output capture
|
|
77
|
-
const wrappedScript = `
|
|
78
|
-
// Snow-Flow Script Execution with Output Capture - ID: ${executionId}
|
|
79
|
-
var __sfOutput = [];
|
|
80
|
-
var __sfStartTime = new GlideDateTime();
|
|
81
|
-
var __sfResult = null;
|
|
82
|
-
var __sfError = null;
|
|
83
|
-
|
|
84
|
-
// Store original gs methods
|
|
85
|
-
var __sfOrigPrint = gs.print;
|
|
86
|
-
var __sfOrigInfo = gs.info;
|
|
87
|
-
var __sfOrigWarn = gs.warn;
|
|
88
|
-
var __sfOrigError = gs.error;
|
|
89
|
-
|
|
90
|
-
// Override gs methods to capture output
|
|
91
|
-
gs.print = function(msg) {
|
|
92
|
-
var m = String(msg);
|
|
93
|
-
__sfOutput.push({level: 'print', message: m, timestamp: new GlideDateTime().getDisplayValue()});
|
|
94
|
-
__sfOrigPrint(m);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
gs.info = function(msg) {
|
|
98
|
-
var m = String(msg);
|
|
99
|
-
__sfOutput.push({level: 'info', message: m, timestamp: new GlideDateTime().getDisplayValue()});
|
|
100
|
-
__sfOrigInfo(m);
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
gs.warn = function(msg) {
|
|
104
|
-
var m = String(msg);
|
|
105
|
-
__sfOutput.push({level: 'warn', message: m, timestamp: new GlideDateTime().getDisplayValue()});
|
|
106
|
-
__sfOrigWarn(m);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
gs.error = function(msg) {
|
|
110
|
-
var m = String(msg);
|
|
111
|
-
__sfOutput.push({level: 'error', message: m, timestamp: new GlideDateTime().getDisplayValue()});
|
|
112
|
-
__sfOrigError(m);
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// Execute the user script
|
|
116
|
-
try {
|
|
117
|
-
gs.info('=== Snow-Flow Script Execution Started ===');
|
|
118
|
-
|
|
119
|
-
__sfResult = (function() {
|
|
120
|
-
${script}
|
|
121
|
-
})();
|
|
122
|
-
|
|
123
|
-
gs.info('=== Snow-Flow Script Execution Completed ===');
|
|
124
|
-
|
|
125
|
-
if (__sfResult !== undefined && __sfResult !== null) {
|
|
126
|
-
gs.info('Script returned: ' + (typeof __sfResult === 'object' ? JSON.stringify(__sfResult) : String(__sfResult)));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
} catch(e) {
|
|
130
|
-
__sfError = e.toString();
|
|
131
|
-
gs.error('=== Snow-Flow Script Execution Failed ===');
|
|
132
|
-
gs.error('Error: ' + e.toString());
|
|
133
|
-
if (e.stack) {
|
|
134
|
-
gs.error('Stack: ' + e.stack);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Restore original gs methods
|
|
139
|
-
gs.print = __sfOrigPrint;
|
|
140
|
-
gs.info = __sfOrigInfo;
|
|
141
|
-
gs.warn = __sfOrigWarn;
|
|
142
|
-
gs.error = __sfOrigError;
|
|
143
|
-
|
|
144
|
-
// Calculate execution time
|
|
145
|
-
var __sfEndTime = new GlideDateTime();
|
|
146
|
-
var __sfExecTimeMs = Math.abs(GlideDateTime.subtract(__sfStartTime, __sfEndTime).getNumericValue());
|
|
147
|
-
|
|
148
|
-
// Build result object
|
|
149
|
-
var __sfResultObj = {
|
|
150
|
-
executionId: '${executionId}',
|
|
151
|
-
success: __sfError === null,
|
|
152
|
-
result: __sfResult,
|
|
153
|
-
error: __sfError,
|
|
154
|
-
output: __sfOutput,
|
|
155
|
-
executionTimeMs: __sfExecTimeMs,
|
|
156
|
-
completedAt: __sfEndTime.getDisplayValue()
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
// Store result in system property for retrieval
|
|
160
|
-
gs.setProperty('${outputMarker}', JSON.stringify(__sfResultObj));
|
|
161
|
-
gs.info('${outputMarker}:DONE');
|
|
162
|
-
`;
|
|
163
|
-
// Step 1: Create Scheduled Script Job (sysauto_script)
|
|
164
|
-
const jobName = `Snow-Flow Output Capture - ${executionId}`;
|
|
165
|
-
const createResponse = await client.post('/api/now/table/sysauto_script', {
|
|
166
|
-
name: jobName,
|
|
167
|
-
script: wrappedScript,
|
|
168
|
-
active: true,
|
|
169
|
-
run_type: 'on_demand',
|
|
170
|
-
conditional: false
|
|
171
|
-
});
|
|
172
|
-
if (!createResponse.data?.result?.sys_id) {
|
|
173
|
-
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.SERVICENOW_API_ERROR, 'Failed to create scheduled script job', { details: createResponse.data });
|
|
174
|
-
}
|
|
175
|
-
const jobSysId = createResponse.data.result.sys_id;
|
|
176
|
-
// Step 2: Create sys_trigger to execute immediately
|
|
177
|
-
const now = new Date();
|
|
178
|
-
const triggerTime = new Date(now.getTime() + 2000); // 2 seconds from now
|
|
179
|
-
const triggerTimeStr = triggerTime.toISOString().replace('T', ' ').substring(0, 19);
|
|
180
|
-
try {
|
|
181
|
-
await client.post('/api/now/table/sys_trigger', {
|
|
182
|
-
name: jobName,
|
|
183
|
-
next_action: triggerTimeStr,
|
|
184
|
-
trigger_type: 0, // Run Once
|
|
185
|
-
state: 0, // Ready
|
|
186
|
-
document: 'sysauto_script',
|
|
187
|
-
document_key: jobSysId,
|
|
188
|
-
claimed_by: '',
|
|
189
|
-
system_id: 'snow-flow'
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
catch (triggerError) {
|
|
193
|
-
// If trigger creation fails, job won't auto-execute
|
|
194
|
-
}
|
|
195
|
-
// Step 3: Poll for execution results
|
|
196
|
-
const startTime = Date.now();
|
|
197
|
-
let result = null;
|
|
198
|
-
let attempts = 0;
|
|
199
|
-
const maxAttempts = Math.ceil(timeout / 2000);
|
|
200
|
-
while (Date.now() - startTime < timeout && attempts < maxAttempts) {
|
|
201
|
-
attempts++;
|
|
202
|
-
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
203
|
-
try {
|
|
204
|
-
// Check sys_properties for output marker
|
|
205
|
-
const propResponse = await client.get('/api/now/table/sys_properties', {
|
|
206
|
-
params: {
|
|
207
|
-
sysparm_query: `name=${outputMarker}`,
|
|
208
|
-
sysparm_fields: 'value,sys_id',
|
|
209
|
-
sysparm_limit: 1
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
if (propResponse.data?.result?.[0]?.value) {
|
|
213
|
-
try {
|
|
214
|
-
result = JSON.parse(propResponse.data.result[0].value);
|
|
215
|
-
// Delete the property after reading
|
|
216
|
-
const propSysId = propResponse.data.result[0].sys_id;
|
|
217
|
-
if (propSysId) {
|
|
218
|
-
await client.delete(`/api/now/table/sys_properties/${propSysId}`).catch(() => { });
|
|
219
|
-
}
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
catch (parseErr) {
|
|
223
|
-
// Continue polling
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
catch (pollError) {
|
|
228
|
-
// Continue polling
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Step 4: Cleanup - delete the scheduled job
|
|
232
|
-
try {
|
|
233
|
-
await client.delete(`/api/now/table/sysauto_script/${jobSysId}`);
|
|
234
|
-
}
|
|
235
|
-
catch (cleanupError) {
|
|
236
|
-
// Ignore cleanup errors
|
|
237
|
-
}
|
|
238
|
-
// Step 5: Format and return results
|
|
239
|
-
if (result) {
|
|
240
|
-
// Organize output by level
|
|
241
|
-
const organized = {
|
|
242
|
-
print: result.output.filter((o) => o.level === 'print').map((o) => o.message),
|
|
243
|
-
info: result.output.filter((o) => o.level === 'info').map((o) => o.message),
|
|
244
|
-
warn: result.output.filter((o) => o.level === 'warn').map((o) => o.message),
|
|
245
|
-
error: result.output.filter((o) => o.level === 'error').map((o) => o.message),
|
|
246
|
-
success: result.success
|
|
247
|
-
};
|
|
248
|
-
return (0, error_handler_js_1.createSuccessResult)({
|
|
249
|
-
success: result.success,
|
|
250
|
-
result: result.result,
|
|
251
|
-
error: result.error,
|
|
252
|
-
output: organized,
|
|
253
|
-
raw_output: result.output,
|
|
254
|
-
execution_time_ms: result.executionTimeMs,
|
|
255
|
-
execution_id: executionId
|
|
256
|
-
}, {
|
|
257
|
-
script_length: script.length,
|
|
258
|
-
scope,
|
|
259
|
-
es5_validated: validate_es5,
|
|
260
|
-
method: 'sysauto_script_with_trigger'
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
else {
|
|
264
|
-
// Script was saved but execution couldn't be confirmed
|
|
265
|
-
return (0, error_handler_js_1.createSuccessResult)({
|
|
266
|
-
success: true,
|
|
267
|
-
execution_id: executionId,
|
|
268
|
-
message: 'Script was saved as scheduled job but automatic execution could not be confirmed. The sys_trigger may not have been created (permissions) or the scheduler has not yet picked it up.',
|
|
269
|
-
scheduled_job_sys_id: jobSysId,
|
|
270
|
-
action_required: 'Navigate to System Scheduler > Scheduled Jobs and run the script manually',
|
|
271
|
-
script_name: jobName
|
|
272
|
-
}, {
|
|
273
|
-
script_length: script.length,
|
|
274
|
-
scope,
|
|
275
|
-
es5_validated: validate_es5,
|
|
276
|
-
method: 'scheduled_job_pending'
|
|
277
|
-
});
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (error) {
|
|
281
|
-
return (0, error_handler_js_1.createErrorResult)(error instanceof error_handler_js_1.SnowFlowError
|
|
282
|
-
? error
|
|
283
|
-
: new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.UNKNOWN_ERROR, error.message, { originalError: error }));
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
function validateES5(code) {
|
|
287
|
-
const violations = [];
|
|
288
|
-
const patterns = [
|
|
289
|
-
{ regex: /\b(const|let)\s+/g, type: 'const/let', fix: "Use 'var'" },
|
|
290
|
-
{ regex: /\([^)]*\)\s*=>/g, type: 'arrow_function', fix: 'Use function() {}' },
|
|
291
|
-
{ regex: /`[^`]*`/g, type: 'template_literal', fix: 'Use string concatenation' },
|
|
292
|
-
{ regex: /\{[^}]+\}\s*=\s*/g, type: 'destructuring', fix: 'Use explicit properties' },
|
|
293
|
-
{ regex: /for\s*\([^)]*\s+of\s+/g, type: 'for_of', fix: 'Use traditional for loop' },
|
|
294
|
-
{ regex: /class\s+\w+/g, type: 'class', fix: 'Use function constructor' }
|
|
295
|
-
];
|
|
296
|
-
patterns.forEach(({ regex, type, fix }) => {
|
|
297
|
-
let match;
|
|
298
|
-
while ((match = regex.exec(code)) !== null) {
|
|
299
|
-
violations.push({
|
|
300
|
-
type,
|
|
301
|
-
line: code.substring(0, match.index).split('\n').length,
|
|
302
|
-
code: match[0],
|
|
303
|
-
fix
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
return { valid: violations.length === 0, violations };
|
|
308
|
-
}
|
|
309
|
-
exports.version = '1.0.0';
|
|
310
|
-
exports.author = 'Snow-Flow SDK Migration';
|
|
311
|
-
//# sourceMappingURL=snow_execute_script_with_output.js.map
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_script_with_output.js","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAgDH,0BA4PC;AAzSD,kDAA8D;AAC9D,oEAAiH;AAEpG,QAAA,cAAc,GAAsB;IAC/C,IAAI,EAAE,iCAAiC;IACvC,WAAW,EAAE,sFAAsF;IACnG,gDAAgD;IAChD,QAAQ,EAAE,YAAY;IACtB,WAAW,EAAE,kBAAkB;IAC/B,SAAS,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,CAAC;IACtD,UAAU,EAAE,UAAU;IACtB,SAAS,EAAE,MAAM;IAEjB,yBAAyB;IACzB,sEAAsE;IACtE,UAAU,EAAE,OAAO;IACnB,YAAY,EAAE,CAAC,WAAW,EAAE,OAAO,CAAC;IACpC,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,2FAA2F;aACzG;YACD,KAAK,EAAE;gB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UAAU,EAAE,CAAC;AACxD,CAAC;AAEY,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,MAAM,GAAG,yBAAyB,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* snow_deploy - Deploy ServiceNow artifacts with validation
|
|
3
|
-
*
|
|
4
|
-
* Deploys widgets, pages, flows, and other artifacts to ServiceNow
|
|
5
|
-
* with automatic ES5 validation, coherence checking, and Update Set management.
|
|
6
|
-
*/
|
|
7
|
-
import { MCPToolDefinition, ServiceNowContext, ToolResult } from '../../shared/types.js';
|
|
8
|
-
export declare const toolDefinition: MCPToolDefinition;
|
|
9
|
-
export declare function execute(args: any, context: ServiceNowContext): Promise<ToolResult>;
|
|
10
|
-
export declare const version = "1.0.0";
|
|
11
|
-
export declare const author = "Snow-Flow SDK Migration";
|
|
12
|
-
//# sourceMappingURL=snow_deploy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"snow_deploy.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/deployment/snow_deploy.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIzF,eAAO,MAAM,cAAc,EAAE,iBA+D5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAuHxF;AA4OD,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,MAAM,4BAA4B,CAAC"}
|