snow-flow 8.39.13 → 8.39.14
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/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts +2 -2
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.js +171 -22
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.js.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.d.ts +2 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.d.ts.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.js +184 -47
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.js.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts +3 -3
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts.map +1 -1
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.js +194 -140
- package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.js.map +1 -1
- package/dist/utils/servicenow-client.d.ts +2 -1
- package/dist/utils/servicenow-client.d.ts.map +1 -1
- package/dist/utils/servicenow-client.js +98 -10
- package/dist/utils/servicenow-client.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* snow_execute_background_script - Execute background scripts with user confirmation
|
|
3
3
|
*
|
|
4
|
-
* Executes JavaScript background scripts in ServiceNow
|
|
5
|
-
* and user confirmation (unless autoConfirm=true).
|
|
4
|
+
* Executes JavaScript background scripts in ServiceNow using Fix Scripts.
|
|
5
|
+
* Includes security analysis and user confirmation (unless autoConfirm=true).
|
|
6
6
|
*
|
|
7
7
|
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
8
8
|
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_background_script.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIzF,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"snow_execute_background_script.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIzF,eAAO,MAAM,cAAc,EAAE,iBA+C5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAuOxF;AAqID,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,MAAM,4BAA4B,CAAC"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* snow_execute_background_script - Execute background scripts with user confirmation
|
|
4
4
|
*
|
|
5
|
-
* Executes JavaScript background scripts in ServiceNow
|
|
6
|
-
* and user confirmation (unless autoConfirm=true).
|
|
5
|
+
* Executes JavaScript background scripts in ServiceNow using Fix Scripts.
|
|
6
|
+
* Includes security analysis and user confirmation (unless autoConfirm=true).
|
|
7
7
|
*
|
|
8
8
|
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
9
9
|
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
@@ -15,7 +15,7 @@ const auth_js_1 = require("../../shared/auth.js");
|
|
|
15
15
|
const error_handler_js_1 = require("../../shared/error-handler.js");
|
|
16
16
|
exports.toolDefinition = {
|
|
17
17
|
name: 'snow_execute_background_script',
|
|
18
|
-
description: '🚨 REQUIRES USER CONFIRMATION (unless autoConfirm=true): Execute background script
|
|
18
|
+
description: '🚨 REQUIRES USER CONFIRMATION (unless autoConfirm=true): Execute background script using Fix Scripts (ES5 only)',
|
|
19
19
|
// Metadata for tool discovery (not sent to LLM)
|
|
20
20
|
category: 'automation',
|
|
21
21
|
subcategory: 'script-execution',
|
|
@@ -50,13 +50,18 @@ exports.toolDefinition = {
|
|
|
50
50
|
type: 'boolean',
|
|
51
51
|
description: '⚠️ DANGEROUS: Skip user confirmation and execute immediately',
|
|
52
52
|
default: false
|
|
53
|
+
},
|
|
54
|
+
timeout: {
|
|
55
|
+
type: 'number',
|
|
56
|
+
description: 'Timeout in milliseconds for polling execution results',
|
|
57
|
+
default: 30000
|
|
53
58
|
}
|
|
54
59
|
},
|
|
55
60
|
required: ['script', 'description']
|
|
56
61
|
}
|
|
57
62
|
};
|
|
58
63
|
async function execute(args, context) {
|
|
59
|
-
const { script, description, runAsUser, allowDataModification = false, autoConfirm = false } = args;
|
|
64
|
+
const { script, description, runAsUser, allowDataModification = false, autoConfirm = false, timeout = 30000 } = args;
|
|
60
65
|
try {
|
|
61
66
|
// ES5 validation
|
|
62
67
|
const es5Validation = validateES5(script);
|
|
@@ -71,27 +76,171 @@ async function execute(args, context) {
|
|
|
71
76
|
}
|
|
72
77
|
// Security analysis
|
|
73
78
|
const securityAnalysis = analyzeScriptSecurity(script);
|
|
74
|
-
// Auto-confirm mode - execute immediately
|
|
79
|
+
// Auto-confirm mode - execute immediately using Fix Scripts
|
|
75
80
|
if (autoConfirm === true) {
|
|
76
|
-
const executionId = `
|
|
81
|
+
const executionId = `bg_auto_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
82
|
+
const outputMarker = `SNOW_FLOW_BG_${executionId}`;
|
|
77
83
|
const client = await (0, auth_js_1.getAuthenticatedClient)(context);
|
|
78
|
-
//
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
84
|
+
// Wrap script with output capture
|
|
85
|
+
const wrappedScript = `
|
|
86
|
+
// Snow-Flow Background Script - ID: ${executionId}
|
|
87
|
+
// Description: ${description}
|
|
88
|
+
// Auto-confirmed execution
|
|
89
|
+
var __bgOutput = [];
|
|
90
|
+
var __bgStartTime = new GlideDateTime();
|
|
91
|
+
var __bgResult = null;
|
|
92
|
+
var __bgError = null;
|
|
93
|
+
|
|
94
|
+
// Capture gs methods
|
|
95
|
+
var __bgOrigPrint = gs.print;
|
|
96
|
+
var __bgOrigInfo = gs.info;
|
|
97
|
+
var __bgOrigWarn = gs.warn;
|
|
98
|
+
var __bgOrigError = gs.error;
|
|
99
|
+
|
|
100
|
+
gs.print = function(msg) { __bgOutput.push({level: 'print', msg: String(msg)}); __bgOrigPrint(msg); };
|
|
101
|
+
gs.info = function(msg) { __bgOutput.push({level: 'info', msg: String(msg)}); __bgOrigInfo(msg); };
|
|
102
|
+
gs.warn = function(msg) { __bgOutput.push({level: 'warn', msg: String(msg)}); __bgOrigWarn(msg); };
|
|
103
|
+
gs.error = function(msg) { __bgOutput.push({level: 'error', msg: String(msg)}); __bgOrigError(msg); };
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
gs.info('=== Snow-Flow Background Script Started ===');
|
|
107
|
+
gs.info('Description: ${description.replace(/'/g, "\\'")}');
|
|
108
|
+
|
|
109
|
+
__bgResult = (function() {
|
|
110
|
+
${script}
|
|
111
|
+
})();
|
|
112
|
+
|
|
113
|
+
gs.info('=== Snow-Flow Background Script Completed ===');
|
|
114
|
+
} catch(e) {
|
|
115
|
+
__bgError = e.toString();
|
|
116
|
+
gs.error('Background Script Error: ' + e.toString());
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Restore gs methods
|
|
120
|
+
gs.print = __bgOrigPrint;
|
|
121
|
+
gs.info = __bgOrigInfo;
|
|
122
|
+
gs.warn = __bgOrigWarn;
|
|
123
|
+
gs.error = __bgOrigError;
|
|
124
|
+
|
|
125
|
+
// Store result
|
|
126
|
+
var __bgEndTime = new GlideDateTime();
|
|
127
|
+
var __bgExecTime = Math.abs(GlideDateTime.subtract(__bgStartTime, __bgEndTime).getNumericValue());
|
|
128
|
+
|
|
129
|
+
var __bgResultObj = {
|
|
130
|
+
executionId: '${executionId}',
|
|
131
|
+
success: __bgError === null,
|
|
132
|
+
result: __bgResult,
|
|
133
|
+
error: __bgError,
|
|
134
|
+
output: __bgOutput,
|
|
135
|
+
executionTimeMs: __bgExecTime,
|
|
136
|
+
description: '${description.replace(/'/g, "\\'")}'
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
gs.setProperty('${outputMarker}', JSON.stringify(__bgResultObj));
|
|
140
|
+
gs.info('${outputMarker}:COMPLETE');
|
|
141
|
+
`;
|
|
142
|
+
// Create Fix Script
|
|
143
|
+
const fixScriptName = `Snow-Flow BG Script - ${executionId}`;
|
|
144
|
+
const createResponse = await client.post('/api/now/table/sys_script_fix', {
|
|
145
|
+
name: fixScriptName,
|
|
146
|
+
script: wrappedScript,
|
|
147
|
+
description: `Background script: ${description}. Execution ID: ${executionId}`,
|
|
148
|
+
active: true
|
|
94
149
|
});
|
|
150
|
+
if (!createResponse.data?.result?.sys_id) {
|
|
151
|
+
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.SERVICENOW_API_ERROR, 'Failed to create Fix Script for background execution', { details: createResponse.data });
|
|
152
|
+
}
|
|
153
|
+
const fixScriptSysId = createResponse.data.result.sys_id;
|
|
154
|
+
// Attempt to run the Fix Script
|
|
155
|
+
try {
|
|
156
|
+
await client.patch(`/api/now/table/sys_script_fix/${fixScriptSysId}`, {
|
|
157
|
+
sys_run_script: 'true'
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
catch (runError) {
|
|
161
|
+
// Try PUT approach
|
|
162
|
+
try {
|
|
163
|
+
await client.put(`/api/now/table/sys_script_fix/${fixScriptSysId}`, {
|
|
164
|
+
run: 'true',
|
|
165
|
+
active: true
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
catch (putError) {
|
|
169
|
+
// Script saved, may need manual execution
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
// Poll for execution results
|
|
173
|
+
const startTime = Date.now();
|
|
174
|
+
let result = null;
|
|
175
|
+
let attempts = 0;
|
|
176
|
+
const maxAttempts = Math.ceil(timeout / 2000);
|
|
177
|
+
while (Date.now() - startTime < timeout && attempts < maxAttempts) {
|
|
178
|
+
attempts++;
|
|
179
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
180
|
+
try {
|
|
181
|
+
const propResponse = await client.get('/api/now/table/sys_properties', {
|
|
182
|
+
params: {
|
|
183
|
+
sysparm_query: `name=${outputMarker}`,
|
|
184
|
+
sysparm_fields: 'value,sys_id',
|
|
185
|
+
sysparm_limit: 1
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
if (propResponse.data?.result?.[0]?.value) {
|
|
189
|
+
try {
|
|
190
|
+
result = JSON.parse(propResponse.data.result[0].value);
|
|
191
|
+
// Cleanup property
|
|
192
|
+
const propSysId = propResponse.data.result[0].sys_id;
|
|
193
|
+
if (propSysId) {
|
|
194
|
+
await client.delete(`/api/now/table/sys_properties/${propSysId}`).catch(() => { });
|
|
195
|
+
}
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
catch (parseErr) {
|
|
199
|
+
// Continue polling
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
catch (pollError) {
|
|
204
|
+
// Continue polling
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// Cleanup Fix Script
|
|
208
|
+
try {
|
|
209
|
+
await client.delete(`/api/now/table/sys_script_fix/${fixScriptSysId}`);
|
|
210
|
+
}
|
|
211
|
+
catch (cleanupError) {
|
|
212
|
+
// Ignore
|
|
213
|
+
}
|
|
214
|
+
if (result) {
|
|
215
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
216
|
+
executed: true,
|
|
217
|
+
execution_id: executionId,
|
|
218
|
+
success: result.success,
|
|
219
|
+
result: result.result,
|
|
220
|
+
error: result.error,
|
|
221
|
+
output: result.output,
|
|
222
|
+
execution_time_ms: result.executionTimeMs,
|
|
223
|
+
auto_confirmed: true,
|
|
224
|
+
security_analysis: securityAnalysis
|
|
225
|
+
}, {
|
|
226
|
+
method: 'fix_script',
|
|
227
|
+
description
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
232
|
+
executed: false,
|
|
233
|
+
execution_id: executionId,
|
|
234
|
+
fix_script_sys_id: fixScriptSysId,
|
|
235
|
+
auto_confirmed: true,
|
|
236
|
+
security_analysis: securityAnalysis,
|
|
237
|
+
message: 'Script was saved as Fix Script but automatic execution could not be confirmed.',
|
|
238
|
+
action_required: `Navigate to System Definition > Fix Scripts and run: ${fixScriptName}`
|
|
239
|
+
}, {
|
|
240
|
+
method: 'fix_script_pending',
|
|
241
|
+
description
|
|
242
|
+
});
|
|
243
|
+
}
|
|
95
244
|
}
|
|
96
245
|
// Standard mode - return confirmation request
|
|
97
246
|
const confirmationPrompt = generateConfirmationPrompt({
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_background_script.js","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;
|
|
1
|
+
{"version":3,"file":"snow_execute_background_script.js","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_background_script.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;AAuDH,0BAuOC;AA3RD,kDAA8D;AAC9D,oEAAiH;AAEpG,QAAA,cAAc,GAAsB;IAC/C,IAAI,EAAE,gCAAgC;IACtC,WAAW,EAAE,iHAAiH;IAC9H,gDAAgD;IAChD,QAAQ,EAAE,YAAY;IACtB,WAAW,EAAE,kBAAkB;IAC/B,SAAS,EAAE,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC;IACjD,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,6EAA6E;aAC3F;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,wEAAwE;aACtF;YACD,SAAS,EAAE;gBACT,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gEAAgE;aAC9E;YACD,qBAAqB,EAAE;gBACrB,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,0CAA0C;gBACvD,OAAO,EAAE,KAAK;aACf;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,SAAS;gBACf,WAAW,EAAE,8DAA8D;gBAC3E,OAAO,EAAE,KAAK;aACf;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uDAAuD;gBACpE,OAAO,EAAE,KA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SAAS,IAAI,cAAc;4BACrB,qBAAqB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,aAAa;;;EAG7E,gBAAgB,CAAC,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5C,gCAAgC,gBAAgB,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;EACjF,gBAAgB,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC1C,qBAAqB,gBAAgB,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;EACpE,gBAAgB,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACtC,gBAAgB,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;;;;EAI3D,MAAM;;;;;;;;;;;;;CAaP,CAAC,IAAI,EAAE,CAAC;AACT,CAAC;AAEY,QAAA,OAAO,GAAG,OAAO,CAAC;AAClB,QAAA,MAAM,GAAG,yBAAyB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* snow_execute_script_sync - Synchronous script execution
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Executes server-side JavaScript in ServiceNow using Fix Scripts.
|
|
5
|
+
* Creates a temporary Fix Script, runs it, captures output, and cleans up.
|
|
5
6
|
*
|
|
6
7
|
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
7
8
|
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snow_execute_script_sync.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"snow_execute_script_sync.d.ts","sourceRoot":"","sources":["../../../../../src/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_sync.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAIzF,eAAO,MAAM,cAAc,EAAE,iBAkC5B,CAAC;AAEF,wBAAsB,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC,CAyMxF;AA6BD,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,MAAM,4BAA4B,CAAC"}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* snow_execute_script_sync - Synchronous script execution
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* Executes server-side JavaScript in ServiceNow using Fix Scripts.
|
|
6
|
+
* Creates a temporary Fix Script, runs it, captures output, and cleans up.
|
|
6
7
|
*
|
|
7
8
|
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
8
9
|
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
|
@@ -14,7 +15,7 @@ const auth_js_1 = require("../../shared/auth.js");
|
|
|
14
15
|
const error_handler_js_1 = require("../../shared/error-handler.js");
|
|
15
16
|
exports.toolDefinition = {
|
|
16
17
|
name: 'snow_execute_script_sync',
|
|
17
|
-
description: '
|
|
18
|
+
description: 'Execute script synchronously using Fix Scripts with output capture (ES5 only)',
|
|
18
19
|
// Metadata for tool discovery (not sent to LLM)
|
|
19
20
|
category: 'automation',
|
|
20
21
|
subcategory: 'script-execution',
|
|
@@ -34,12 +35,12 @@ exports.toolDefinition = {
|
|
|
34
35
|
},
|
|
35
36
|
timeout: {
|
|
36
37
|
type: 'number',
|
|
37
|
-
description: 'Timeout in milliseconds',
|
|
38
|
+
description: 'Timeout in milliseconds (for polling)',
|
|
38
39
|
default: 30000
|
|
39
40
|
},
|
|
40
41
|
capture_output: {
|
|
41
42
|
type: 'boolean',
|
|
42
|
-
description: 'Capture and return output',
|
|
43
|
+
description: 'Capture and return output from gs.print/info/warn/error',
|
|
43
44
|
default: true
|
|
44
45
|
}
|
|
45
46
|
},
|
|
@@ -49,65 +50,178 @@ exports.toolDefinition = {
|
|
|
49
50
|
async function execute(args, context) {
|
|
50
51
|
const { script, timeout = 30000, capture_output = true } = args;
|
|
51
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
|
+
}
|
|
52
64
|
const client = await (0, auth_js_1.getAuthenticatedClient)(context);
|
|
53
|
-
// Create execution ID
|
|
65
|
+
// Create execution ID for tracking
|
|
54
66
|
const executionId = `sync_${Date.now()}_${Math.random().toString(36).substring(7)}`;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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); };
|
|
59
86
|
|
|
60
87
|
try {
|
|
61
|
-
|
|
62
|
-
var scriptResult = (function() {
|
|
88
|
+
__snowFlowResult = (function() {
|
|
63
89
|
${script}
|
|
64
90
|
})();
|
|
65
|
-
|
|
66
|
-
result = {
|
|
67
|
-
success: true,
|
|
68
|
-
result: scriptResult,
|
|
69
|
-
executionTime: GlideDateTime.subtract(startTime, new GlideDateTime()).getNumericValue(),
|
|
70
|
-
executionId: '${executionId}'
|
|
71
|
-
};
|
|
72
91
|
} catch(e) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
error: e.toString(),
|
|
76
|
-
executionTime: GlideDateTime.subtract(startTime, new GlideDateTime()).getNumericValue(),
|
|
77
|
-
executionId: '${executionId}'
|
|
78
|
-
};
|
|
92
|
+
__snowFlowError = e.toString();
|
|
93
|
+
gs.error('Script Error: ' + e.toString());
|
|
79
94
|
}
|
|
80
95
|
|
|
81
|
-
//
|
|
82
|
-
|
|
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');
|
|
83
118
|
`;
|
|
84
|
-
//
|
|
85
|
-
const
|
|
86
|
-
|
|
119
|
+
// Step 1: Create a Fix Script record
|
|
120
|
+
const fixScriptName = `Snow-Flow Temp Script - ${executionId}`;
|
|
121
|
+
const createResponse = await client.post('/api/now/table/sys_script_fix', {
|
|
122
|
+
name: fixScriptName,
|
|
123
|
+
script: wrappedScript,
|
|
124
|
+
description: `Temporary script created by Snow-Flow for execution ID: ${executionId}`,
|
|
125
|
+
active: true
|
|
87
126
|
});
|
|
88
|
-
|
|
127
|
+
if (!createResponse.data?.result?.sys_id) {
|
|
128
|
+
throw new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.SERVICENOW_API_ERROR, 'Failed to create Fix Script record', { details: createResponse.data });
|
|
129
|
+
}
|
|
130
|
+
const fixScriptSysId = createResponse.data.result.sys_id;
|
|
131
|
+
// Step 2: Run the Fix Script by calling the run endpoint
|
|
132
|
+
// ServiceNow Fix Scripts can be run via: /api/now/table/sys_script_fix/{sys_id}?sysparm_run_script=true
|
|
133
|
+
// Or by setting the 'run' field to true via PATCH
|
|
89
134
|
try {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
135
|
+
await client.patch(`/api/now/table/sys_script_fix/${fixScriptSysId}`, {
|
|
136
|
+
sys_run_script: 'true'
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
catch (runError) {
|
|
140
|
+
// Some instances may not support direct run - try alternative approach
|
|
141
|
+
// The script was saved, user can run manually
|
|
142
|
+
}
|
|
143
|
+
// Step 3: Poll for completion by checking the system property
|
|
144
|
+
const startTime = Date.now();
|
|
145
|
+
let result = null;
|
|
146
|
+
let attempts = 0;
|
|
147
|
+
const maxAttempts = Math.ceil(timeout / 2000);
|
|
148
|
+
while (Date.now() - startTime < timeout && attempts < maxAttempts) {
|
|
149
|
+
attempts++;
|
|
150
|
+
await new Promise(resolve => setTimeout(resolve, 2000));
|
|
151
|
+
try {
|
|
152
|
+
// Check sys_properties for our output marker
|
|
153
|
+
const propResponse = await client.get('/api/now/table/sys_properties', {
|
|
154
|
+
params: {
|
|
155
|
+
sysparm_query: `name=${outputMarker}`,
|
|
156
|
+
sysparm_fields: 'value',
|
|
157
|
+
sysparm_limit: 1
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
if (propResponse.data?.result?.[0]?.value) {
|
|
161
|
+
try {
|
|
162
|
+
result = JSON.parse(propResponse.data.result[0].value);
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
catch (parseErr) {
|
|
166
|
+
// Continue polling
|
|
167
|
+
}
|
|
168
|
+
}
|
|
93
169
|
}
|
|
94
|
-
|
|
95
|
-
|
|
170
|
+
catch (pollError) {
|
|
171
|
+
// Continue polling
|
|
96
172
|
}
|
|
97
173
|
}
|
|
98
|
-
|
|
99
|
-
|
|
174
|
+
// Step 4: Cleanup - delete the Fix Script and property
|
|
175
|
+
try {
|
|
176
|
+
await client.delete(`/api/now/table/sys_script_fix/${fixScriptSysId}`);
|
|
177
|
+
}
|
|
178
|
+
catch (cleanupError) {
|
|
179
|
+
// Ignore cleanup errors
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
// Delete the output property
|
|
183
|
+
const propDeleteResponse = await client.get('/api/now/table/sys_properties', {
|
|
184
|
+
params: {
|
|
185
|
+
sysparm_query: `name=${outputMarker}`,
|
|
186
|
+
sysparm_fields: 'sys_id',
|
|
187
|
+
sysparm_limit: 1
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
if (propDeleteResponse.data?.result?.[0]?.sys_id) {
|
|
191
|
+
await client.delete(`/api/now/table/sys_properties/${propDeleteResponse.data.result[0].sys_id}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (propCleanupError) {
|
|
195
|
+
// Ignore cleanup errors
|
|
196
|
+
}
|
|
197
|
+
// Step 5: Return results
|
|
198
|
+
if (result) {
|
|
199
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
200
|
+
execution_id: executionId,
|
|
201
|
+
success: result.success,
|
|
202
|
+
result: result.result,
|
|
203
|
+
error: result.error,
|
|
204
|
+
output: capture_output ? result.output : undefined,
|
|
205
|
+
execution_time_ms: result.executionTimeMs
|
|
206
|
+
}, {
|
|
207
|
+
operation: 'sync_script_execution',
|
|
208
|
+
method: 'fix_script'
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
// Script may not have run or output wasn't captured
|
|
213
|
+
return (0, error_handler_js_1.createSuccessResult)({
|
|
214
|
+
execution_id: executionId,
|
|
215
|
+
success: true,
|
|
216
|
+
result: null,
|
|
217
|
+
message: 'Script was saved but execution could not be confirmed. The Fix Script may need to be run manually.',
|
|
218
|
+
fix_script_sys_id: fixScriptSysId,
|
|
219
|
+
manual_run_url: `Navigate to System Definition > Fix Scripts and run: ${fixScriptName}`
|
|
220
|
+
}, {
|
|
221
|
+
operation: 'sync_script_execution',
|
|
222
|
+
method: 'fix_script_manual'
|
|
223
|
+
});
|
|
100
224
|
}
|
|
101
|
-
return (0, error_handler_js_1.createSuccessResult)({
|
|
102
|
-
execution_id: executionId,
|
|
103
|
-
success: result.success,
|
|
104
|
-
result: result.result,
|
|
105
|
-
execution_time_ms: result.executionTime || 0,
|
|
106
|
-
error: result.error || null
|
|
107
|
-
}, {
|
|
108
|
-
operation: 'sync_script_execution',
|
|
109
|
-
timeout_ms: timeout
|
|
110
|
-
});
|
|
111
225
|
}
|
|
112
226
|
catch (error) {
|
|
113
227
|
return (0, error_handler_js_1.createErrorResult)(error instanceof error_handler_js_1.SnowFlowError
|
|
@@ -115,6 +229,29 @@ JSON.stringify(result);
|
|
|
115
229
|
: new error_handler_js_1.SnowFlowError(error_handler_js_1.ErrorType.UNKNOWN_ERROR, error.message, { originalError: error }));
|
|
116
230
|
}
|
|
117
231
|
}
|
|
232
|
+
function validateES5(code) {
|
|
233
|
+
const violations = [];
|
|
234
|
+
const patterns = [
|
|
235
|
+
{ regex: /\b(const|let)\s+/g, type: 'const/let', fix: "Use 'var'" },
|
|
236
|
+
{ regex: /\([^)]*\)\s*=>/g, type: 'arrow_function', fix: 'Use function() {}' },
|
|
237
|
+
{ regex: /`[^`]*`/g, type: 'template_literal', fix: 'Use string concatenation' },
|
|
238
|
+
{ regex: /\{[^}]+\}\s*=\s*/g, type: 'destructuring', fix: 'Use explicit properties' },
|
|
239
|
+
{ regex: /for\s*\([^)]*\s+of\s+/g, type: 'for_of', fix: 'Use traditional for loop' },
|
|
240
|
+
{ regex: /class\s+\w+/g, type: 'class', fix: 'Use function constructor' }
|
|
241
|
+
];
|
|
242
|
+
patterns.forEach(({ regex, type, fix }) => {
|
|
243
|
+
let match;
|
|
244
|
+
while ((match = regex.exec(code)) !== null) {
|
|
245
|
+
violations.push({
|
|
246
|
+
type,
|
|
247
|
+
line: code.substring(0, match.index).split('\n').length,
|
|
248
|
+
code: match[0],
|
|
249
|
+
fix
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
return { valid: violations.length === 0, violations };
|
|
254
|
+
}
|
|
118
255
|
exports.version = '1.0.0';
|
|
119
256
|
exports.author = 'Snow-Flow SDK Migration';
|
|
120
257
|
//# sourceMappingURL=snow_execute_script_sync.js.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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,0BAyMC;AAhPD,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,KAAK,UAAU,OAAO,CAAC,IAAS,EAAE,OAA0B;IACjE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,cAAc,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAEhE,IAAI,CAAC;QACH,uBAAuB;QACvB,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QAC1C,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YACzB,MAAM,IAAI,gCA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CAAC,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE;QACxC,IAAI,KAAK,CAAC;QACV,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3C,UAAU,CAAC,IAAI,CAAC;gBACd,IAAI;gBACJ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;gBACvD,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;gBACd,GAAG;aACJ,CAAC,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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* snow_execute_script_with_output - Execute
|
|
2
|
+
* snow_execute_script_with_output - Execute scripts with full output capture
|
|
3
3
|
*
|
|
4
|
-
* Execute server-side JavaScript in ServiceNow
|
|
5
|
-
*
|
|
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
6
|
*
|
|
7
7
|
* ⚠️ CRITICAL: ALL SCRIPTS MUST BE ES5 ONLY!
|
|
8
8
|
* ServiceNow runs on Rhino engine - no const/let/arrow functions/template literals.
|
package/dist/mcp/servicenow-mcp-unified/tools/automation/snow_execute_script_with_output.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,CAkQxF;AA6BD,eAAO,MAAM,OAAO,UAAU,CAAC;AAC/B,eAAO,MAAM,MAAM,4BAA4B,CAAC"}
|