diff --git a/deps_src/imgui/imconfig.h b/deps_src/imgui/imconfig.h index a63eea31ac..9c2cc742b5 100644 --- a/deps_src/imgui/imconfig.h +++ b/deps_src/imgui/imconfig.h @@ -14,6 +14,10 @@ #pragma once +// OrcaSlicer: let automation (the MCP server) record items through the test-engine hooks, which +// ImGuiWrapper implements. ImGui calls them only while ImGuiContext::TestEngineHookItems is set. +#define IMGUI_ENABLE_TEST_ENGINE + //---- Define assertion handler. Defaults to calling assert(). // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) diff --git a/deps_src/imgui/imgui_widgets.cpp b/deps_src/imgui/imgui_widgets.cpp index 73eacf7f8d..38b3f1c5ba 100644 --- a/deps_src/imgui/imgui_widgets.cpp +++ b/deps_src/imgui/imgui_widgets.cpp @@ -7219,7 +7219,7 @@ bool ImGui::BBLImageSelectable(ImTextureID user_texture_id, const ImVec2& size_a if (pressed && (window->Flags & ImGuiWindowFlags_Popup) && !(flags & ImGuiSelectableFlags_DontClosePopups) && !(g.CurrentItemFlags & ImGuiItemFlags_SelectableDontClosePopup)) CloseCurrentPopup(); - IMGUI_TEST_ENGINE_ITEM_INFO(id, label, window->DC.LastItemStatusFlags); + IMGUI_TEST_ENGINE_ITEM_INFO(id, NULL, window->DC.LastItemStatusFlags); return pressed; } diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 512506b07b..e687d4eb84 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -169,6 +169,7 @@ using json = nlohmann::json; #ifdef SLIC3R_GUI #include "slic3r/GUI/GUI_Init.hpp" + #include "slic3r/GUI/Mcp/McpStdioBridge.hpp" // BBLPrinterAgent::from_orca_filament_id(); the map and its lookups live in libslic3r_gui, // which only a SLIC3R_GUI build links (see target_link_libraries(OrcaSlicer libslic3r_gui) // in CMakeLists). @@ -1203,6 +1204,13 @@ int CLI::run(int argc, char **argv) // Save the thread ID of the main thread. save_main_thread_id(); +#ifdef SLIC3R_GUI + // The stdio bridge is a plain pipe to a running GUI instance; it needs none of the setup below. + for (int i = 1; i < argc; ++i) + if (std::strcmp(argv[i], "--mcp-stdio") == 0) + return Slic3r::GUI::Mcp::run_stdio_bridge(argc, argv); +#endif + #ifdef __WXGTK__ // ------------------------------------------------------------------ // Linux backend selection — runtime, based on GDK_BACKEND env var. @@ -1511,6 +1519,18 @@ int CLI::run(int argc, char **argv) //BBS: remove GCodeViewer as separate APP logic //params.start_as_gcodeviewer = start_as_gcodeviewer; + if (const auto *opt = m_config.opt("mcp")) + params.mcp.enable = opt->value; + if (const auto *opt = m_config.opt("mcp_port")) + params.mcp.port = opt->value; + if (const auto *opt = m_config.opt("mcp_token")) + params.mcp.token = opt->value; + // Resolved now: the GUI moves the working directory to /log before the script runs. + if (const auto *opt = m_config.opt("mcp_script")) + params.mcp.script = resolve_cli_input_path(opt->value); + if (const auto *opt = m_config.opt("mcp_script_out")) + params.mcp.script_out = resolve_cli_input_path(opt->value); + BOOST_LOG_TRIVIAL(info) << "begin to launch OrcaSlicer GUI soon"; return Slic3r::GUI::GUI_Run(params); #else // SLIC3R_GUI diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index d5523fa50a..fc7b231335 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -13173,6 +13173,42 @@ CLIMiscConfigDef::CLIMiscConfigDef() def->tooltip = L("Load and store settings at the given directory. This is useful for maintaining different profiles or including configurations from a network storage."); + def = this->add("mcp", coBool); + def->label = L("MCP server"); + def->tooltip = L("Start the MCP server for AI agents on 127.0.0.1 for this run, whatever the preference says."); + def->set_default_value(new ConfigOptionBool(false)); + + def = this->add("mcp_port", coInt); + def->label = L("MCP server port"); + def->tooltip = L("Port of the MCP server. Defaults to the preference, or 13619."); + def->cli_params = "port"; + def->min = 0; + def->max = 65535; + def->set_default_value(new ConfigOptionInt(0)); + + def = this->add("mcp_token", coString); + def->label = L("MCP server token"); + def->tooltip = L("Bearer token the MCP server requires for this run. The ORCA_MCP_TOKEN environment variable takes precedence and does not show up in the process list."); + def->cli_params = "token"; + def->set_default_value(new ConfigOptionString()); + + def = this->add("mcp_script", coString); + def->label = L("MCP script"); + def->tooltip = L("Run an MCP script once the GUI is ready, write its results, and exit: 0 when it passed, 1 when a step failed, 2 when the script is invalid."); + def->cli_params = "file"; + def->set_default_value(new ConfigOptionString()); + + def = this->add("mcp_script_out", coString); + def->label = L("MCP script output directory"); + def->tooltip = L("Where --mcp-script writes result.json and screenshots. Defaults to