mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-27 15:49:52 -05:00
Everything that drives OrcaSlicer by command (the dispatch of the command catalog, jobs, the journal, replays, Python scripts, recordings) lived inside the MCP server's service class. So Action Replay, the Run Script panel, a plugin's tool call, a person's recording and a run from the command line each had to start "the MCP service", with all of its GUI hooks, although none of them needs a server or an agent. The automation runtime is now a subsystem of its own. It starts the first time a front end asks for it and knows none of them. The MCP endpoint (HTTP, the protocol, the token, the discovery file, the takeover of a port another window holds) is one front end beside the others, opened and closed without stopping what the others run. The widget inspector, menu capture and ImGui item recording are turned on only by a front end that drives the GUI, so a person's recording or long command does not carry them. The part of the runtime that needs no GUI is the library libslic3r_automation, built without wxWidgets and tested by its own suite, automation_tests. A wx dependency in it fails to build, and its tests no longer link the GUI library or the embedded Python. The command line has one option set for this: --run FILE runs a replay or a Python script once the GUI is ready, with --outputdir for its files, and --unrestricted-scripts and --cad turn their settings on for one run without saving them. --mcp-run, --mcp-run-out and --mcp-token are gone; the scripts setting is python_scripts_unrestricted and a session's output folder is <datadir>/automation/out. get_app_state reports ready and version at the top level, and its mcp block describes the endpoint only. No change to slicing output.
71 lines
4.3 KiB
C++
71 lines
4.3 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "slic3r/GUI/Mcp/McpSetup.hpp"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <string>
|
|
|
|
using namespace Slic3r::GUI::Mcp;
|
|
using nlohmann::json;
|
|
|
|
namespace {
|
|
|
|
const std::string kUrl = "http://127.0.0.1:13619/mcp";
|
|
const std::string kToken = "t0ken";
|
|
// Backslashes, a space and a quote, which each format has to escape or keep.
|
|
const std::string kExe = R"(C:\Program Files\Orca's\orca-slicer.exe)";
|
|
|
|
std::string setup(Agent agent, Transport transport) { return agent_setup(agent, transport, kUrl, kToken, kExe); }
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("an HTTP setup holds the server's address and token", "[Mcp]")
|
|
{
|
|
CHECK(setup(Agent::ClaudeCode, Transport::Http) ==
|
|
R"(claude mcp add --transport http --scope user orcaslicer http://127.0.0.1:13619/mcp --header "Authorization: Bearer t0ken")");
|
|
CHECK(setup(Agent::Codex, Transport::Http) == "[mcp_servers.orcaslicer]\n"
|
|
"url = \"http://127.0.0.1:13619/mcp\"\n"
|
|
"http_headers = { \"Authorization\" = \"Bearer t0ken\" }\n");
|
|
CHECK(json::parse(setup(Agent::OpenCode, Transport::Http)) ==
|
|
json{{"mcp", {{"orcaslicer", {{"type", "remote"}, {"url", kUrl}, {"headers", {{"Authorization", "Bearer t0ken"}}}}}}}});
|
|
CHECK(setup(Agent::DeepSeekHarness, Transport::Http) == "- insert:\n"
|
|
" - id: mcp-orcaslicer\n"
|
|
" name: '@deepseek-ai/dsh-mcp-client'\n"
|
|
" config:\n"
|
|
" serverName: orcaslicer\n"
|
|
" transport: streamable-http\n"
|
|
" url: 'http://127.0.0.1:13619/mcp'\n"
|
|
" headers:\n"
|
|
" Authorization: 'Bearer t0ken'\n");
|
|
CHECK(json::parse(setup(Agent::OtherApps, Transport::Http)) ==
|
|
json{{"mcpServers", {{"orcaslicer", {{"type", "http"}, {"url", kUrl}, {"headers", {{"Authorization", "Bearer t0ken"}}}}}}}});
|
|
}
|
|
|
|
TEST_CASE("a stdio setup runs the executable with --mcp-stdio", "[Mcp]")
|
|
{
|
|
CHECK(setup(Agent::ClaudeCode, Transport::Stdio) ==
|
|
R"(claude mcp add --scope user orcaslicer -- "C:\Program Files\Orca's\orca-slicer.exe" --mcp-stdio)");
|
|
CHECK(setup(Agent::Codex, Transport::Stdio) == "[mcp_servers.orcaslicer]\n"
|
|
R"(command = "C:\\Program Files\\Orca's\\orca-slicer.exe")"
|
|
"\n"
|
|
"args = [\"--mcp-stdio\"]\n");
|
|
CHECK(json::parse(setup(Agent::OpenCode, Transport::Stdio)) ==
|
|
json{{"mcp", {{"orcaslicer", {{"type", "local"}, {"command", json::array({kExe, "--mcp-stdio"})}}}}}});
|
|
CHECK(setup(Agent::DeepSeekHarness, Transport::Stdio) == "- insert:\n"
|
|
" - id: mcp-orcaslicer\n"
|
|
" name: '@deepseek-ai/dsh-mcp-client'\n"
|
|
" config:\n"
|
|
" serverName: orcaslicer\n"
|
|
" transport: stdio\n"
|
|
R"( command: 'C:\Program Files\Orca''s\orca-slicer.exe')"
|
|
"\n"
|
|
" args: ['--mcp-stdio']\n");
|
|
CHECK(json::parse(setup(Agent::OtherApps, Transport::Stdio)) ==
|
|
json{{"mcpServers", {{"orcaslicer", {{"command", kExe}, {"args", json::array({"--mcp-stdio"})}}}}}});
|
|
|
|
// The bridge reads the token from the discovery file, so a stdio setup never carries it.
|
|
for (const Agent agent : {Agent::ClaudeCode, Agent::Codex, Agent::OpenCode, Agent::DeepSeekHarness, Agent::OtherApps})
|
|
CHECK(setup(agent, Transport::Stdio).find(kToken) == std::string::npos);
|
|
}
|