@sonisoft/now-sdk-ext-mcp 4.8.1 → 4.8.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-script.d.ts","sourceRoot":"","sources":["../../src/tools/execute-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"execute-script.d.ts","sourceRoot":"","sources":["../../src/tools/execute-script.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AASpE;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAgJjE"}
|
|
@@ -2,6 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import { BackgroundScriptExecutor } from "@sonisoft/now-sdk-ext-core";
|
|
3
3
|
import { withConnectionRetry } from "../common/connection.js";
|
|
4
4
|
import { annotationsFor } from "../common/annotations.js";
|
|
5
|
+
/** The `code` core puts on ScriptScopeError. */
|
|
6
|
+
const SCRIPT_SCOPE_ERROR_CODE = "NEX_SCRIPT_SCOPE_UNAVAILABLE";
|
|
5
7
|
/**
|
|
6
8
|
* Registers the execute_script tool on the MCP server.
|
|
7
9
|
*
|
|
@@ -15,13 +17,16 @@ export function registerExecuteScriptTool(server) {
|
|
|
15
17
|
description: "Execute JavaScript on a ServiceNow instance using Scripts - Background " +
|
|
16
18
|
"(the /sys.scripts.do endpoint). The script runs server-side with full " +
|
|
17
19
|
"GlideSystem API access (gs, GlideRecord, GlideAggregate, GlideDateTime, " +
|
|
18
|
-
"GlideUser, etc.). Use gs.
|
|
20
|
+
"GlideUser, etc.). Use gs.info() to produce output (gs.print() also works in global, but prints nothing in a scoped app).\n\n" +
|
|
19
21
|
"SCOPE BEHAVIOR: Scripts execute within the specified application scope. " +
|
|
20
22
|
"When running in a scoped app (e.g., scope: 'x_myapp_custom'), you can " +
|
|
21
23
|
"reference that scope's Script Includes and classes directly by name " +
|
|
22
24
|
"(e.g., MyUtil.doSomething()) without fully-qualifying them. When running " +
|
|
23
25
|
"in global scope, scoped classes must be fully-qualified " +
|
|
24
|
-
"(e.g., x_myapp_custom.MyUtil.doSomething())
|
|
26
|
+
"(e.g., x_myapp_custom.MyUtil.doSomething()). Only 'global' and applications " +
|
|
27
|
+
"developed on the instance (sys_app) can be used; installed store apps " +
|
|
28
|
+
"(sys_store_app) cannot — run in global and call their APIs fully-qualified. " +
|
|
29
|
+
"In a scoped app, use gs.info() for output: gs.print() is global-only.\n\n" +
|
|
25
30
|
"IMPORTANT: This executes code directly on the ServiceNow instance. " +
|
|
26
31
|
"Always review scripts before execution and prefer read-only operations " +
|
|
27
32
|
"unless modification is explicitly intended.",
|
|
@@ -37,7 +42,7 @@ export function registerExecuteScriptTool(server) {
|
|
|
37
42
|
script: z
|
|
38
43
|
.string()
|
|
39
44
|
.describe("The JavaScript code to execute on the ServiceNow instance. " +
|
|
40
|
-
"Use gs.
|
|
45
|
+
"Use gs.info() (or, in global only, gs.print()) to output results — these are the only " +
|
|
41
46
|
"ways to capture output from background scripts. The script runs in " +
|
|
42
47
|
"the server-side Rhino engine with access to all ServiceNow server-side " +
|
|
43
48
|
"APIs: GlideRecord, GlideAggregate, GlideDateTime, GlideUser, " +
|
|
@@ -46,9 +51,11 @@ export function registerExecuteScriptTool(server) {
|
|
|
46
51
|
scope: z
|
|
47
52
|
.string()
|
|
48
53
|
.default("global")
|
|
49
|
-
.describe("The application scope to execute the script in. Accepts
|
|
50
|
-
'-
|
|
51
|
-
|
|
54
|
+
.describe("The application scope to execute the script in. Accepts:\n" +
|
|
55
|
+
'- "global" — the Global scope.\n' +
|
|
56
|
+
'- The scope of an application developed on the instance (a sys_app, e.g. ' +
|
|
57
|
+
'"x_myapp_custom") — resolved to its sys_id via the sys_app table. ' +
|
|
58
|
+
"Installed store apps (sys_store_app) are rejected with an explanation.\n" +
|
|
52
59
|
"- A sys_id directly (32-character hex string) if already known.\n\n" +
|
|
53
60
|
'Defaults to "global". Set this to the target app scope when you need ' +
|
|
54
61
|
"to access scoped Script Includes, Business Rules, or other scoped " +
|
|
@@ -82,7 +89,7 @@ export function registerExecuteScriptTool(server) {
|
|
|
82
89
|
content: [
|
|
83
90
|
{
|
|
84
91
|
type: "text",
|
|
85
|
-
text: "Script executed but returned no output. If you expected output, make sure your script uses gs.print() or gs.info().",
|
|
92
|
+
text: "Script executed but returned no output. If you expected output, make sure your script uses gs.print() or gs.info() (gs.info() in a scoped app, where gs.print() prints nothing).",
|
|
86
93
|
},
|
|
87
94
|
],
|
|
88
95
|
};
|
|
@@ -108,11 +115,19 @@ export function registerExecuteScriptTool(server) {
|
|
|
108
115
|
}
|
|
109
116
|
catch (error) {
|
|
110
117
|
const message = error instanceof Error ? error.message : String(error);
|
|
118
|
+
// An unusable scope (store app, typo, …) fails before the script is sent, and
|
|
119
|
+
// core's message already says why and what to do — say that, not "error
|
|
120
|
+
// executing script", which reads as if the script itself ran and failed.
|
|
121
|
+
// Matched by code, not by importing ScriptScopeError, so an older core
|
|
122
|
+
// without that export cannot break this module at load.
|
|
123
|
+
const isScopeError = error?.code === SCRIPT_SCOPE_ERROR_CODE;
|
|
111
124
|
return {
|
|
112
125
|
content: [
|
|
113
126
|
{
|
|
114
127
|
type: "text",
|
|
115
|
-
text:
|
|
128
|
+
text: isScopeError
|
|
129
|
+
? `Script not run. ${message}`
|
|
130
|
+
: `Error executing script: ${message}`,
|
|
116
131
|
},
|
|
117
132
|
],
|
|
118
133
|
isError: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-script.js","sourceRoot":"","sources":["../../src/tools/execute-script.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,mBA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;YACxE,yEAAyE;YACzE,uEAAuE;YACvE,wDAAwD;YACxD,MAAM,YAAY,GACf,KAAmC,EAAE,IAAI,KAAK,uBAAuB,CAAC;YACzE,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,YAAY;4BAChB,CAAC,CAAC,mBAAmB,OAAO,EAAE;4BAC9B,CAAC,CAAC,2BAA2B,OAAO,EAAE;qBACzC;iBACF;gBACD,OAAO,EAAE,IAAI;aACd,CAAC;QACJ,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sonisoft/now-sdk-ext-mcp",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.2",
|
|
4
4
|
"description": "MCP server for interacting with ServiceNow instances via @sonisoft/now-sdk-ext-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"servicenow",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"@servicenow/sdk-cli": "4.9.2",
|
|
49
49
|
"@servicenow/sdk-cli-core": "3.0.3",
|
|
50
50
|
"@servicenow/sdk-core": "4.9.2",
|
|
51
|
-
"@sonisoft/now-sdk-ext-core": "^6.
|
|
52
|
-
"@sonisoft/sn-credstore": "1.
|
|
51
|
+
"@sonisoft/now-sdk-ext-core": "^6.6.2",
|
|
52
|
+
"@sonisoft/sn-credstore": "1.4.0",
|
|
53
53
|
"zod": "^3.23.8"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|