MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / _process_command

Method _process_command

modules/mcp/mcp_bridge.cpp:271–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271Dictionary MCPBridge::_process_command(const Dictionary &p_cmd) {
272 String action = p_cmd.get("action", "");
273 Dictionary args = p_cmd.get("args", Dictionary());
274 Dictionary resp;
275
276 fprintf(stderr, "[MCP] Bridge processing command: %s\n", action.utf8().get_data());
277
278 if (action == "capture") {
279 SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
280 if (st) {
281 Window *vp = st->get_root();
282 if (!vp) {
283 resp["error"] = "No root window found";
284 return resp;
285 }
286 Ref<Texture2D> tex = vp->get_texture();
287 if (tex.is_null()) {
288 resp["error"] = "Viewport texture is missing";
289 return resp;
290 }
291 Ref<Image> img = tex->get_image();
292
293 float scale = args.get("scale", 1.0);
294 if (scale != 1.0) {
295 img->resize(img->get_width() * scale, img->get_height() * scale);
296 }
297
298 PackedByteArray png_buffer = img->save_png_to_buffer();
299 resp["image_base64"] = CryptoCore::b64_encode_str(png_buffer.ptr(), png_buffer.size());
300 resp["format"] = "png";
301 resp["width"] = img->get_width();
302 resp["height"] = img->get_height();
303 } else {
304 resp["error"] = "No scene tree found";
305 }
306 } else if (action == "click") {
307 Vector2 pos;
308 if (args.has("node_path")) {
309 SceneTree *st = Object::cast_to<SceneTree>(OS::get_singleton()->get_main_loop());
310 if (!st) {
311 resp["error"] = "No scene tree found";
312 return resp;
313 }
314 Window *root_window = st->get_root();
315 if (!root_window) {
316 resp["error"] = "No root window found";
317 return resp;
318 }
319 Node *node = root_window->get_node_or_null(args["node_path"]);
320 Control *ctrl = Object::cast_to<Control>(node);
321 if (ctrl) {
322 pos = ctrl->get_screen_transform().get_origin() + ctrl->get_size() / 2.0;
323 } else if (Object::cast_to<Node2D>(node)) {
324 pos = Object::cast_to<Node2D>(node)->get_global_position();
325 } else {
326 resp["error"] = "Node not found or not a 2D element";
327 return resp;
328 }

Callers

nothing calls this directly

Calls 15

find_keycodeFunction · 0.85
save_png_to_bufferMethod · 0.80
get_node_or_nullMethod · 0.80
parse_input_eventMethod · 0.80
set_button_indexMethod · 0.80
begins_withMethod · 0.80
has_actionMethod · 0.80
substrMethod · 0.80
to_upperMethod · 0.80
set_keycodeMethod · 0.80
set_physical_keycodeMethod · 0.80
set_unicodeMethod · 0.80

Tested by

no test coverage detected