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:
Namhyeon, Go 2026-04-12 21:11:22 +09:00
parent c22ca660ec
commit 03d078bde8
3 changed files with 17 additions and 6 deletions

View File

@ -69,12 +69,15 @@ function extract(message, callback) {
try {
var result = callback(data.method, params, id);
return {
jsonrpc: "2.0",
result: result === undefined ? null : result,
id: id
};
if (result !== false) {
return {
jsonrpc: "2.0",
result: result === undefined ? null : result,
id: id
};
}
return result;
} catch (e) {
return {
jsonrpc: "2.0",

View File

@ -16,14 +16,17 @@ function StdioServer() {
};
this.send = function (message) {
if (!message) return;
if (typeof message === "object") {
try {
var _serialized = JSON.stringify(message);
message = _serialized;
} catch (e) { /* ignore */ };
} catch (e) { /* ignore */ }
}
WScript.StdOut.WriteLine(message);
WScript.StdErr.WriteLine(message);
};
this.listen = function () {

View File

@ -31,6 +31,11 @@ function main(args) {
};
}
if (method === "notifications/initialized") {
// DO NOT return anything
return false;
}
if (method == "tools/list") {
return {
"tools": [