@sonisoft/now-sdk-ext-mcp 1.0.0 → 2.2.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/README.md +23 -3
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/catalog.d.ts +8 -0
- package/dist/tools/catalog.d.ts.map +1 -0
- package/dist/tools/catalog.js +352 -0
- package/dist/tools/catalog.js.map +1 -0
- package/dist/tools/execute-script.d.ts.map +1 -1
- package/dist/tools/execute-script.js +30 -15
- package/dist/tools/execute-script.js.map +1 -1
- package/dist/tools/flow.d.ts +9 -0
- package/dist/tools/flow.d.ts.map +1 -0
- package/dist/tools/flow.js +436 -0
- package/dist/tools/flow.js.map +1 -0
- package/dist/tools/knowledge.d.ts +11 -0
- package/dist/tools/knowledge.d.ts.map +1 -0
- package/dist/tools/knowledge.js +527 -0
- package/dist/tools/knowledge.js.map +1 -0
- package/dist/tools/scope.js +2 -2
- package/dist/tools/scope.js.map +1 -1
- package/dist/tools/xml-record.d.ts +15 -0
- package/dist/tools/xml-record.d.ts.map +1 -0
- package/dist/tools/xml-record.js +145 -0
- package/dist/tools/xml-record.js.map +1 -0
- package/package.json +12 -6
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { XMLRecordManager } from "@sonisoft/now-sdk-ext-core";
|
|
3
|
+
import { withConnectionRetry } from "../common/connection.js";
|
|
4
|
+
/**
|
|
5
|
+
* Instance parameter description shared across XML record tools.
|
|
6
|
+
*/
|
|
7
|
+
const INSTANCE_DESC = "The ServiceNow instance auth alias to use. " +
|
|
8
|
+
'This is the alias configured via `now-sdk auth --add` (e.g., "dev224436", "prod", "test"). ' +
|
|
9
|
+
'The user will typically refer to this by name when saying things like "on my dev224436 instance". ' +
|
|
10
|
+
"If not provided, falls back to the SN_AUTH_ALIAS environment variable.";
|
|
11
|
+
// ============================================================
|
|
12
|
+
// 1. export_record_xml
|
|
13
|
+
// ============================================================
|
|
14
|
+
/**
|
|
15
|
+
* Registers the export_record_xml tool on the MCP server.
|
|
16
|
+
*
|
|
17
|
+
* Exports a single record as ServiceNow unload XML format via the
|
|
18
|
+
* /<table>.do?UNL endpoint.
|
|
19
|
+
*/
|
|
20
|
+
export function registerExportRecordXmlTool(server) {
|
|
21
|
+
server.registerTool("export_record_xml", {
|
|
22
|
+
title: "Export Record as XML",
|
|
23
|
+
description: "Export a single record from a ServiceNow instance in unload XML format. " +
|
|
24
|
+
"Uses the /<table>.do?UNL endpoint to generate ServiceNow-native XML that " +
|
|
25
|
+
"can be imported into another instance or used as a configuration backup.\n\n" +
|
|
26
|
+
"Common use cases:\n" +
|
|
27
|
+
"- Backing up a Script Include, Business Rule, or other configuration record\n" +
|
|
28
|
+
"- Exporting a record to transfer it to another instance\n" +
|
|
29
|
+
"- Comparing record definitions across instances\n" +
|
|
30
|
+
"- Generating XML for inclusion in an update set",
|
|
31
|
+
inputSchema: {
|
|
32
|
+
instance: z.string().optional().describe(INSTANCE_DESC),
|
|
33
|
+
table: z
|
|
34
|
+
.string()
|
|
35
|
+
.describe("The table name of the record to export (e.g., 'sys_script_include', " +
|
|
36
|
+
"'sys_script', 'incident', 'sys_ui_page', 'kb_knowledge')."),
|
|
37
|
+
sys_id: z
|
|
38
|
+
.string()
|
|
39
|
+
.describe("The sys_id of the record to export."),
|
|
40
|
+
},
|
|
41
|
+
}, async ({ instance, table, sys_id }) => {
|
|
42
|
+
try {
|
|
43
|
+
const result = await withConnectionRetry(instance, async (snInstance) => {
|
|
44
|
+
const mgr = new XMLRecordManager(snInstance);
|
|
45
|
+
return await mgr.exportRecord({ table, sysId: sys_id });
|
|
46
|
+
});
|
|
47
|
+
const summary = `Exported record from ${result.table}/${result.sysId}` +
|
|
48
|
+
(result.unloadDate ? ` (unload date: ${result.unloadDate})` : "") +
|
|
49
|
+
` — ${Buffer.byteLength(result.xml, "utf8")} bytes of XML`;
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: "text",
|
|
54
|
+
text: summary + "\n\n" + result.xml,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
61
|
+
return {
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: `Error exporting record: ${message}`,
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
isError: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// ============================================================
|
|
74
|
+
// 2. import_records_xml
|
|
75
|
+
// ============================================================
|
|
76
|
+
/**
|
|
77
|
+
* Registers the import_records_xml tool on the MCP server.
|
|
78
|
+
*
|
|
79
|
+
* Imports XML records into ServiceNow via the sys_upload.do processor.
|
|
80
|
+
*/
|
|
81
|
+
export function registerImportRecordsXmlTool(server) {
|
|
82
|
+
server.registerTool("import_records_xml", {
|
|
83
|
+
title: "Import Records from XML",
|
|
84
|
+
description: "Import XML records into a ServiceNow instance via the sys_upload.do processor. " +
|
|
85
|
+
"Accepts ServiceNow unload XML format (the output of export_record_xml or " +
|
|
86
|
+
"update set XML exports).\n\n" +
|
|
87
|
+
"IMPORTANT: This is a mutative operation that creates or updates records on the " +
|
|
88
|
+
"instance. Always verify the XML content and target table before importing. " +
|
|
89
|
+
"Use this for restoring configurations, migrating records between instances, " +
|
|
90
|
+
"or applying exported record definitions.",
|
|
91
|
+
inputSchema: {
|
|
92
|
+
instance: z.string().optional().describe(INSTANCE_DESC),
|
|
93
|
+
xml_content: z
|
|
94
|
+
.string()
|
|
95
|
+
.describe("The XML content to import in ServiceNow unload format. This is typically " +
|
|
96
|
+
"the output from export_record_xml or an XML update set export."),
|
|
97
|
+
target_table: z
|
|
98
|
+
.string()
|
|
99
|
+
.describe("The target table to import the records into (e.g., 'sys_script_include', " +
|
|
100
|
+
"'sys_script', 'incident'). Must match the table in the XML content."),
|
|
101
|
+
},
|
|
102
|
+
}, async ({ instance, xml_content, target_table }) => {
|
|
103
|
+
try {
|
|
104
|
+
const result = await withConnectionRetry(instance, async (snInstance) => {
|
|
105
|
+
const mgr = new XMLRecordManager(snInstance);
|
|
106
|
+
return await mgr.importRecords({
|
|
107
|
+
xmlContent: xml_content,
|
|
108
|
+
targetTable: target_table,
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
if (!result.success) {
|
|
112
|
+
return {
|
|
113
|
+
content: [
|
|
114
|
+
{
|
|
115
|
+
type: "text",
|
|
116
|
+
text: `Import failed for records into table '${result.targetTable}'.`,
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
isError: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
content: [
|
|
124
|
+
{
|
|
125
|
+
type: "text",
|
|
126
|
+
text: `Successfully imported records into table '${result.targetTable}'.`,
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
133
|
+
return {
|
|
134
|
+
content: [
|
|
135
|
+
{
|
|
136
|
+
type: "text",
|
|
137
|
+
text: `Error importing records: ${message}`,
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
isError: true,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=xml-record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-record.js","sourceRoot":"","sources":["../../src/tools/xml-record.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAE9D;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AW,EAAE,YAAY,EAAE,EAAE,EAAE;QAChD,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;gBACtE,MAAM,GAAG,GAAG,IAAI,gBAAgB,CAAC,UAAU,CAAC,CAAC;gBAC7C,OAAO,MAAM,GAAG,CAAC,aAAa,CAAC;oBAC7B,UAAU,EAAE,WAAW;oBACvB,WAAW,EAAE,YAAY;iBAC1B,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBACpB,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,yCAAyC,MAAM,CAAC,WAAW,IAAI;yBACtE;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,6CAA6C,MAAM,CAAC,WAAW,IAAI;qBAC1E;iBACF;aACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,OAAO,GACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACzD,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,4BAA4B,OAAO,EAAE;qBAC5C;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": "
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "MCP server for interacting with ServiceNow instances via @sonisoft/now-sdk-ext-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"servicenow",
|
|
@@ -42,19 +42,25 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
45
|
-
"@servicenow/sdk": "4.0
|
|
46
|
-
"@servicenow/sdk-cli": "4.0
|
|
45
|
+
"@servicenow/sdk": "4.3.0",
|
|
46
|
+
"@servicenow/sdk-cli": "4.3.0",
|
|
47
47
|
"@servicenow/sdk-cli-core": "3.0.2",
|
|
48
|
-
"@servicenow/sdk-core": "4.0
|
|
49
|
-
"@sonisoft/now-sdk-ext-core": "^
|
|
48
|
+
"@servicenow/sdk-core": "4.3.0",
|
|
49
|
+
"@sonisoft/now-sdk-ext-core": "^3.4.0",
|
|
50
50
|
"zod": "^3.23.8"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
+
"@semantic-release/commit-analyzer": "^13.0.1",
|
|
54
|
+
"@semantic-release/git": "^10.0.1",
|
|
55
|
+
"@semantic-release/github": "^12.0.6",
|
|
56
|
+
"@semantic-release/npm": "^13.1.4",
|
|
57
|
+
"@semantic-release/release-notes-generator": "^14.1.0",
|
|
53
58
|
"@types/jest": "^30.0.0",
|
|
54
59
|
"@types/node": "^22.3.0",
|
|
55
60
|
"jest": "^30.2.0",
|
|
56
61
|
"jest-junit": "^16.0.0",
|
|
57
62
|
"rimraf": "^6.0.0",
|
|
63
|
+
"semantic-release": "^25.0.3",
|
|
58
64
|
"ts-jest": "^29.4.6",
|
|
59
65
|
"ts-node": "^10.9.2",
|
|
60
66
|
"typescript": "^5.5.4"
|
|
@@ -63,6 +69,6 @@
|
|
|
63
69
|
"access": "public"
|
|
64
70
|
},
|
|
65
71
|
"engines": {
|
|
66
|
-
"node": ">=
|
|
72
|
+
"node": ">=22.0.0"
|
|
67
73
|
}
|
|
68
74
|
}
|