diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md index 61e049191b..a3816a5942 100644 --- a/docs/HLSD/mcp-server.md +++ b/docs/HLSD/mcp-server.md @@ -557,7 +557,7 @@ A line that is valid JSON but not one message object, such as a batch, gets an e The CLI options are in `CLIMiscConfigDef`, so the GUI still starts: `--mcp`, `--mcp-port N`, `--mcp-token T`, `--mcp-script FILE`, `--mcp-script-out DIR` and `--mcp-stdio`. The AppConfig `app` section holds `mcp_enabled` (false) and `mcp_port` (13619). Preferences › General › AI features -opens with a line on what agents can do and who can connect, then has four rows: +opens with a line on what agents can do and who can connect, then has five rows: - **"MCP server"**: checked while the server runs. A dot and a line beside it give the state: "Running", "Off", "Not running" (enabled, but the start failed), that another window serves @@ -566,24 +566,34 @@ opens with a line on what agents can do and who can connect, then has four rows: - **"Server port"**. - **"Server address"**: the URL, dimmed while the server is off, when it shows the port turning it on would use. +- **"Connection type"**: HTTP (the default) or stdio, for the setup the next row copies, with a + line under it on what the choice means for the agent. It is not saved: it shapes only the copied + text. - **"Add to an agent"**: a picker, "Copy", and a line under them saying what to do with the copied - text. The agents connect over HTTP, with the URL and the token in force: - - Claude Code: `claude mcp add --transport http --scope user orcaslicer --header "Authorization: Bearer "`. - - Codex: an `[mcp_servers.orcaslicer]` table with `url` and `http_headers` for - `~/.codex/config.toml`, since `codex mcp add` takes a token only from an environment variable. - - opencode: an `mcp.orcaslicer` entry of type `remote` with `url` and `headers`. - - DeepSeek Harness: an `insert` row with a `@deepseek-ai/dsh-mcp-client` entry (`streamable-http`, - `url`, `headers`) for `~/.dsh/cordis.patch.yml`, which every profile applies. - - "Other apps": an `mcpServers.orcaslicer` entry that runs ` --mcp-stdio`, for apps - that only take a command, such as Claude Desktop. It uses the AppImage's own path inside an - AppImage. + text. An HTTP setup holds the URL and the token in force; a stdio setup runs + ` --mcp-stdio`, using the AppImage's own path inside an AppImage, and holds no token, + since the bridge reads it from the discovery file: + - Claude Code: `claude mcp add --transport http --scope user orcaslicer --header "Authorization: Bearer "`, + or `claude mcp add --scope user orcaslicer -- "" --mcp-stdio`. + - Codex: an `[mcp_servers.orcaslicer]` table for `~/.codex/config.toml`, with `url` and + `http_headers`, since `codex mcp add` takes a token only from an environment variable, or with + `command` and `args`. + - opencode: an `mcp.orcaslicer` entry of type `remote` with `url` and `headers`, or of type + `local` with `command`. + - DeepSeek Harness: an `insert` row with a `@deepseek-ai/dsh-mcp-client` entry for + `~/.dsh/cordis.patch.yml`, which every profile applies: `streamable-http` with `url` and + `headers`, or `stdio` with `command` and `args`. + - "Other apps": an `mcpServers.orcaslicer` entry, the shape most apps read: of type `http` with + `url` and `headers`, or with `command` and `args` for apps that only take a command, such as + Claude Desktop. HTTP is the default because its URL stays the same whichever OrcaSlicer build runs, and starting an agent session never starts OrcaSlicer: the stdio bridge launches the app as soon as a client starts it, so a user-wide registration would open OrcaSlicer with every agent session. The cost is that OrcaSlicer must be running with the server on before the agent connects, and a registration holds the token: a new token (delete the token file, then turn the server off and on) or a new port -means copying the setup again. +means copying the setup again. Stdio suits an agent that should open OrcaSlicer on demand, and apps +that can't connect over HTTP; its setup names this executable, so it breaks when the program moves. ## Testing diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 35a4778dc7..e52cb2d70c 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -156,6 +156,8 @@ set(SLIC3R_GUI_SOURCES GUI/Mcp/McpService.cpp GUI/Mcp/McpService.hpp GUI/Mcp/McpServicePtr.hpp + GUI/Mcp/McpSetup.cpp + GUI/Mcp/McpSetup.hpp GUI/Mcp/McpStdioBridge.cpp GUI/Mcp/McpStdioBridge.hpp GUI/Mcp/McpToken.cpp diff --git a/src/slic3r/GUI/Mcp/McpSetup.cpp b/src/slic3r/GUI/Mcp/McpSetup.cpp new file mode 100644 index 0000000000..ad5caf4bf2 --- /dev/null +++ b/src/slic3r/GUI/Mcp/McpSetup.cpp @@ -0,0 +1,52 @@ +#include "McpSetup.hpp" + +#include + +#include + +namespace Slic3r { namespace GUI { namespace Mcp { + +std::string agent_setup(Agent agent, Transport transport, const std::string& url, const std::string& token, const std::string& exe) +{ + using nlohmann::ordered_json; + const bool http = transport == Transport::Http; + const std::string bearer = "Bearer " + token; + switch (agent) { + case Agent::ClaudeCode: + return http ? "claude mcp add --transport http --scope user orcaslicer " + url + " --header \"Authorization: " + bearer + "\"" : + "claude mcp add --scope user orcaslicer -- \"" + exe + "\" --mcp-stdio"; + case Agent::Codex: // a table for ~/.codex/config.toml: Codex's command line takes a token only from an environment variable + return "[mcp_servers.orcaslicer]\n" + + (http ? "url = \"" + url + "\"\nhttp_headers = { \"Authorization\" = \"" + bearer + "\" }\n" : + // A JSON string is also a TOML basic string, with the path's backslashes escaped. + "command = " + ordered_json(exe).dump() + "\nargs = [\"--mcp-stdio\"]\n"); + case Agent::OpenCode: + return ordered_json{{"mcp", {{"orcaslicer", http ? ordered_json{{"type", "remote"}, {"url", url}, {"headers", {{"Authorization", bearer}}}} : + ordered_json{{"type", "local"}, {"command", ordered_json::array({exe, "--mcp-stdio"})}}}}}} + .dump(2); + case Agent::DeepSeekHarness: { // an insert row for ~/.dsh/cordis.patch.yml, which every profile applies + std::string quoted_exe; // a single-quoted YAML scalar, which doubles its quotes and keeps backslashes + for (const char c : exe) + quoted_exe += c == '\'' ? std::string("''") : std::string(1, c); + return "- insert:\n" + " - id: mcp-orcaslicer\n" + " name: '@deepseek-ai/dsh-mcp-client'\n" + " config:\n" + " serverName: orcaslicer\n" + + (http ? " transport: streamable-http\n" + " url: '" + url + "'\n" + " headers:\n" + " Authorization: '" + bearer + "'\n" : + " transport: stdio\n" + " command: '" + quoted_exe + "'\n" + " args: ['--mcp-stdio']\n"); + } + case Agent::OtherApps: // the mcpServers shape most apps read + return ordered_json{{"mcpServers", {{"orcaslicer", http ? ordered_json{{"type", "http"}, {"url", url}, {"headers", {{"Authorization", bearer}}}} : + ordered_json{{"command", exe}, {"args", ordered_json::array({"--mcp-stdio"})}}}}}} + .dump(2); + } + return {}; +} + +}}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Mcp/McpSetup.hpp b/src/slic3r/GUI/Mcp/McpSetup.hpp new file mode 100644 index 0000000000..9f95f27c3c --- /dev/null +++ b/src/slic3r/GUI/Mcp/McpSetup.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace Slic3r { namespace GUI { namespace Mcp { + +// The agents Preferences copies a setup for, in its picker's order. +enum class Agent { ClaudeCode, Codex, OpenCode, DeepSeekHarness, OtherApps }; + +// How a setup connects the agent, in Preferences' order. HTTP reaches the running server at an +// address that stays the same whichever OrcaSlicer build runs, so it is the default. Stdio runs +// the executable with --mcp-stdio, which relays to the server and starts OrcaSlicer when none is +// running, but breaks when the program moves; it also serves apps that only run servers as commands. +enum class Transport { Http, Stdio }; + +// The text that adds OrcaSlicer to `agent`, in the form the agent takes it: a command to run or an +// entry for its configuration file. An HTTP setup holds the server's `url` and `token`; a stdio +// setup holds the executable `exe` (UTF-8) and no token, since --mcp-stdio reads it from the +// discovery file. +std::string agent_setup(Agent agent, Transport transport, const std::string& url, const std::string& token, const std::string& exe); + +}}} // namespace Slic3r::GUI::Mcp diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index d185494614..b75066129a 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -43,8 +43,8 @@ #include "slic3r/GUI/Mcp/McpOptions.hpp" #include "slic3r/GUI/Mcp/McpPaths.hpp" #include "slic3r/GUI/Mcp/McpService.hpp" +#include "slic3r/GUI/Mcp/McpSetup.hpp" #include "slic3r/GUI/Mcp/McpToken.hpp" -#include #include #include #include @@ -1342,41 +1342,26 @@ static std::string mcp_url(const Mcp::McpService *mcp, AppConfig *config) return "http://127.0.0.1:" + std::to_string(port) + "/mcp"; } -// The agents the setup row covers, in its order. All but the last connect over HTTP: the address -// stays the same whichever OrcaSlicer build runs, and starting an agent session never starts -// OrcaSlicer. The last is for apps that only run a server as a command: it runs this program with -// --mcp-stdio, which starts OrcaSlicer when needed but breaks when the program moves. -enum class McpAgent { ClaudeCode, Codex, OpenCode, DeepSeekHarness, OtherApps }; - -static std::string mcp_setup_text(McpAgent agent, const std::string &url, const std::string &token) +// The program a stdio setup runs. Inside an AppImage the executable path is a temporary mount. +static std::string mcp_executable() { - using nlohmann::ordered_json; - const std::string bearer = "Bearer " + token; - switch (agent) { - case McpAgent::ClaudeCode: - return "claude mcp add --transport http --scope user orcaslicer " + url + " --header \"Authorization: " + bearer + "\""; - case McpAgent::Codex: // a table for ~/.codex/config.toml: Codex's command line takes a token only from an environment variable - return "[mcp_servers.orcaslicer]\nurl = \"" + url + "\"\nhttp_headers = { \"Authorization\" = \"" + bearer + "\" }\n"; - case McpAgent::OpenCode: - return ordered_json{{"mcp", {{"orcaslicer", {{"type", "remote"}, {"url", url}, {"headers", {{"Authorization", bearer}}}}}}}}.dump(2); - case McpAgent::DeepSeekHarness: // an insert row for ~/.dsh/cordis.patch.yml, which every profile applies - return "- insert:\n" - " - id: mcp-orcaslicer\n" - " name: '@deepseek-ai/dsh-mcp-client'\n" - " config:\n" - " serverName: orcaslicer\n" - " transport: streamable-http\n" - " url: '" + url + "'\n" - " headers:\n" - " Authorization: '" + bearer + "'\n"; - case McpAgent::OtherApps: { - wxString exe; - if (!wxGetEnv("APPIMAGE", &exe)) // inside an AppImage the executable path is a temporary mount - exe = wxStandardPaths::Get().GetExecutablePath(); - return ordered_json{{"mcpServers", {{"orcaslicer", {{"command", into_u8(exe)}, {"args", ordered_json::array({"--mcp-stdio"})}}}}}}.dump(2); - } - } - return {}; + wxString exe; + if (!wxGetEnv("APPIMAGE", &exe)) + exe = wxStandardPaths::Get().GetExecutablePath(); + return into_u8(exe); +} + +// Stacks a grey hint under a row's controls, at the start of the control column. +wxBoxSizer *PreferencesDialog::with_mcp_hint(wxBoxSizer *row, ::Label *hint) +{ + hint->SetForegroundColour(wxColour("#6B6B6B")); + auto column = new wxBoxSizer(wxVERTICAL); + column->Add(row); + auto hint_row = new wxBoxSizer(wxHORIZONTAL); + hint_row->AddSpacer(FromDIP(DESIGN_LEFT_MARGIN + 5) + DESIGN_TITLE_SIZE.x); // create_item_label's margin, label and gap + hint_row->Add(hint); + column->Add(hint_row, 0, wxTOP, FromDIP(2)); + return column; } // Swaps the button's text for `confirmation` for two seconds, at the button's width so the row @@ -1503,6 +1488,34 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_address(wxString title, wxString return m_sizer; } +wxBoxSizer *PreferencesDialog::create_item_mcp_transport(wxString title, wxString tooltip) +{ + wxBoxSizer *m_sizer = create_item_label(title, tooltip); + + // The names agents' own settings use, untranslated. The hint says what each choice means for the + // agent, so it stays in view rather than in a tooltip. + m_mcp_transport = new RadioGroup(m_parent, {"HTTP", "stdio"}, wxHORIZONTAL); + m_mcp_transport_hint = new ::Label(m_parent, ::Label::Body_13, wxEmptyString); + auto show_transport = [this]() { + m_mcp_transport_hint->SetLabel(Mcp::Transport(m_mcp_transport->GetSelection()) == Mcp::Transport::Http ? + _L("The agent connects to the open OrcaSlicer while the MCP server is on. The setup holds " + "the access token, so don't share it.") : + _L("The agent starts this copy of OrcaSlicer when it isn't open, so set the agent up again " + "after OrcaSlicer moves.")); + m_mcp_transport_hint->Wrap(FromDIP(MCP_HINT_WIDTH)); + m_parent->Layout(); + m_parent->FitInside(); + }; + show_transport(); + m_mcp_transport->Bind(wxEVT_RADIOBOX, [show_transport](wxCommandEvent &e) { + show_transport(); + e.Skip(); + }); + + m_sizer->Add(m_mcp_transport, 0, wxALIGN_CENTER_VERTICAL); + return with_mcp_hint(m_sizer, m_mcp_transport_hint); +} + wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString tooltip) { wxBoxSizer *m_sizer = create_item_label(title, tooltip); @@ -1521,8 +1534,8 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString "restart opencode.")}, {"DeepSeek Harness", _L("Add the copied entry to cordis.patch.yml in the .dsh folder of your home folder, then " "restart DeepSeek Harness.")}, - {_L("Other apps"), _L("Add the copied settings to the app's MCP configuration file. The app runs OrcaSlicer from its " - "current location, so set it up again after OrcaSlicer moves.")}, + {_L("Other apps"), _L("Add the copied settings to the app's MCP configuration file. For an app that can't connect " + "over HTTP, choose stdio.")}, }; // Wide enough for "DeepSeek Harness"; the button gives up the room, narrower than other Parameter buttons. @@ -1536,16 +1549,12 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString auto copy_button = new Button(m_parent, _L("Copy")); copy_button->SetStyle(ButtonStyle::Regular, ButtonType::Parameter); copy_button->SetMinSize(FromDIP(MCP_COPY_BUTTON_SIZE)); + copy_button->SetToolTip(tooltip); m_mcp_copy_button = copy_button; m_mcp_agent_hint = new ::Label(m_parent, ::Label::Body_13, wxEmptyString); - m_mcp_agent_hint->SetForegroundColour(wxColour("#6B6B6B")); - auto show_agent = [this, agents, copy_button](int index) { - const bool http = McpAgent(index) != McpAgent::OtherApps; - copy_button->SetToolTip(http ? _L("Copy the setup for the chosen agent. It holds the access token, so keep it out of " - "files you share.") - : _L("Copy the setup for apps that run OrcaSlicer's MCP server as a command.")); + auto show_agent = [this, agents](int index) { m_mcp_agent_hint->SetLabel(agents[index].hint); m_mcp_agent_hint->Wrap(FromDIP(MCP_HINT_WIDTH)); m_parent->Layout(); @@ -1559,11 +1568,13 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString }); copy_button->Bind(wxEVT_BUTTON, [this, picker, confirm = confirm_on_button(copy_button, _L("Copied"))](wxCommandEvent &) { - const McpAgent agent = McpAgent(picker->GetSelection()); - const Mcp::McpService *mcp = wxGetApp().mcp_service(); - // The token the server uses: its own while it runs, otherwise the token file's, which turning it on reads. + const Mcp::Agent agent = Mcp::Agent(picker->GetSelection()); + const Mcp::Transport transport = Mcp::Transport(m_mcp_transport->GetSelection()); + const Mcp::McpService *mcp = wxGetApp().mcp_service(); + // The token the server uses: its own while it runs, otherwise the token file's, which turning it + // on reads. A stdio setup holds none: --mcp-stdio reads it from the discovery file. std::string token; - if (agent != McpAgent::OtherApps) { + if (transport == Mcp::Transport::Http) { std::string err; token = mcp != nullptr && mcp->serving() ? mcp->token() : Mcp::load_or_create_token(Mcp::path_from_utf8(data_dir()), err); if (token.empty()) { @@ -1572,7 +1583,8 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString } } if (wxTheClipboard->Open()) { - wxTheClipboard->SetData(new wxTextDataObject(from_u8(mcp_setup_text(agent, mcp_url(mcp, app_config), token)))); + const std::string setup = Mcp::agent_setup(agent, transport, mcp_url(mcp, app_config), token, mcp_executable()); + wxTheClipboard->SetData(new wxTextDataObject(from_u8(setup))); wxTheClipboard->Close(); confirm(); } @@ -1580,15 +1592,7 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_connect(wxString title, wxString m_sizer->Add(picker, 0, wxALIGN_CENTER_VERTICAL); m_sizer->Add(copy_button, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(6)); - - // The hint goes under the picker, at the start of the control column. - auto column = new wxBoxSizer(wxVERTICAL); - column->Add(m_sizer); - auto hint_row = new wxBoxSizer(wxHORIZONTAL); - hint_row->AddSpacer(FromDIP(DESIGN_LEFT_MARGIN + 5) + DESIGN_TITLE_SIZE.x); // create_item_label's margin, label and gap - hint_row->Add(m_mcp_agent_hint); - column->Add(hint_row, 0, wxTOP, FromDIP(2)); - return column; + return with_mcp_hint(m_sizer, m_mcp_agent_hint); } wxBoxSizer *PreferencesDialog::create_item_bambu_cloud(wxString title, wxString tooltip) @@ -1931,6 +1935,7 @@ void PreferencesDialog::on_dpi_changed(const wxRect &suggested_rect) { // Label::Wrap takes pixels, so the AI features texts wrap again at the new scale. m_mcp_intro->Wrap(FromDIP(MCP_INTRO_WIDTH)); m_mcp_status->Wrap(FromDIP(MCP_STATUS_WIDTH)); + m_mcp_transport_hint->Wrap(FromDIP(MCP_HINT_WIDTH)); m_mcp_agent_hint->Wrap(FromDIP(MCP_HINT_WIDTH)); m_mcp_copy_button->SetMinSize(FromDIP(MCP_COPY_BUTTON_SIZE)); // Rescale() restored the Parameter style's width @@ -2180,6 +2185,10 @@ void PreferencesDialog::create_items() _L("The address agents connect to over HTTP, with the access token.")); g_sizer->Add(item_mcp_address); + auto item_mcp_transport = create_item_mcp_transport(_L("Connection type"), + _L("How the agent you set up below connects to OrcaSlicer.")); + g_sizer->Add(item_mcp_transport); + auto item_mcp_connect = create_item_mcp_connect(_L("Add to an agent"), _L("Copy the setup that connects the chosen agent to OrcaSlicer.")); g_sizer->Add(item_mcp_connect); diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index ea1206d3e2..6c3d6d36aa 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -24,6 +24,7 @@ #include "Widgets/TabCtrl.hpp" #include "Widgets/Label.hpp" #include "Widgets/Button.hpp" +#include "Widgets/RadioGroup.hpp" #include "slic3r/Utils/bambu_networking.hpp" namespace Slic3r { namespace GUI { @@ -91,6 +92,8 @@ public: ::Label * m_mcp_status_dot = {nullptr}; ::Label * m_mcp_status = {nullptr}; ::Label * m_mcp_address = {nullptr}; + RadioGroup * m_mcp_transport = {nullptr}; + ::Label * m_mcp_transport_hint = {nullptr}; ::Label * m_mcp_agent_hint = {nullptr}; ::Button * m_mcp_copy_button = {nullptr}; ::CheckBox * m_skip_identical_frames_checkbox = {nullptr}; @@ -127,7 +130,9 @@ public: wxBoxSizer *create_item_bambu_cloud(wxString title, wxString tooltip); wxBoxSizer *create_item_mcp_server(wxString title, wxString tooltip); wxBoxSizer *create_item_mcp_address(wxString title, wxString tooltip); + wxBoxSizer *create_item_mcp_transport(wxString title, wxString tooltip); wxBoxSizer *create_item_mcp_connect(wxString title, wxString tooltip); + wxBoxSizer *with_mcp_hint(wxBoxSizer *row, ::Label *hint); void update_mcp_status(const std::string& note = {}); wxBoxSizer *create_item_network_plugin_version(wxString title, wxString tooltip); #ifdef WIN32 diff --git a/tests/slic3rutils/CMakeLists.txt b/tests/slic3rutils/CMakeLists.txt index d3d5b06cce..5dbc7417a7 100644 --- a/tests/slic3rutils/CMakeLists.txt +++ b/tests/slic3rutils/CMakeLists.txt @@ -27,6 +27,7 @@ add_executable(${_TEST_NAME}_tests test_mcp_operations.cpp test_mcp_protocol.cpp test_mcp_script.cpp + test_mcp_setup.cpp test_mcp_token.cpp test_mcp_tools.cpp test_mcp_ui.cpp diff --git a/tests/slic3rutils/test_mcp_setup.cpp b/tests/slic3rutils/test_mcp_setup.cpp new file mode 100644 index 0000000000..df77541435 --- /dev/null +++ b/tests/slic3rutils/test_mcp_setup.cpp @@ -0,0 +1,70 @@ +#include + +#include "slic3r/GUI/Mcp/McpSetup.hpp" + +#include + +#include + +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); +}