From 2120a8f8b436605eb688253f22e9cc81e22d7ae1 Mon Sep 17 00:00:00 2001 From: "Namhyeon, Go" Date: Sun, 12 Apr 2026 22:54:24 +0900 Subject: [PATCH] Add ES3 evaluator and isError flag Introduce an isError flag and propagate it through RPC responses, including initialize and action listings. Add a new action "evaluate_js_es3" with an input schema that accepts a script string and a handler that evaluates the script (returns the evaluation result as text or "Error" on exception). Also set isError for unknown methods so the RPC indicates failures consistently. --- mcploader.js | 45 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/mcploader.js b/mcploader.js index 2ee76da..8534244 100644 --- a/mcploader.js +++ b/mcploader.js @@ -14,6 +14,8 @@ function main(args) { e.target.send( JsonRpc2.extract(message, function (method, params, id) { + var isError = false; + if (method == "initialize") { return { "protocolVersion": "2025-11-25", @@ -27,7 +29,8 @@ function main(args) { "serverInfo": { "name": "WelsonJS MCP", "version": "1.0.0" - } + }, + "isError": isError }; } @@ -55,8 +58,23 @@ function main(args) { }, "required": ["a", "b"] } + }, + { + "name": "evaluate_js_es3", + "title": "Evaluate JavaScript ES3", + "description": "Evaluate JavaScript with ES3 syntax (use ES3 syntax strictly)", + "inputSchema": { + "type": "object", + "properties": { + "script": { + "type": "string" + } + }, + "required": ["script"] + } } - ] + ], + "isError": isError }; } @@ -71,13 +89,32 @@ function main(args) { "text": "Result is " + (parseFloat(params.arguments.a) + parseFloat(params.arguments.b)) } ], - "isError": false + "isError": isError }; } + + if (function_calling_name == "evaluate_js_es3") { + return { + "content": [ + { + "type": "text", + "text": (function(script) { + try { + return String(eval(script)); + } catch (e) { + return "Error"; + isError = true; + } + })(params.arguments.script) + } + ] + } + } } + isError = true; return { - "isError": true + "isError": isError }; }) );