mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Allow no-reply notifications; also write messages to stderr
Treat a callback returning false as a signal to suppress a JSON-RPC reply (jsonrpc2.extract). Add a special-case in mcploader to return false for "notifications/initialized" so no response is sent. In stdio-server, skip sending falsy messages, keep object serialization, and write outgoing messages to both StdOut and StdErr (useful for logging/debugging). Small cleanup in catch formatting.
This commit is contained in:
parent
c22ca660ec
commit
03d078bde8
|
|
@ -69,12 +69,15 @@ function extract(message, callback) {
|
||||||
try {
|
try {
|
||||||
var result = callback(data.method, params, id);
|
var result = callback(data.method, params, id);
|
||||||
|
|
||||||
return {
|
if (result !== false) {
|
||||||
jsonrpc: "2.0",
|
return {
|
||||||
result: result === undefined ? null : result,
|
jsonrpc: "2.0",
|
||||||
id: id
|
result: result === undefined ? null : result,
|
||||||
};
|
id: id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
jsonrpc: "2.0",
|
jsonrpc: "2.0",
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,17 @@ function StdioServer() {
|
||||||
};
|
};
|
||||||
|
|
||||||
this.send = function (message) {
|
this.send = function (message) {
|
||||||
|
if (!message) return;
|
||||||
|
|
||||||
if (typeof message === "object") {
|
if (typeof message === "object") {
|
||||||
try {
|
try {
|
||||||
var _serialized = JSON.stringify(message);
|
var _serialized = JSON.stringify(message);
|
||||||
message = _serialized;
|
message = _serialized;
|
||||||
} catch (e) { /* ignore */ };
|
} catch (e) { /* ignore */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
WScript.StdOut.WriteLine(message);
|
WScript.StdOut.WriteLine(message);
|
||||||
|
WScript.StdErr.WriteLine(message);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.listen = function () {
|
this.listen = function () {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ function main(args) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method === "notifications/initialized") {
|
||||||
|
// DO NOT return anything
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (method == "tools/list") {
|
if (method == "tools/list") {
|
||||||
return {
|
return {
|
||||||
"tools": [
|
"tools": [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user