mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
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.
This commit is contained in:
parent
97802fd074
commit
2120a8f8b4
45
mcploader.js
45
mcploader.js
|
|
@ -14,6 +14,8 @@ function main(args) {
|
||||||
|
|
||||||
e.target.send(
|
e.target.send(
|
||||||
JsonRpc2.extract(message, function (method, params, id) {
|
JsonRpc2.extract(message, function (method, params, id) {
|
||||||
|
var isError = false;
|
||||||
|
|
||||||
if (method == "initialize") {
|
if (method == "initialize") {
|
||||||
return {
|
return {
|
||||||
"protocolVersion": "2025-11-25",
|
"protocolVersion": "2025-11-25",
|
||||||
|
|
@ -27,7 +29,8 @@ function main(args) {
|
||||||
"serverInfo": {
|
"serverInfo": {
|
||||||
"name": "WelsonJS MCP",
|
"name": "WelsonJS MCP",
|
||||||
"version": "1.0.0"
|
"version": "1.0.0"
|
||||||
}
|
},
|
||||||
|
"isError": isError
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,8 +58,23 @@ function main(args) {
|
||||||
},
|
},
|
||||||
"required": ["a", "b"]
|
"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))
|
"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 {
|
return {
|
||||||
"isError": true
|
"isError": isError
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user