|
@@ -389,7 +389,7 @@ public class McpServer extends NanoHTTPD {
|
|
|
case "execute_plugin":
|
|
case "execute_plugin":
|
|
|
textResult = callExecutePlugin(
|
|
textResult = callExecutePlugin(
|
|
|
arguments.getString("plugin_id"),
|
|
arguments.getString("plugin_id"),
|
|
|
- arguments.optJSONObject("arguments"));
|
|
|
|
|
|
|
+ extractArgsObject(arguments, "arguments"));
|
|
|
break;
|
|
break;
|
|
|
case "plot":
|
|
case "plot":
|
|
|
textResult = callPlot(
|
|
textResult = callPlot(
|
|
@@ -545,6 +545,19 @@ public class McpServer extends NanoHTTPD {
|
|
|
return pluginManager.deletePlugin(pluginId);
|
|
return pluginManager.deletePlugin(pluginId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /** 从工具参数中提取嵌套的 arguments,兼容 JSONObject 和 JSON 字符串 */
|
|
|
|
|
+ private JSONObject extractArgsObject(JSONObject params, String key) throws JSONException {
|
|
|
|
|
+ Object val = params.opt(key);
|
|
|
|
|
+ if (val == null || JSONObject.NULL.equals(val)) return null;
|
|
|
|
|
+ if (val instanceof JSONObject) return (JSONObject) val;
|
|
|
|
|
+ if (val instanceof String) {
|
|
|
|
|
+ String s = ((String) val).trim();
|
|
|
|
|
+ if (s.isEmpty()) return null;
|
|
|
|
|
+ return new JSONObject(s);
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private String callPlot(String function, String variable, String xMin, String xMax) {
|
|
private String callPlot(String function, String variable, String xMin, String xMax) {
|
|
|
String result = symjaEngine.plot(function, variable, xMin, xMax);
|
|
String result = symjaEngine.plot(function, variable, xMin, xMax);
|
|
|
String expr = "Plot[" + function + ", {" + variable + ", " + xMin + ", " + xMax + "}]";
|
|
String expr = "Plot[" + function + ", {" + variable + ", " + xMin + ", " + xMax + "}]";
|
|
@@ -599,7 +612,9 @@ public class McpServer extends NanoHTTPD {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return executePluginJS(jsCode, inputValues);
|
|
|
|
|
|
|
+ String result = executePluginJS(jsCode, inputValues);
|
|
|
|
|
+ AppSession.publishMcpEvent("plugin:" + pluginId, result);
|
|
|
|
|
+ return result;
|
|
|
} catch (JSONException e) {
|
|
} catch (JSONException e) {
|
|
|
return "Error: Malformed plugin data: " + e.getMessage();
|
|
return "Error: Malformed plugin data: " + e.getMessage();
|
|
|
}
|
|
}
|