|
@@ -437,6 +437,12 @@ public class McpServer extends NanoHTTPD {
|
|
|
AppSession.requestOpenPlugin(pluginId);
|
|
AppSession.requestOpenPlugin(pluginId);
|
|
|
return "{\"opened\":\"" + pluginId + "\"}";
|
|
return "{\"opened\":\"" + pluginId + "\"}";
|
|
|
}
|
|
}
|
|
|
|
|
+ // 调试命令:__eval js_code — 在 WebView 中执行 JS
|
|
|
|
|
+ if (expression.startsWith("__eval ")) {
|
|
|
|
|
+ String js = expression.substring(7);
|
|
|
|
|
+ AppSession.requestEvalJs(js);
|
|
|
|
|
+ return "{\"eval_sent\":true,\"note\":\"result arrives via MCP event sync (~1s delay)\"}";
|
|
|
|
|
+ }
|
|
|
if (expression.startsWith("__tap ")) {
|
|
if (expression.startsWith("__tap ")) {
|
|
|
AppSession.publishMcpEvent(expression, "");
|
|
AppSession.publishMcpEvent(expression, "");
|
|
|
return "{\"tapped\":" + expression.substring(5).trim() + "}";
|
|
return "{\"tapped\":" + expression.substring(5).trim() + "}";
|
|
@@ -688,7 +694,15 @@ public class McpServer extends NanoHTTPD {
|
|
|
return output.isEmpty() ? "(plugin returned nothing)" : output;
|
|
return output.isEmpty() ? "(plugin returned nothing)" : output;
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
- return "Error executing plugin: " + e.getMessage();
|
|
|
|
|
|
|
+ String msg = e.getMessage();
|
|
|
|
|
+ // Rhino wraps JS errors — extract the actual JS error
|
|
|
|
|
+ if (msg != null && msg.contains("JavaScript exception")) {
|
|
|
|
|
+ msg = "JS: " + msg;
|
|
|
|
|
+ }
|
|
|
|
|
+ // Include stack trace for debugging
|
|
|
|
|
+ java.io.StringWriter sw = new java.io.StringWriter();
|
|
|
|
|
+ e.printStackTrace(new java.io.PrintWriter(sw));
|
|
|
|
|
+ return "Error: " + msg + "\n---\n" + sw.toString().substring(0, Math.min(500, sw.toString().length()));
|
|
|
} finally {
|
|
} finally {
|
|
|
Context.exit();
|
|
Context.exit();
|
|
|
}
|
|
}
|
|
@@ -921,6 +935,7 @@ public class McpServer extends NanoHTTPD {
|
|
|
api.put("version", "2.0");
|
|
api.put("version", "2.0");
|
|
|
api.put("namespace", "IJS");
|
|
api.put("namespace", "IJS");
|
|
|
api.put("plugin_modes", "inline (dialog) or fullscreen (interactive panel)");
|
|
api.put("plugin_modes", "inline (dialog) or fullscreen (interactive panel)");
|
|
|
|
|
+ api.put("debug_commands", "__open plugin_id (open fullscreen plugin), __eval js_code (run JS in WebView, result via event sync), __tap x y (simulate canvas touch)");
|
|
|
api.put("libraries", "lodash 4.17.21, seedrandom 3.0.5, Matter.js 0.19.0");
|
|
api.put("libraries", "lodash 4.17.21, seedrandom 3.0.5, Matter.js 0.19.0");
|
|
|
JSONObject symja = new JSONObject();
|
|
JSONObject symja = new JSONObject();
|
|
|
symja.put("print", "(msg) - console output");
|
|
symja.put("print", "(msg) - console output");
|