@sonisoft/now-sdk-ext-mcp 4.8.2 → 4.8.3
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 +6 -0
- package/dist/common/logging.d.ts.map +1 -1
- package/dist/common/logging.js +62 -15
- package/dist/common/logging.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -521,6 +521,12 @@ Since stdout is reserved for JSON-RPC, **never use `console.log()` in server cod
|
|
|
521
521
|
- Every tool that talks to ServiceNow should accept an optional `instance` parameter
|
|
522
522
|
- Test every tool through the MCP client (not by calling handler functions directly) so the full protocol stack is exercised
|
|
523
523
|
|
|
524
|
+
## ServiceNow SDK upgrades
|
|
525
|
+
|
|
526
|
+
New `@servicenow/sdk` releases are rolled through sn-credstore, core, the CLI and the MCP
|
|
527
|
+
server by a scheduled routine. Its runbook and scripts (`scripts/sdk-watch/`) are described in
|
|
528
|
+
[docs/SDK_UPGRADE_ROUTINE.md](docs/SDK_UPGRADE_ROUTINE.md).
|
|
529
|
+
|
|
524
530
|
## License
|
|
525
531
|
|
|
526
532
|
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/common/logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../../src/common/logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,MAAM,EAAiC,MAAM,4BAA4B,CAAC;AAgBnF;;;;;;GAMG;AACH,wBAAgB,WAAW,IAAI,IAAI,CA4DlC;AAWD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
package/dist/common/logging.js
CHANGED
|
@@ -15,8 +15,13 @@
|
|
|
15
15
|
* stdout is the JSON-RPC transport. Everything here goes to stderr, and nothing in this
|
|
16
16
|
* process may ever write to fd 1.
|
|
17
17
|
*/
|
|
18
|
+
import { createRequire } from "node:module";
|
|
18
19
|
import { Logger, configureLogging, redactValue } from "@sonisoft/now-sdk-ext-core";
|
|
19
20
|
import { logger as sdkLogger } from "@servicenow/sdk-cli/dist/logger/index.js";
|
|
21
|
+
/** The SDK logger module, wherever it was installed. */
|
|
22
|
+
const SDK_LOGGER_PATH = /@servicenow[\\/]sdk-cli[\\/]dist[\\/]logger[\\/]index\.js$/;
|
|
23
|
+
const isSdkLogger = (value) => typeof value?.setLevel === "function"
|
|
24
|
+
&& ["info", "warn", "error", "debug"].every(level => typeof value[level] === "function");
|
|
20
25
|
let configured = false;
|
|
21
26
|
/**
|
|
22
27
|
* Configures process-wide logging. Call once, before anything constructs a manager.
|
|
@@ -40,22 +45,64 @@ export function initLogging() {
|
|
|
40
45
|
// resolves those; naming them here would override an operator's NEX_LOG_FILE=0.
|
|
41
46
|
});
|
|
42
47
|
const sdkLog = getLogger("ServiceNow SDK");
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
// Every copy of the SDK's logger, not just the one this package resolves. When this
|
|
49
|
+
// package's @servicenow/sdk-cli and core's differ, core loads its own copy, and that
|
|
50
|
+
// is the copy that refreshes OAuth tokens. Unpatched, it printed "[now-sdk] Access
|
|
51
|
+
// Token has expired, refreshing token" through console.log, onto fd 1. Core has
|
|
52
|
+
// already been imported by now, so its copy is in the module cache.
|
|
53
|
+
//
|
|
54
|
+
// This finds CommonJS copies only (require.cache), which is what the SDK ships today.
|
|
55
|
+
// Should a release move its logger to ESM, the console backstop below still catches
|
|
56
|
+
// its console.log output, and scripts/sdk-watch/stdio-smoke.mjs checks fd 1 directly.
|
|
57
|
+
const cache = createRequire(import.meta.url).cache;
|
|
58
|
+
const copies = new Set(isSdkLogger(sdkLogger) ? [sdkLogger] : []);
|
|
59
|
+
for (const [path, mod] of Object.entries(cache)) {
|
|
60
|
+
const exported = mod?.exports?.logger;
|
|
61
|
+
if (SDK_LOGGER_PATH.test(path) && isSdkLogger(exported))
|
|
62
|
+
copies.add(exported);
|
|
58
63
|
}
|
|
64
|
+
for (const copy of copies) {
|
|
65
|
+
copy.setLevel("silent");
|
|
66
|
+
for (const level of ["info", "warn", "error", "debug"]) {
|
|
67
|
+
copy[level] = (...args) => sdkLog[level](toMessage(args) || "ServiceNow SDK");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// And a backstop for anything else that reaches for console.log, info or debug: a
|
|
71
|
+
// copy loaded later, or another library. Those write to stdout; route them to stderr
|
|
72
|
+
// through the redacting logger instead. warn and error already go to stderr. Core's
|
|
73
|
+
// logger writes to a process.stderr stream, never console, so this cannot recurse;
|
|
74
|
+
// the guard keeps it that way if that ever changes.
|
|
75
|
+
const consoleLog = getLogger("console");
|
|
76
|
+
let routing = false;
|
|
77
|
+
const route = (level) => (...args) => {
|
|
78
|
+
if (routing) {
|
|
79
|
+
process.stderr.write(`${toMessage(args)}\n`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
routing = true;
|
|
83
|
+
try {
|
|
84
|
+
consoleLog[level](toMessage(args));
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
routing = false;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
console.log = route("info");
|
|
91
|
+
console.info = route("info");
|
|
92
|
+
console.debug = route("debug");
|
|
93
|
+
}
|
|
94
|
+
/** Joins log arguments, serialising anything that is not a string through redaction. */
|
|
95
|
+
function toMessage(args) {
|
|
96
|
+
return args.map(arg => {
|
|
97
|
+
if (typeof arg === "string")
|
|
98
|
+
return arg;
|
|
99
|
+
try {
|
|
100
|
+
return JSON.stringify(redactValue(arg)) ?? String(arg);
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
return "[unserializable]";
|
|
104
|
+
}
|
|
105
|
+
}).join(" ");
|
|
59
106
|
}
|
|
60
107
|
/**
|
|
61
108
|
* Returns a named logger.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/common/logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE/E,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;;;;GAMG;AACH,MAAM,UAAU,WAAW;IACvB,IAAI,UAAU,EAAE,CAAC;QACb,OAAO;IACX,CAAC;IACD,UAAU,GAAG,IAAI,CAAC;IAElB,gBAAgB,CAAC;QACb,+EAA+E;QAC/E,+EAA+E;QAC/E,+EAA+E;QAC/E,kEAAkE;QAClE,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,IAAI,EAAE,IAAI,MAAM;QACzD,2EAA2E;QAC3E,gFAAgF;KACnF,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAC3C,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/common/logging.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE/E,wDAAwD;AACxD,MAAM,eAAe,GAAG,4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