Bladeren bron

feat: document all MCP debug commands — __key + comprehensive discoverability

Now MCP clients can discover:
- evaluate tool description lists __open, __eval, __tap, __key
- debug://commands resource with full usage guide and workflow
- api://plugin resource references all debug commands
- __key command documented (simulate calculator key presses)

Co-Authored-By: Claude <noreply@anthropic.com>
nonvioce 3 maanden geleden
bovenliggende
commit
f3b289f02f
1 gewijzigde bestanden met toevoegingen van 33 en 3 verwijderingen
  1. 33 3
      app/src/main/java/com/nonvioce/ijs/McpServer.java

+ 33 - 3
app/src/main/java/com/nonvioce/ijs/McpServer.java

@@ -201,7 +201,10 @@ public class McpServer extends NanoHTTPD {
             "Evaluate a Symja mathematical expression. Supports calculus, algebra, " +
             "Evaluate a Symja mathematical expression. Supports calculus, algebra, " +
             "linear algebra, number theory, special functions, transforms, and more. " +
             "linear algebra, number theory, special functions, transforms, and more. " +
             "Uses Wolfram/Mathematica-like syntax with square brackets for function calls, " +
             "Uses Wolfram/Mathematica-like syntax with square brackets for function calls, " +
-            "e.g. Integrate[x^2, x], Solve[x^2-5*x+6==0, x], Det[{{1,2},{3,4}}].",
+            "e.g. Integrate[x^2, x], Solve[x^2-5*x+6==0, x], Det[{{1,2},{3,4}}]. " +
+            "Debug commands: '__open plugin_id' to open a fullscreen plugin, " +
+            "'__eval js_code' to run JS in WebView context (result via event sync), " +
+            "'__tap x y' to simulate canvas touch, '__key name' to simulate key press (2,+, -,*,/,^,(,),=,del,c).",
             inputSchema(
             inputSchema(
                 props().put("expression", stringProp("The Symja expression to evaluate")),
                 props().put("expression", stringProp("The Symja expression to evaluate")),
                 "expression")));
                 "expression")));
@@ -789,7 +792,12 @@ public class McpServer extends NanoHTTPD {
         resources.put(resource("api://plugin",
         resources.put(resource("api://plugin",
             "Plugin API Reference",
             "Plugin API Reference",
             "application/json",
             "application/json",
-            "Complete IJS API available to plugins: IJS.Symja (math), IJS.canvas (drawing), IJS.input (touch), IJS.io (file I/O), IJS.audio (sound), IJS.ui (panel control). Libraries: lodash, seedrandom, Matter.js"));
+            "Complete IJS API: schema, IJS.Symja/canvas/input/io/audio/ui, libraries, execution environments. Read for full plugin development guide."));
+
+        resources.put(resource("debug://commands",
+            "Debug Commands",
+            "application/json",
+            "Plugin debugging via evaluate(): __open plugin_id, __eval js_code, __tap x y, __key name. See api://plugin for details."));
 
 
         JSONObject result = new JSONObject();
         JSONObject result = new JSONObject();
         result.put("resources", resources);
         result.put("resources", resources);
@@ -821,6 +829,10 @@ public class McpServer extends NanoHTTPD {
                 contents.put(resourceContent(uri, "application/json", getPluginApiReference()));
                 contents.put(resourceContent(uri, "application/json", getPluginApiReference()));
                 break;
                 break;
             }
             }
+            case "debug://commands": {
+                contents.put(resourceContent(uri, "application/json", getDebugCommandsReference()));
+                break;
+            }
             default:
             default:
                 throw new JSONException("Unknown resource URI: " + uri);
                 throw new JSONException("Unknown resource URI: " + uri);
         }
         }
@@ -940,7 +952,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("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), __key name (simulate key press)");
             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");
@@ -1048,6 +1060,24 @@ public class McpServer extends NanoHTTPD {
         }
         }
     }
     }
 
 
+    /** Debug commands reference */
+    private String getDebugCommandsReference() {
+        try {
+            JSONObject ref = new JSONObject();
+            ref.put("_title", "IJS MCP Plugin Debug Commands");
+            ref.put("_usage", "Use via the 'evaluate' tool with these expression prefixes");
+            ref.put("__open", "Open a fullscreen plugin in the WebView console. Usage: evaluate('__open plugin_id'). Example: evaluate('__open power_of_two')");
+            ref.put("__eval", "Execute JavaScript in WebView context. Result arrives via MCP event sync (~1 second delay). Use double quotes for strings. Example: evaluate('__eval JSON.stringify({w:IJS.canvas.width()})')");
+            ref.put("__key", "Simulate a calculator key press. Requires an open fullscreen plugin. Keys: 2, +, -, *, /, ^, (, ), =, del, c. Example: evaluate('__key 2')
+            ref.put("__tap", "Simulate touch at canvas logical coordinates. Requires an open fullscreen plugin. Example: evaluate('__tap 300 235')");
+            ref.put("_workflow", "1. evaluate('__open plugin_id') → 2. evaluate('__tap x y') or evaluate('__key 2') → 3. evaluate('__eval console.log(\"debug\")'). Results from __eval come through regular MCP event polling.");
+            ref.put("_note", "Debug commands bypass Symja evaluation. Non-debug expressions are evaluated normally.");
+            return ref.toString(2);
+        } catch (Exception e) {
+            return "{}";
+        }
+    }
+
     /** Gracefully stop the server. */
     /** Gracefully stop the server. */
     public void stopServer() {
     public void stopServer() {
         initialized = false;
         initialized = false;