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 { 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",

View File

@ -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 () {

View File

@ -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": [