diff --git a/docs/HLSD/mcp-server.md b/docs/HLSD/mcp-server.md
index 744270d676..5fb5716672 100644
--- a/docs/HLSD/mcp-server.md
+++ b/docs/HLSD/mcp-server.md
@@ -2967,7 +2967,8 @@ plugin. A person runs one in the Run Script panel or with `--mcp-run file.py`; a
`run_script {code, args, timeout_s, filename}`; a plugin's code may call `run_script` too. A script that runs
under `python file.py` runs the same way here, and code written for a plugin's `execute()` (windows, progress,
presets, storage) runs from a script unchanged. A script is not a plugin: it gets no permission prompt and no
-grants, is never in the Plugins list, and ends when its work ends, leaving nothing loaded.
+grants, is never in the Plugins list, and ends when its work ends, leaving nothing loaded. It always runs; one
+setting decides whether the plugin permission checks hold it (The setting, below).
**Entry contract.** `run_python_code()` (`plugin/PythonScriptRunner.cpp`) runs the code on the calling thread, the
MCP job that runs `run_script`, holding an interpreter lease and the GIL, as a session with one file work (Run
@@ -3099,26 +3100,36 @@ code. The install isn't covered by the watcher; uv's 120 s timeout bounds it.
**Identity.** A person's script runs under the audit identity `script`, an agent's under `mcp`
(`kScriptIdentityPerson`, `kScriptIdentityAgent`); `McpService::person_run()` tells them apart by the run's
-lineage, since the panel's and `--mcp-run`'s jobs are marked as a person's (`as_person()`). Every audited
-access is allowed to these identities and logged under them (reads at debug level), apart from the categorical
-denies every plugin has (`is_denied_path()`): nothing contains the code, and the setting is the boundary. The
-threads, pool tasks and window callbacks of a run carry its identity. A run owns what its calls leave behind, as a
-replay does (`begin_run_scope()`): auto-answer rules, a recording and a held press end with it. The
-identities are reserved: a plugin whose key equals one is refused before any of its code runs. A plugin's
-`run_script` runs under the plugin's own identity and grants instead, with the same main-program environment, but
-its windows, callbacks and storage stay the plugin's.
+lineage, since the panel's and `--mcp-run`'s jobs are marked as a person's (`as_person()`). The plugin audit
+([plugin-permissions.md](plugin-permissions.md)) judges a script under its identity as it judges a plugin, with
+one difference: a script has no install state to hold a grant, so it is never asked, and what the implicit
+rules don't allow is denied with a `PermissionError` that names the setting. The threads, pool tasks and window
+callbacks of a run carry its identity. A run owns what its calls leave behind, as a replay does
+(`begin_run_scope()`): auto-answer rules, a recording and a held press end with it. The identities are
+reserved: a plugin whose key equals one is refused before any of its code runs, so a plugin is never judged as
+a script. A plugin's `run_script` runs under the plugin's own identity and grants instead, with the same
+main-program environment, but its windows, callbacks and storage stay the plugin's.
-**The setting.** One switch, `mcp_python_scripts`, off by default, lets both a person's scripts and an agent's
-`run_script` run; with it off they are refused (a plugin's `run_script` needs none). It is changed only in
-`PythonScriptsDialog`, opened from Preferences › AI features › Python scripts, which is named
-`kHiddenFromAutomation`: the UI tools never see it and `ModalTracker` leaves it off the stack, so no dialog tool or
-auto-answer rule reaches it. No tool writes the key, and `get_app_state.python.scripts_allowed` reads it, so an
-agent learns that `run_script` is off before it plans a run rather than from the refusal.
+**The setting.** One switch, `mcp_python_unrestricted`, off by default, decides how a person's scripts and an
+agent's `run_script` are judged (a plugin's `run_script` is the plugin's and ignores it). Off, a script is
+restricted: its Python code reads and writes OrcaSlicer's data folder, reads the resources folder, the standard
+library and, in a file run, the folder of its file (`PythonRunScope::allow_folder_reads()`, a scoped root on
+each of the run's threads, so its imports work), and is denied every other audited access: files elsewhere,
+programs, threads and the network. On, every audited access is allowed to it
+(`PluginAuditManager::set_scripts_unrestricted()`, which `apply_python_scripts_setting()` sets at startup and
+on a change, and the audit reads on whichever thread raises the event). The categorical denies every plugin has
+(`is_denied_path()`) hold either way. The audit is a Python audit hook, not a sandbox: the tools a script calls
+through `orca.host.tools` and the rest of `orca.host` run OrcaSlicer's own code and are not judged, so a
+restricted script still does what an agent's tool calls do. The setting is changed only in `PythonScriptsDialog`,
+opened from Preferences › AI features › Python scripts, which is named `kHiddenFromAutomation`: the UI tools never
+see it and `ModalTracker` leaves it off the stack, so no dialog tool or auto-answer rule reaches it. No tool
+writes the key, and `get_app_state.python.scripts_unrestricted` reads it, so an agent learns what its script may
+do before it plans a run rather than from a refusal.
**The host surface and the bridge.** A script reaches the whole `orca.host`, as a plugin does: reads, `orca.host.ui`
(message boxes, progress dialogs, HTML windows, dock panels, notifications), the staged preset update, bundle
reload and the 3MF copy; nothing is plugin-only. `orca.host.plugin.storage()` is a script's own folder, the folder
-of its file; code sent as text has none. `orca.host.tools.call(name, args)` and `run_replay(replay, vars)`, whose
+of its file, which a restricted script reads but doesn't write; code sent as text has none. `orca.host.tools.call(name, args)` and `run_replay(replay, vars)`, whose
replay is a dict or its JSON text (`plugin/host/PluginHostTools.cpp`), reach the tools from any thread of the run
while it lasts, through the run's bridge: its calls are `ToolContext::call_child()` of the `run_script` job, so
each has its tool's guards, admission and undo, and the GIL is released while it waits. At the end the bridge
@@ -3213,8 +3224,7 @@ presses are released as each work ends (`release_run_presses()`). Its `orca.host
`LineageNode`, a running idle job under the session's job that only parents calls: a stop requests the stop for the
node and cancels its operations (`cancel_operations_of()`), so every call in flight, inline ones such as `wait`
included, returns at once while the session goes on, and the next work after a stop starts once that cancelling is done,
-under a renewed node. With Python
-scripts off the job refuses before it hosts anything, and turning them off ends the session.
+under a renewed node.
**Stop.** Stop interrupts what runs now: the work, and the session's threads and tasks; while the session is idle a
stop reaches its threads and tasks for five seconds (`kStopWindow`), and the session goes on. A stop moves the run
@@ -3223,7 +3233,7 @@ before it ran") while one submitted later does, and ends the session's message b
thread (`PluginHostUi::end_run_modals()`), so code waiting in them can be interrupted, leaving its modeless windows,
dock panels and callbacks open. A cancel or time-out of the job reaches everything until the end, and ends the
session. A Run all still waiting for the old session to end is dropped by Stop and reported stopped. Restart session, Close script, New, Open, a recent or dropped script, Run all (which runs in a session of
-its own, as `python file.py` does), turning Python scripts off, quitting and a main-window rebuild end the session
+its own, as `python file.py` does), quitting and a main-window rebuild end the session
and stop it, so it ends as a stopped run does: its threads get five seconds, its `atexit` functions run once, and
what the teardown runs can be interrupted, as a stop asked once the session is ending reaches its teardown even when
nothing else was live; then its windows close and its folder's helpers are evicted.
@@ -3251,8 +3261,8 @@ editor's share of the width, so a resized pane keeps its proportions; a drag sto
console, and its arrow keys, Home and End and double-click (back to 60%) work as a window splitter's. The arrows on its
grip hide a side, as does a drag that ends 48 px past a side's smallest width; a hidden side leaves a strip at its edge
that brings it back at its width: the editor's shows each cell's bar, the console's a dot for a run going, output not
-seen, or a failed run. The console's side hides only while it shows the console, never the start page or the note that
-Python is off. The share and the hidden side are AppConfig `run_script` › `split` and `hidden_side`, saved when a drag
+seen, or a failed run. The console's side hides only while it shows the console, never the start page. The share and
+the hidden side are AppConfig `run_script` › `split` and `hidden_side`, saved when a drag
ends rather than as it moves.
**Out of the tools' reach.** Like Action Replay's page, the page navigates nowhere but its own loads: a dropped
@@ -3278,18 +3288,16 @@ that has the focus (the console prompt) takes the forwarded Undo, Redo and Selec
## Plugins and the tools
-A plugin's code calls the tools through `orca.host.tools` once it holds the `tools` permission
-(`PluginPermissions::tools`), which it declares with `request_permissions(tools=True)`. The person answers
-it at load in its own prompt (`request_tools_permission()`), apart from the plugin's other permissions,
-and a refusal leaves the plugin loading without it. With the permission a plugin can do what an agent can:
-work in the GUI, answer dialogs, replace the project, write presets and files; the prompt says so. A plugin's
-`run_script` is the plugin's own code: its identity and grants, its windows and storage, though it runs as a main
-program as any script does.
+A plugin's code calls the tools through `orca.host.tools`, with no permission of its own: any loaded plugin
+can do what an agent can, work in the GUI, answer dialogs, replace the project, write presets and files. The
+tools run OrcaSlicer's own code, which the plugin audit doesn't judge, so a plugin's grants bound its Python
+code and not what it asks the tools to do. A plugin's `run_script` is the plugin's own code: its identity and
+grants, its windows and storage, though it runs as a main program as any script does.
A plugin's call waits for the UI thread, so it comes only from a thread nothing there waits for: a Script
worker, a Python thread one starts (the thread shim carries the mark) or MCP's own thread running a plugin
operation (`ScopedToolCallerThread`). A call from the UI thread, a slicing hook or another plugin callback
-is refused before anything waits. `install_plugin_tool_caller()` routes a permitted plugin's calls. The UI
+is refused before anything waits. `install_plugin_tool_caller()` routes a plugin's calls. The UI
thread, which owns the service and runs the plugin's unload, admits each one: the plugin must still be
loaded and its scope not ended, and the service is started in its catalog-only mode when MCP is off; the
call then holds a lease the service's drain waits for. A caller that stops waiting because the app closes
@@ -3315,9 +3323,8 @@ since plugin code may write the log folder. A plugin's window callbacks run with
so their calls are refused.
**Plugin operations.** A plugin may offer operations to agents, replays and scripts with
-`orca.register_operation(name, description, schema, handler, changes)` while it loads. The person grants
-each one in its own prompt (`request_operation_permission()`, saved in `PluginPermissions::operations`);
-a refused one is not offered. Granted operations are staged and offered once the plugin's load has committed
+`orca.register_operation(name, description, schema, handler, changes)` while it loads, without a prompt.
+Its operations are staged and offered once the plugin's load has committed
(`PluginOperations::activate()`, in one step under the lock an unload's withdrawal takes); any exit of a
load that did not commit, an exception included, drops them, and they are withdrawn when the plugin
unloads. An operation is reached as
diff --git a/docs/HLSD/plugin-permissions.md b/docs/HLSD/plugin-permissions.md
index ceb84ff901..7b72007e17 100644
--- a/docs/HLSD/plugin-permissions.md
+++ b/docs/HLSD/plugin-permissions.md
@@ -118,6 +118,20 @@ order:
After a granted root event with a target, the hook records the operation frame so the
nested events of the same operation are not asked again.
+### Python scripts
+
+A Python script run from the Run Script panel, with `--mcp-run` or by an agent's `run_script`
+is not a plugin, but its events are judged here under a reserved identity, `script` or `mcp`
+(see "Python scripts" in [mcp-server.md](mcp-server.md)). A script has no sidecar, so it holds
+no grant and is never asked: steps 1 to 3 apply to it, and any other event is denied with a
+`PermissionError` that names the setting below. A file run also reads the folder of its file,
+through a per-call scoped root.
+
+The "Run Python scripts unrestricted" setting (Preferences, AI features, Python scripts; off by
+default) lifts this for every script: while it is on, a script's event is allowed right after
+step 1, so only the denied paths stay blocked. No plugin key may equal a script identity; such a
+plugin is refused at load.
+
## Permission prompts
### Declared permissions during load
@@ -285,7 +299,9 @@ never treated as an opt-out.
- **Host APIs are not audit events.** Calls into OrcaSlicer's Python host APIs, such as
preset updates or UI actions, execute C++ host code and follow that API's contract. The
audit hook judges the Python-level filesystem, network, process and thread events it is
- given, not the host API's internal work.
+ given, not the host API's internal work. That includes `orca.host.tools`, through which any
+ plugin calls the MCP tools: it can write the files those tools write and answer dialogs,
+ permission prompts included.
- **Denied paths are a direct-access block.** Path laundering through a symlink,
hardlink, subprocess, or Windows 8.3 short name is outside the model. A tree grant is
canonicalized for matching, but the deny check itself is base-name and component based.
diff --git a/resources/web/dialog/RunScript/index.html b/resources/web/dialog/RunScript/index.html
index fcecf3d742..e0b63c766c 100644
--- a/resources/web/dialog/RunScript/index.html
+++ b/resources/web/dialog/RunScript/index.html
@@ -111,14 +111,6 @@
No recent scripts
-
-
-
Python scripts are off.
-
You can edit and save this script, but it can't run until Python scripts are on.
-
A script runs with OrcaSlicer's full access to your computer.
-
-
Turn on Python scripts…
-
diff --git a/resources/web/dialog/RunScript/run_script.js b/resources/web/dialog/RunScript/run_script.js
index fbc59a3df7..80099a7ff0 100644
--- a/resources/web/dialog/RunScript/run_script.js
+++ b/resources/web/dialog/RunScript/run_script.js
@@ -3,7 +3,6 @@
// the host's copy is never behind.
const S = {
- python: true,
ready: false,
none: true, // no script open
fileName: "",
@@ -198,8 +197,8 @@ const NEWS_TIPS = {
failed: ["show_console_failed", "Show the console: the last run failed"],
};
-// Whether the side right of the divider shows the console, rather than the start page or the note that Python is off.
-function consoleShown() { return !S.none && S.python; }
+// Whether the side right of the divider shows the console, rather than the start page.
+function consoleShown() { return !S.none; }
function renderLayout() {
const panes = $("panes");
@@ -313,7 +312,7 @@ function setUpSplit() {
function busy() { return !!S.pending || !!S.run || S.session === "working"; }
-function canRun() { return S.python && S.ready && !S.none && !busy() && S.session !== "ending"; }
+function canRun() { return S.ready && !S.none && !busy() && S.session !== "ending"; }
function runAll() {
closeEditorSuggestions(editor);
@@ -342,7 +341,7 @@ function runCell() {
function runConsole() {
const input = $("prompt-input");
const code = input.value;
- if (!code.trim() || !S.python || !S.ready || busy() || S.session === "ending") return;
+ if (!code.trim() || !S.ready || busy() || S.session === "ending") return;
input.value = "";
S.pending = { kind: "console", code };
S.message = null;
@@ -726,7 +725,7 @@ function renderStatus() {
bar.classList.add("is-error");
$("status-main").textContent = S.message;
$("status-detail").textContent = "";
- } else if (S.python && !S.ready) {
+ } else if (!S.ready) {
$("status-main").textContent = T("starting", "OrcaSlicer is still starting…");
$("status-detail").textContent = "";
} else {
@@ -748,7 +747,7 @@ function render() {
$("run-cell").disabled = !canRun();
$("stop").disabled = !(working || S.session === "threads");
$("restart").disabled = S.session === "none" || working || ending;
- const promptOff = !S.python || !S.ready || working || ending;
+ const promptOff = !S.ready || working || ending;
$("prompt-input").disabled = promptOff;
$("prompt-input").closest(".prompt-line").classList.toggle("off", promptOff);
@@ -757,8 +756,7 @@ function render() {
editor.setReadOnly(S.none || !!S.run);
$("editor").classList.toggle("is-readonly", !!S.run);
$("start").hidden = !S.none;
- $("off").hidden = S.none || S.python;
- $("console").hidden = S.none || !S.python;
+ $("console").hidden = S.none;
renderLayout();
placeAddButton();
renderSession();
@@ -914,7 +912,6 @@ function onForwardedKey(action) {
function HandleStudio(msg) {
switch (msg.command) {
case "state":
- S.python = !!msg.python_on;
S.ready = !!msg.ready;
S.recent = msg.recent || [];
S.session = msg.session || "none";
@@ -963,10 +960,6 @@ function HandleStudio(msg) {
break;
case "key": onForwardedKey(msg.action); break;
case "shortcuts": setToggleChord(msg.toggle_key && msg.toggle_key.chord); break;
- case "python":
- S.python = !!msg.on;
- render();
- break;
}
}
@@ -1038,7 +1031,6 @@ function OnInit() {
$("stop").addEventListener("click", () => send("stop"));
$("restart").addEventListener("click", () => send("restart"));
$("clear").addEventListener("click", clearConsole);
- $("turn-on").addEventListener("click", () => send("turn_on_python"));
$("prompt-input").addEventListener("keydown", (e) => {
if (e.key === "Enter" && !e.shiftKey && !e.ctrlKey && !e.metaKey && !e.altKey) {
e.preventDefault();
diff --git a/resources/web/dialog/RunScript/run_script.test.js b/resources/web/dialog/RunScript/run_script.test.js
index 206f871a33..eac3421137 100644
--- a/resources/web/dialog/RunScript/run_script.test.js
+++ b/resources/web/dialog/RunScript/run_script.test.js
@@ -308,7 +308,7 @@ test("the console's strip shows a run going, then new output, and a failed run u
assert.equal(model.consoleNews("failed", "start"), "running");
});
-test("the console's side hides only while it shows the console, not the start page or the note that Python is off", () => {
+test("the console's side hides only while it shows the console, not the start page", () => {
assert.equal(model.hiddenSide("console", true), "console");
assert.equal(model.hiddenSide("console", false), "");
assert.equal(model.hiddenSide("editor", false), "editor");
diff --git a/resources/web/dialog/RunScript/run_script_model.js b/resources/web/dialog/RunScript/run_script_model.js
index b9369cee8c..6d8b44335d 100644
--- a/resources/web/dialog/RunScript/run_script_model.js
+++ b/resources/web/dialog/RunScript/run_script_model.js
@@ -360,8 +360,7 @@
}
// The side hidden as the panel draws it, from the side the layout hides. The console's side hides only while it shows
- // the console (`consoleShown`): with no script open or Python off it holds the start page or the note about Python,
- // which stay in sight.
+ // the console (`consoleShown`): with no script open it holds the start page, which stays in sight.
function hiddenSide(hidden, consoleShown) { return hidden === "console" && !consoleShown ? "" : hidden; }
// What the hidden console's strip shows after `event` (start, output, finished, failed), from what it shows now
diff --git a/resources/web/dialog/RunScript/style.css b/resources/web/dialog/RunScript/style.css
index 2f37197cd1..91875e61cc 100644
--- a/resources/web/dialog/RunScript/style.css
+++ b/resources/web/dialog/RunScript/style.css
@@ -14,7 +14,6 @@
--rs-ring: rgba(0, 150, 136, 0.25);
--rs-ring-soft: rgba(0, 150, 136, 0.08);
--rs-fail: var(--plugin-status-danger, #b42318);
- --rs-warn: var(--plugin-status-warn, #a15c00);
--rs-chrome: var(--footer-bg, #f3f4f5);
--rs-console: #fbfcfc;
--rs-btn-bg: var(--btn-bg, #ffffff);
@@ -401,7 +400,6 @@ html, body {
.recent .f { font-weight: 600; white-space: nowrap; }
.recent .d { color: var(--rs-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.label-sm { font-size: 12px; color: var(--rs-muted); margin: 0 0 6px; }
-.off-note { border-left: 3px solid var(--rs-warn); padding: 2px 0 2px 12px; margin-bottom: 14px; }
/* ---- status line, while a run goes ---- */
.statusline { display: flex; align-items: center; gap: 10px; padding: 4px 10px; border-top: 1px solid var(--rs-rule); background: var(--rs-chrome); font-size: 12px; color: var(--rs-muted); flex: none; }
diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp
index ca0abf4ed6..e2740baf94 100644
--- a/src/slic3r/GUI/GUI_App.cpp
+++ b/src/slic3r/GUI/GUI_App.cpp
@@ -256,6 +256,7 @@
#include "slic3r/GUI/Gizmos/GLGizmosManager.hpp"
#include "slic3r/GUI/HttpServer.hpp"
#include "slic3r/GUI/Mcp/McpOptions.hpp"
+#include "slic3r/GUI/Mcp/PythonScriptsDialog.hpp"
#include "slic3r/GUI/Mcp/McpService.hpp"
#include "slic3r/plugin/PluginOperations.hpp"
#include "slic3r/GUI/ImGuiWrapper.hpp"
@@ -3104,6 +3105,7 @@ void GUI_App::init_plugin_gui_wiring()
plugin_mgr.subscribe_on_unload_callback(PluginHostUi::close_windows_for_plugin);
Mcp::install_plugin_tool_caller();
+ Mcp::apply_python_scripts_setting(*app_config);
// A plugin loaded again may make tool calls again.
plugin_mgr.subscribe_on_load_callback([](const std::string& plugin_key) {
if (wxTheApp != nullptr)
diff --git a/src/slic3r/GUI/Mcp/McpOptions.hpp b/src/slic3r/GUI/Mcp/McpOptions.hpp
index 549f794ae4..149fff4113 100644
--- a/src/slic3r/GUI/Mcp/McpOptions.hpp
+++ b/src/slic3r/GUI/Mcp/McpOptions.hpp
@@ -7,10 +7,10 @@ namespace Slic3r { namespace GUI { namespace Mcp {
// Default port of the MCP endpoint; 13618 is the OAuth callback server.
inline constexpr int kDefaultPort = 13619;
-// The app config key of the Python scripts setting: one switch, off unless true, that lets a person run
-// .py scripts (the Run Script dialog, --mcp-run) and agents send run_script. Only the window
-// show_python_scripts_dialog() opens writes it; no tool does.
-inline constexpr char kPythonScriptsKey[] = "mcp_python_scripts";
+// The app config key of the unrestricted Python scripts setting: one switch, off unless true. While it is on,
+// the scripts a person runs (the Run Script panel, --mcp-run) and agents send (run_script) skip the plugin
+// permission checks. Only the window show_python_scripts_dialog() opens writes it; no tool does.
+inline constexpr char kPythonUnrestrictedKey[] = "mcp_python_unrestricted";
// MCP settings from the command line. Paths are absolute: OrcaSlicer.cpp resolves them
// against the original working directory before the GUI changes it.
diff --git a/src/slic3r/GUI/Mcp/McpPluginCaller.cpp b/src/slic3r/GUI/Mcp/McpPluginCaller.cpp
index d691919867..fdecbeb7ba 100644
--- a/src/slic3r/GUI/Mcp/McpPluginCaller.cpp
+++ b/src/slic3r/GUI/Mcp/McpPluginCaller.cpp
@@ -5,7 +5,6 @@
#include "McpTypes.hpp"
#include "slic3r/GUI/GUI_App.hpp"
-#include "slic3r/plugin/PluginFsUtils.hpp"
#include "slic3r/plugin/PluginManager.hpp"
#include "slic3r/plugin/host/PluginHostTools.hpp"
@@ -108,10 +107,6 @@ std::string named_paths(const json& args)
void install_plugin_tool_caller()
{
set_plugin_tool_caller([](const std::string& plugin, const std::string& tool, const json& args) -> json {
- PluginInstallState state;
- if (!PluginManager::instance().get_install_state(plugin, state) || !state.permissions.tools)
- throw std::runtime_error("This plugin has not been granted the tools permission; it asks for it with "
- "request_permissions(tools=True)");
McpService* service = admit_plugin_call(plugin);
struct Lease
{
diff --git a/src/slic3r/GUI/Mcp/McpService.cpp b/src/slic3r/GUI/Mcp/McpService.cpp
index e6e5ff2efe..5139e927eb 100644
--- a/src/slic3r/GUI/Mcp/McpService.cpp
+++ b/src/slic3r/GUI/Mcp/McpService.cpp
@@ -167,8 +167,8 @@ const char* kInstructions =
"or cancel_job.\n"
"- export_replay saves this session's calls as a replay that run_replay runs.\n"
"- run_script runs Python against orca.host, the plugin API (search_python_api searches it), computing over meshes and "
- "settings and calling tools through orca.host.tools, once the person has allowed Python scripts in Preferences "
- "(get_app_state.python.scripts_allowed).\n"
+ "settings and calling tools through orca.host.tools; its own file, program, thread and network use is restricted "
+ "unless get_app_state.python.scripts_unrestricted.\n"
"- Not sure what does something? search_tools {query} searches every catalog at once: the tools, the operations "
"plugins offer (plugin.., which the tool list does not show; call_tool runs them), Speed Dial actions, "
"settings, the Python API and the Design tab's CAD tools, each match with how to use it.\n"
diff --git a/src/slic3r/GUI/Mcp/McpService.hpp b/src/slic3r/GUI/Mcp/McpService.hpp
index 1998f88cb3..3c498ed451 100644
--- a/src/slic3r/GUI/Mcp/McpService.hpp
+++ b/src/slic3r/GUI/Mcp/McpService.hpp
@@ -292,9 +292,9 @@ private:
std::set m_unloaded_plugins; // under m_rules_mutex
};
-// Lets plugins call the tools through orca.host.tools: a call from a Script worker of a plugin holding the
-// tools permission runs as McpCore::call_plugin(), starting the service in its catalog-only mode when MCP
-// is off, and is logged. Called once by GUI_App as it sets up plugins.
+// Lets plugins call the tools through orca.host.tools: a call from a plugin's Script worker runs as
+// McpCore::call_plugin(), starting the service in its catalog-only mode when MCP is off, and is logged.
+// Called once by GUI_App as it sets up plugins.
void install_plugin_tool_caller();
}}} // namespace Slic3r::GUI::Mcp
diff --git a/src/slic3r/GUI/Mcp/McpTools.hpp b/src/slic3r/GUI/Mcp/McpTools.hpp
index 7cc1e403b5..58e0b8d078 100644
--- a/src/slic3r/GUI/Mcp/McpTools.hpp
+++ b/src/slic3r/GUI/Mcp/McpTools.hpp
@@ -185,7 +185,7 @@ nlohmann::json rank_python_api(const nlohmann::json& reference, const std::strin
// Takes the GIL, as python_api_reference() does.
bool python_has_numpy();
-// The Run Script panel's session as the calling job, a person's run_script job: refused while Python scripts are off.
+// The Run Script panel's session as the calling job, a person's run_script job.
// The job is idle for `wait {for: "idle"}`, and owns what the session's tool calls leave behind (auto-answer rules, a
// recording, a held press) until the session ends, with its rules paused between works and its presses released as each
// work ends. The calls hang under a lineage node of the job, which a stop cancels, inline calls included, and which the
diff --git a/src/slic3r/GUI/Mcp/McpToolsApp.cpp b/src/slic3r/GUI/Mcp/McpToolsApp.cpp
index 36f82a6bb3..6c5a931d12 100644
--- a/src/slic3r/GUI/Mcp/McpToolsApp.cpp
+++ b/src/slic3r/GUI/Mcp/McpToolsApp.cpp
@@ -112,7 +112,7 @@ json app_state(McpService& service)
{"mcp", service.describe()},
{"python",
{{"available", PythonInterpreter::instance().is_initialized()},
- {"scripts_allowed", python_scripts_allowed(*wxGetApp().app_config)}}},
+ {"scripts_unrestricted", python_scripts_unrestricted(*wxGetApp().app_config)}}},
{"jobs", service.jobs().list()}};
if (json recording = service.recorder().state(); !recording.is_null())
state["recording"] = std::move(recording);
@@ -249,8 +249,8 @@ void register_app_tools(McpService& service)
"and display backend, whether it is ready, the main window, the displays (each one's work area x, y, width and "
"height, as set_window takes positions, its scale and whether it is primary), the MCP endpoint (mcp), python "
"(available: Python runs "
- "in this build; scripts_allowed: run_script may run, which only a person turns on, in Preferences > AI features > "
- "Python scripts) and design_tab (the Design tab and call_cad_tool are on; a person turns the CAD feature on in "
+ "in this build; scripts_unrestricted: a script's own file, network, process and thread access is not held to "
+ "OrcaSlicer's folders, which only a person turns on, in Preferences > AI features > Python scripts) and design_tab (the Design tab and call_cad_tool are on; a person turns the CAD feature on in "
"Preferences and restarts). The project: current tab and mode, printer technology, name, path and unsaved changes, "
"selected printer/process/filament presets, plates (count, current), object count, the selection (objects, the "
"instances [[object, instance]] they are selected in and, when parts rather than whole instances are selected, "
diff --git a/src/slic3r/GUI/Mcp/McpToolsPython.cpp b/src/slic3r/GUI/Mcp/McpToolsPython.cpp
index dcac273bd5..58c872cc97 100644
--- a/src/slic3r/GUI/Mcp/McpToolsPython.cpp
+++ b/src/slic3r/GUI/Mcp/McpToolsPython.cpp
@@ -6,7 +6,6 @@
#include "McpService.hpp"
#include "McpTools.hpp"
#include "McpTypes.hpp"
-#include "PythonScriptsDialog.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "slic3r/GUI/I18N.hpp"
@@ -248,10 +247,6 @@ bool python_has_numpy()
ToolResult run_python_session_job(McpService& service, ToolContext& ctx, PythonSession& session, const std::string& filename)
{
- const bool allowed = ctx.observe_ui([] { return json(python_scripts_allowed(*wxGetApp().app_config)); }).get();
- if (!allowed)
- throw ToolFailure("Python scripts are off. A person can allow them in Preferences > AI features > Python scripts.");
-
const std::string job = ctx.job_id();
// The session waits for the person between works: `wait {for: "idle"}` counts only the calls it makes.
service.jobs().set_idle(job);
@@ -298,8 +293,11 @@ void register_python_tools(McpService& service)
"thread, where calls documented as UI thread only raise RuntimeError. The run ends once its code and the non-daemon "
"threads and pool tasks it started are done; its windows close with it. `args` holds the args you pass; set `result` "
"to a JSON value to return it; print() output comes back as output. Reply: {status: finished | raised | cancelled | "
- "timed_out, result, output, traceback?, message?}; a script that raised changed what it changed before. Python runs "
- "with OrcaSlicer's full access to the computer, so a person must allow Python scripts in Preferences first. Recorded "
+ "timed_out, result, output, traceback?, message?}; a script that raised changed what it changed before. The code's "
+ "own file access is held to OrcaSlicer's folders (its data and resources folders, and for a file run the file's "
+ "folder, read only), and it starts no programs or threads and reaches no network: such an access raises "
+ "PermissionError, unless a person has let Python scripts run unrestricted in Preferences "
+ "(get_app_state.python.scripts_unrestricted); the tools it calls work as they do for you. Recorded "
"by export_replay as one step with its code, which a replay runs again against the project as it is then.",
object_schema({{"code", prop("string", "Python source, run as a module body.")},
{"args", {{"type", "object"}, {"description", "Bound to the name `args` in the code."}}},
@@ -310,18 +308,11 @@ void register_python_tools(McpService& service)
"from its folder and its PEP 723 dependencies; any other name only names it.")}},
{"code"}),
[&service](const json& args, ToolContext& ctx) {
- const std::string& plugin = ctx.caller_plugin();
- std::string identity;
- if (!plugin.empty()) {
- // A plugin's script is the plugin's own code: its identity and grants, no setting.
- identity = plugin;
- } else {
- identity = service.person_run(ctx.lineage()) ? kScriptIdentityPerson : kScriptIdentityAgent;
- const bool allowed = ctx.observe_ui([] { return json(python_scripts_allowed(*wxGetApp().app_config)); }).get();
- if (!allowed)
- throw ToolFailure("Python scripts are off. A person can allow them in Preferences > AI features > Python "
- "scripts; no tool can.");
- }
+ // A plugin's script is the plugin's own code: its identity and grants.
+ const std::string& plugin = ctx.caller_plugin();
+ const std::string identity = !plugin.empty() ? plugin :
+ service.person_run(ctx.lineage()) ? kScriptIdentityPerson :
+ kScriptIdentityAgent;
// A run owns what its calls leave behind (auto-answer rules, a recording, a held press) as a JSON
// script does: it all ends with the run.
@@ -364,7 +355,7 @@ void register_python_tools(McpService& service)
});
// cancel_job {job} stops a run: its code is interrupted at its next bytecode.
run.cancellable = true;
- // Python has the app's full access to the computer.
+ // A script reaches outside the app: files, programs and the network.
run.open_world = true;
reg.add(run);
diff --git a/src/slic3r/GUI/Mcp/PythonScriptsDialog.cpp b/src/slic3r/GUI/Mcp/PythonScriptsDialog.cpp
index 3f5aad0930..3588e81b26 100644
--- a/src/slic3r/GUI/Mcp/PythonScriptsDialog.cpp
+++ b/src/slic3r/GUI/Mcp/PythonScriptsDialog.cpp
@@ -8,13 +8,11 @@
#include "slic3r/GUI/GUI_Utils.hpp"
#include "slic3r/GUI/I18N.hpp"
#include "slic3r/GUI/MainFrame.hpp"
-#include "slic3r/GUI/RunScriptPanel.hpp"
#include "slic3r/GUI/Widgets/CheckBox.hpp"
#include "slic3r/GUI/Widgets/DialogButtons.hpp"
#include "slic3r/GUI/Widgets/Label.hpp"
-#include "slic3r/GUI/Widgets/StateColor.hpp"
+#include "slic3r/plugin/PluginAuditManager.hpp"
-#include
#include
#include
#include
@@ -41,24 +39,17 @@ public:
auto* sizer = new wxBoxSizer(wxVERTICAL);
m_about = new Label(this, Label::Body_13,
- _L("When this is on, you can run Python scripts (.py files) in the Run Script panel and with "
- "--mcp-run, and AI agents connected to the MCP server can send Python code to run inside "
- "OrcaSlicer."));
+ _L("Python scripts are subject to the same permission checks as plugins: the scripts you run in "
+ "the Run Script panel or with --mcp-run, and the ones AI agents send through the MCP server. "
+ "When this option is on, they bypass the permission checks, which is useful for fully "
+ "automated workflows."));
m_about->Wrap(FromDIP(kTextWidth));
sizer->Add(m_about, 0, wxLEFT | wxRIGHT | wxTOP, FromDIP(16));
- m_warning = new Label(this, Label::Body_13,
- _L("A Python script runs with OrcaSlicer's full access to your computer: it can read and change "
- "your files and reach the network. Turning this on for your own scripts also lets connected "
- "agents send scripts, so turn it on only while you trust them."));
- m_warning->SetForegroundColour(StateColor::darkModeColorFor(wxColour("#B05A00")));
- m_warning->Wrap(FromDIP(kTextWidth));
- sizer->Add(m_warning, 0, wxLEFT | wxRIGHT | wxTOP, FromDIP(12));
-
auto* row = new wxBoxSizer(wxHORIZONTAL);
m_allow = new ::CheckBox(this);
- m_allow->SetValue(python_scripts_allowed(*wxGetApp().app_config));
- auto* text = new Label(this, _L("Allow Python scripts"));
+ m_allow->SetValue(python_scripts_unrestricted(*wxGetApp().app_config));
+ auto* text = new Label(this, _L("Run Python scripts unrestricted"));
row->Add(m_allow, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, FromDIP(6));
row->Add(text, 0, wxALIGN_CENTER_VERTICAL);
sizer->Add(row, 0, wxALL, FromDIP(16));
@@ -80,20 +71,23 @@ protected:
{
m_allow->Rescale();
m_about->Wrap(FromDIP(kTextWidth));
- m_warning->Wrap(FromDIP(kTextWidth));
GetSizer()->SetSizeHints(this);
Refresh();
}
private:
- Label* m_about = nullptr;
- Label* m_warning = nullptr;
- ::CheckBox* m_allow = nullptr;
+ Label* m_about = nullptr;
+ ::CheckBox* m_allow = nullptr;
};
} // namespace
-bool python_scripts_allowed(const AppConfig& config) { return config.get_bool(kPythonScriptsKey); }
+bool python_scripts_unrestricted(const AppConfig& config) { return config.get_bool(kPythonUnrestrictedKey); }
+
+void apply_python_scripts_setting(const AppConfig& config)
+{
+ PluginAuditManager::instance().set_scripts_unrestricted(python_scripts_unrestricted(config));
+}
bool show_python_scripts_dialog(wxWindow* parent)
{
@@ -102,11 +96,10 @@ bool show_python_scripts_dialog(wxWindow* parent)
return false;
AppConfig& config = *wxGetApp().app_config;
const bool allow = dialog.allow();
- if (allow == python_scripts_allowed(config))
+ if (allow == python_scripts_unrestricted(config))
return false;
- config.set_bool(kPythonScriptsKey, allow);
- if (RunScriptPanel* panel = wxGetApp().run_script_panel_if_built())
- panel->python_setting_changed();
+ config.set_bool(kPythonUnrestrictedKey, allow);
+ apply_python_scripts_setting(config);
return true;
}
diff --git a/src/slic3r/GUI/Mcp/PythonScriptsDialog.hpp b/src/slic3r/GUI/Mcp/PythonScriptsDialog.hpp
index 7d2411dd7e..9c98d8ccf3 100644
--- a/src/slic3r/GUI/Mcp/PythonScriptsDialog.hpp
+++ b/src/slic3r/GUI/Mcp/PythonScriptsDialog.hpp
@@ -8,11 +8,15 @@ class AppConfig;
namespace GUI { namespace Mcp {
-// Whether the Python scripts setting is on in `config`.
-bool python_scripts_allowed(const AppConfig& config);
+// Whether the unrestricted Python scripts setting is on in `config`.
+bool python_scripts_unrestricted(const AppConfig& config);
-// Opens the window that turns Python scripts on or off, modal on `parent`. The window is hidden from
-// automation (kHiddenFromAutomation), so no MCP tool, script or plugin can find, operate or answer it:
+// Passes the setting in `config` on to the plugin audit, which judges a script's accesses by it. Called once
+// the app config is loaded, and by the setting's window on a change.
+void apply_python_scripts_setting(const AppConfig& config);
+
+// Opens the window that lets Python scripts run unrestricted or not, modal on `parent`. The window is hidden
+// from automation (kHiddenFromAutomation), so no MCP tool, script or plugin can find, operate or answer it:
// only a person changes the setting. Returns whether it changed. UI thread.
bool show_python_scripts_dialog(wxWindow* parent);
diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp
index 33594ab609..d8deb84f80 100644
--- a/src/slic3r/GUI/Preferences.cpp
+++ b/src/slic3r/GUI/Preferences.cpp
@@ -1731,7 +1731,7 @@ wxBoxSizer *PreferencesDialog::create_item_mcp_python(wxString title, wxString t
auto state = new ::Label(m_parent, wxEmptyString);
auto show_state = [this, state] {
- state->SetLabel(Mcp::python_scripts_allowed(*app_config) ? _L("Allowed") : _L("Not allowed"));
+ state->SetLabel(Mcp::python_scripts_unrestricted(*app_config) ? _L("Unrestricted") : _L("Restricted"));
};
show_state();
@@ -2244,8 +2244,7 @@ void PreferencesDialog::create_items()
g_sizer->Add(item_mcp_connect);
auto item_mcp_python = create_item_mcp_python(_L("Python scripts"),
- _L("Whether you can run Python scripts and connected agents can send them. Python code runs with OrcaSlicer's full "
- "access to your computer."));
+ _L("Whether Python scripts are subject to the same permission checks as plugins, or bypass them."));
g_sizer->Add(item_mcp_python);
update_mcp_status();
diff --git a/src/slic3r/GUI/RunScriptPanel.cpp b/src/slic3r/GUI/RunScriptPanel.cpp
index b36d10d14e..b8868bdaef 100644
--- a/src/slic3r/GUI/RunScriptPanel.cpp
+++ b/src/slic3r/GUI/RunScriptPanel.cpp
@@ -15,7 +15,6 @@
#include "Mcp/McpService.hpp"
#include "Mcp/McpTools.hpp"
#include "Mcp/McpTypes.hpp"
-#include "Mcp/PythonScriptsDialog.hpp"
#include "Widgets/WebView.hpp"
#include "Widgets/WebViewHostDialog.hpp"
#include "libslic3r/AppConfig.hpp"
@@ -206,10 +205,6 @@ json page_strings()
"orca.host API. Split it into cells with %s and try one cell at a time.")},
// TRN A line in the console of the Run Script panel, where Run all started a new session.
{"session_restarted", _u8L("Session restarted for Run all")},
- {"python_off_text", _u8L("You can edit and save this script, but it can't run until Python scripts are on.")},
- {"python_off", _u8L("Python scripts are off.")},
- {"python_access", _u8L("A script runs with OrcaSlicer's full access to your computer.")},
- {"turn_on_python", _u8L("Turn on Python scripts…")},
{"starting", _u8L("OrcaSlicer is still starting…")},
{"code_editor", WebViewHostDialog::code_editor_strings()},
};
@@ -484,14 +479,6 @@ void RunScriptPanel::main_window_rebuilt()
wxWakeUpIdle();
}
-void RunScriptPanel::python_setting_changed()
-{
- const bool on = Mcp::python_scripts_allowed(*wxGetApp().app_config);
- send({{"command", "python"}, {"on", on}});
- if (!on)
- end_session();
-}
-
void RunScriptPanel::shortcuts_changed() { send({{"command", "shortcuts"}, {"toggle_key", toggle_key()}}); }
json RunScriptPanel::toggle_key() const
@@ -571,9 +558,6 @@ void RunScriptPanel::handle(const json& payload)
} else if (command == "pane_layout") {
wxGetApp().app_config->set("run_script", "split", json(payload.value("split", 0.6)).dump());
wxGetApp().app_config->set("run_script", "hidden_side", payload.value("hidden", ""));
- } else if (command == "turn_on_python") {
- // The setting's own window tells the panel about a change (python_setting_changed()).
- Mcp::show_python_scripts_dialog(wxGetApp().mainframe);
}
} catch (const std::exception& e) {
send({{"command", "error"}, {"message", e.what()}});
@@ -587,7 +571,6 @@ json RunScriptPanel::state() const
script.erase("command");
return {{"command", "state"},
{"script", std::move(script)},
- {"python_on", Mcp::python_scripts_allowed(*wxGetApp().app_config)},
{"ready", s != nullptr && s->ready()},
{"recent", recent_message()["items"]},
{"session", session_state()},
@@ -852,10 +835,6 @@ void RunScriptPanel::run(const json& payload)
{
if (m_running || m_waiting)
return;
- if (!Mcp::python_scripts_allowed(*wxGetApp().app_config)) {
- refuse(_u8L("Python scripts are off. You can turn them on in Preferences > AI features > Python scripts."));
- return;
- }
Mcp::McpService* s = service();
if (s == nullptr || !s->ready()) {
refuse(_u8L("Scripts can't run while OrcaSlicer is starting or closing."));
diff --git a/src/slic3r/GUI/RunScriptPanel.hpp b/src/slic3r/GUI/RunScriptPanel.hpp
index 3619e083c8..a731c7aa88 100644
--- a/src/slic3r/GUI/RunScriptPanel.hpp
+++ b/src/slic3r/GUI/RunScriptPanel.hpp
@@ -64,8 +64,6 @@ public:
// The end of GUI_App::recreate_GUI(): the pane comes back, with an empty console, if it was wanted, once the old main
// window has been deleted.
void main_window_rebuilt();
- // The Python scripts setting changed: the page is told, and turning it off ends the session.
- void python_setting_changed();
// The toggle's key changed (MainFrame::update_shortcut_labels()).
void shortcuts_changed();
diff --git a/src/slic3r/plugin/PluginAuditManager.cpp b/src/slic3r/plugin/PluginAuditManager.cpp
index db855f7fc4..f5612b62c4 100644
--- a/src/slic3r/plugin/PluginAuditManager.cpp
+++ b/src/slic3r/plugin/PluginAuditManager.cpp
@@ -20,7 +20,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -852,8 +851,6 @@ AuditDecision PluginAuditManager::check_path_access(const boost::filesystem::pat
<< " plugin=" << plugin_key << " reason=denied path keyword";
return {false, "denied path keyword"};
}
- if (is_script_identity(plugin_key))
- return {true, ""};
namespace fs = boost::filesystem;
fs::path candidate = path;
@@ -1533,7 +1530,8 @@ int report_denied(PluginAuditManager& mgr,
violation.reason = decision.reason;
mgr.report_violation(violation);
- std::string message = "Plugin attempted audited operation \"" + event_name + "\" without permission";
+ std::string message = std::string(is_script_identity(violation.plugin_key) ? "Script" : "Plugin") +
+ " attempted audited operation \"" + event_name + "\" without permission";
if (!decision.reason.empty())
message += ": " + decision.reason;
if (!target.empty())
@@ -1865,19 +1863,10 @@ int audit_plugin_event(PluginAuditManager& mgr, const std::string& event_name, A
}
}
- // A person's or an agent's script is unrestricted: past the denied paths above, every audited access
- // is allowed, and logged under its identity.
- if (is_script_identity(mgr.current_plugin())) {
- std::string listed;
- for (const auto& target : targets)
- listed += (listed.empty() ? "" : ", ") + target;
- // Reads at debug: every import reads module files.
- if (event_type == AuditEventCategory::FsRead)
- BOOST_LOG_TRIVIAL(debug) << "[AUDIT] script=" << mgr.current_plugin() << " event=" << event_name << " targets=[" << listed << "]";
- else
- BOOST_LOG_TRIVIAL(info) << "[AUDIT] script=" << mgr.current_plugin() << " event=" << event_name << " targets=[" << listed << "]";
+ // While scripts run unrestricted, every access of a script past the denied paths above is allowed.
+ const bool script = is_script_identity(mgr.current_plugin());
+ if (script && mgr.scripts_unrestricted())
return 0;
- }
// A nested event of an operation already granted, e.g. socket.connect inside an approved
// urlopen(), is not asked again. urllib.Request is always judged on its own URL, so a
@@ -1900,6 +1889,13 @@ int audit_plugin_event(PluginAuditManager& mgr, const std::string& event_name, A
return 0;
}
+ // A script has no install state to hold a grant, so nothing is asked: the error says what lifts the restriction.
+ if (script)
+ return report_denied(mgr, event_name,
+ {false, "Python scripts are restricted; a person can lift that in Preferences > AI features > "
+ "Python scripts"},
+ targets.empty() ? std::string() : targets.front());
+
PluginInstallState state;
const bool have_install_state = PluginManager::instance().get_install_state(mgr.current_plugin(), state);
if (!have_install_state) {
@@ -2084,120 +2080,6 @@ bool PluginAuditManager::request_permissions(const std::string& plugin_key, cons
return persisted;
}
-bool PluginAuditManager::request_tools_permission(const std::string& plugin_key)
-{
- PluginDescriptor descriptor;
- if (plugin_key.empty() || !PluginManager::instance().try_get_plugin_descriptor(plugin_key, descriptor) ||
- descriptor.plugin_root.empty())
- return false;
- const boost::filesystem::path root(descriptor.plugin_root);
- PluginInstallState state;
- InstallStateReadStatus state_status;
- {
- std::lock_guard state_lock(install_state_mutex());
- state_status = read_install_state_status(root, state);
- }
- // Same sidecar rules as request_permissions: an unreadable sidecar is never replaced.
- if (state_status == InstallStateReadStatus::Unreadable)
- return false;
- if (state.permissions.tools)
- return true;
-
- const auto build_message = [](const std::string& plugin_name) {
- // TRN %1% is a plugin's name.
- return GUI::format_wxstr(_L("%1% asks to use OrcaSlicer's tools, as an AI agent can. With this permission it can change "
- "your project, presets and files, work in OrcaSlicer's window while you use it, and answer "
- "its dialogs, other plugins' permission requests included.\n\nAllow it?"),
- plugin_name);
- };
- bool granted = false;
- if (PluginAuditDetail::s_permission_message_prompt_for_testing) {
- granted = PluginAuditDetail::s_permission_message_prompt_for_testing(build_message(descriptor.name).utf8_string());
- } else if (wxTheApp == nullptr || GUI::wxGetApp().is_closing()) {
- return false;
- } else if (wxIsMainThread()) {
- granted = PluginAuditDetail::prompt_for_permission_message({build_message(descriptor.name), {}});
- } else {
- auto result = std::make_shared>();
- auto future = result->get_future();
- GUI::wxGetApp().CallAfter([result, plugin_name = descriptor.name, build_message]() {
- result->set_value(PluginAuditDetail::prompt_for_permission_message({build_message(plugin_name), {}}));
- });
- granted = future.get();
- }
- if (!granted)
- return false;
-
- // Re-read under the lock so the grant adds to whatever was saved while the dialog was open.
- std::lock_guard state_lock(install_state_mutex());
- PluginInstallState latest_state;
- const InstallStateReadStatus latest_status = read_install_state_status(root, latest_state);
- if (latest_status == InstallStateReadStatus::Unreadable ||
- (latest_status == InstallStateReadStatus::Absent && state_status == InstallStateReadStatus::Readable))
- return false;
- state = std::move(latest_state);
- PluginAuditDetail::seed_install_metadata(descriptor, state);
- state.permissions.tools = true;
- return write_install_state(root, state);
-}
-
-bool PluginAuditManager::request_operation_permission(const std::string& plugin_key, const std::string& name,
- const std::string& description)
-{
- PluginDescriptor descriptor;
- if (plugin_key.empty() || !PluginManager::instance().try_get_plugin_descriptor(plugin_key, descriptor) ||
- descriptor.plugin_root.empty())
- return false;
- const boost::filesystem::path root(descriptor.plugin_root);
- PluginInstallState state;
- InstallStateReadStatus state_status;
- {
- std::lock_guard state_lock(install_state_mutex());
- state_status = read_install_state_status(root, state);
- }
- if (state_status == InstallStateReadStatus::Unreadable)
- return false;
- const auto& granted_ops = state.permissions.operations;
- if (std::find(granted_ops.begin(), granted_ops.end(), name) != granted_ops.end())
- return true;
-
- const auto build_message = [name, description](const std::string& plugin_name) {
- // TRN %1% is a plugin's name, %2% the name of an operation it offers, %3% the plugin's description of it.
- return GUI::format_wxstr(_L("%1% offers the operation \"%2%\" to AI agents and scripts:\n\n%3%\n\nLet them call it? "
- "It runs the plugin's code with the plugin's permissions."),
- plugin_name, name, description);
- };
- bool granted = false;
- if (PluginAuditDetail::s_permission_message_prompt_for_testing) {
- granted = PluginAuditDetail::s_permission_message_prompt_for_testing(build_message(descriptor.name).utf8_string());
- } else if (wxTheApp == nullptr || GUI::wxGetApp().is_closing()) {
- return false;
- } else if (wxIsMainThread()) {
- granted = PluginAuditDetail::prompt_for_permission_message({build_message(descriptor.name), {}});
- } else {
- auto result = std::make_shared>();
- auto future = result->get_future();
- GUI::wxGetApp().CallAfter([result, plugin_name = descriptor.name, build_message]() {
- result->set_value(PluginAuditDetail::prompt_for_permission_message({build_message(plugin_name), {}}));
- });
- granted = future.get();
- }
- if (!granted)
- return false;
-
- std::lock_guard state_lock(install_state_mutex());
- PluginInstallState latest_state;
- const InstallStateReadStatus latest_status = read_install_state_status(root, latest_state);
- if (latest_status == InstallStateReadStatus::Unreadable ||
- (latest_status == InstallStateReadStatus::Absent && state_status == InstallStateReadStatus::Readable))
- return false;
- state = std::move(latest_state);
- PluginAuditDetail::seed_install_metadata(descriptor, state);
- if (std::find(state.permissions.operations.begin(), state.permissions.operations.end(), name) == state.permissions.operations.end())
- state.permissions.operations.push_back(name);
- return write_install_state(root, state);
-}
-
void PluginAuditManager::record_root_frame()
{
PyObject* frame = reinterpret_cast(PyEval_GetFrame()); // borrowed reference
diff --git a/src/slic3r/plugin/PluginAuditManager.hpp b/src/slic3r/plugin/PluginAuditManager.hpp
index f6b50c2dec..be0570a489 100644
--- a/src/slic3r/plugin/PluginAuditManager.hpp
+++ b/src/slic3r/plugin/PluginAuditManager.hpp
@@ -4,6 +4,7 @@
// Via pybind11 so this file requests the same python3xx.lib as everything else.
#include
#include
+#include
#include
#include
#include
@@ -20,10 +21,11 @@ struct PluginPermissions;
// reader maps that form onto the boolean permission.
inline constexpr const char* kThreadPermissionTarget = "thread";
-// The audit identities of a Python script a person (the Run Script dialog, --mcp-run) or an agent
-// (run_script) starts. Every audited access is allowed to them and logged under them, apart from the
-// categorical denies (is_denied_path). They are reserved: no plugin key may equal them, so code running
-// under one is never taken for a plugin, and the orca.host functions only plugins may call refuse them.
+// The audit identities of a Python script a person (the Run Script panel, --mcp-run) or an agent
+// (run_script) starts. A script is judged as a plugin is, but has no install state to hold a grant: what
+// the implicit rules don't allow is denied without a prompt, unless scripts run unrestricted
+// (set_scripts_unrestricted). The identities are reserved: no plugin key may equal them, so a plugin is
+// never taken for a script.
inline constexpr char kScriptIdentityPerson[] = "script";
inline constexpr char kScriptIdentityAgent[] = "mcp";
inline bool is_script_identity(const std::string& key) { return key == kScriptIdentityPerson || key == kScriptIdentityAgent; }
@@ -151,6 +153,12 @@ public:
AuditDecision check_path_access(const boost::filesystem::path& candidate, bool is_write);
AuditDecision check_open(const std::string& path, const std::string& mode);
+ // Whether Python scripts (is_script_identity) run unrestricted: every audited access past the denied
+ // paths is allowed to them. It mirrors the person's setting, which the GUI passes on, since events are
+ // judged on any thread. Off until set.
+ void set_scripts_unrestricted(bool unrestricted) { m_scripts_unrestricted.store(unrestricted); }
+ bool scripts_unrestricted() const { return m_scripts_unrestricted.load(); }
+
// Ask the user to grant the requested permissions. The request may originate on a plugin
// load worker, so the implementation marshals the modal dialog to the wx main thread.
// Targets already persisted for the plugin are not shown or asked for again. Returns true
@@ -177,16 +185,6 @@ public:
// relative targets resolved against the working directory at the time of the check.
bool request_permissions(const std::string& plugin_key, const PluginPermissions& requested);
- // Asks the user, on its own, whether the plugin may call OrcaSlicer's tools (PluginPermissions::tools),
- // saying what that lets it do, and saves a Yes. True when it is granted, now or earlier. A plugin that
- // is refused still loads; its tool calls fail. Marshals to the UI thread like request_permissions.
- bool request_tools_permission(const std::string& plugin_key);
-
- // Asks the user whether the plugin may offer its operation `name` to agents and scripts, showing its
- // description, and saves a Yes in PluginPermissions::operations. True when it is granted, now or
- // earlier. A refused operation is not offered; the plugin still loads.
- bool request_operation_permission(const std::string& plugin_key, const std::string& name, const std::string& description);
-
// Ask the user to grant network access to the given http(s) URLs. Each URL is reduced to its
// scheme and host before prompting and persisting, so one approval covers every path, query
// and port on that host. The grant is recorded as an HTTP grant; network_permission_matches
@@ -276,6 +274,7 @@ private:
std::vector m_global_allowed_roots;
std::vector m_denied_filenames;
std::vector m_denied_path_keywords;
+ std::atomic m_scripts_unrestricted{false};
};
// RAII guard that sets the current plugin key and capability name, restoring the previous
diff --git a/src/slic3r/plugin/PluginFsUtils.cpp b/src/slic3r/plugin/PluginFsUtils.cpp
index 6f827023b3..36cb1e8eb8 100644
--- a/src/slic3r/plugin/PluginFsUtils.cpp
+++ b/src/slic3r/plugin/PluginFsUtils.cpp
@@ -869,7 +869,6 @@ InstallStateReadStatus read_install_state_status(const boost::filesystem::path&
read_string_list("network_socket", parsed.permissions.network_socket);
read_string_list("process", parsed.permissions.process);
read_string_list("events", parsed.permissions.events);
- read_string_list("operations", parsed.permissions.operations);
// Threading is a boolean grant. Newer sidecars store the boolean directly; the older
// array form stored an empty list when denied and a nonempty one when granted. By
@@ -890,8 +889,6 @@ InstallStateReadStatus read_install_state_status(const boost::filesystem::path&
// key, a "true" string, a number or any other type leaves it off.
if (permissions.contains("full_access") && permissions["full_access"].is_boolean())
parsed.permissions.full_access = permissions["full_access"].get();
- if (permissions.contains("tools") && permissions["tools"].is_boolean())
- parsed.permissions.tools = permissions["tools"].get();
}
if (state.contains("enabled") && state["enabled"].is_boolean())
@@ -1047,8 +1044,6 @@ bool write_install_state(const boost::filesystem::path& plugin_dir, const Plugin
{"threading", state.permissions.threading},
{"events", state.permissions.events},
{"full_access", state.permissions.full_access},
- {"tools", state.permissions.tools},
- {"operations", state.permissions.operations},
};
nlohmann::json capabilities = nlohmann::json::array();
diff --git a/src/slic3r/plugin/PluginFsUtils.hpp b/src/slic3r/plugin/PluginFsUtils.hpp
index 836fce0b89..bd35f823eb 100644
--- a/src/slic3r/plugin/PluginFsUtils.hpp
+++ b/src/slic3r/plugin/PluginFsUtils.hpp
@@ -38,11 +38,6 @@ struct PluginPermissions
// the cloud refresh token), which stay blocked. Stored as a JSON boolean; a missing or
// non-boolean value reads as false. This is a Python audit-hook policy, not an OS sandbox.
bool full_access = false;
- // The plugin may call OrcaSlicer's MCP tools through orca.host.tools, with the app's authority: what
- // an agent can do, GUI and dialogs included. Asked on its own at load (request_tools_permission).
- bool tools = false;
- // The operations (orca.register_operation names) the person let the plugin offer to agents and scripts.
- std::vector operations;
};
struct PluginInstallState {
diff --git a/src/slic3r/plugin/PluginOperations.hpp b/src/slic3r/plugin/PluginOperations.hpp
index 18240b7c51..20de4f943d 100644
--- a/src/slic3r/plugin/PluginOperations.hpp
+++ b/src/slic3r/plugin/PluginOperations.hpp
@@ -13,7 +13,7 @@ namespace pybind11 { class object; }
namespace Slic3r {
// An operation a plugin offers to agents and scripts (D4): declared with orca.register_operation() while
-// the plugin loads, offered only once the person has granted it, and gone when the plugin unloads. Agents
+// the plugin loads, offered once the plugin has loaded, and gone when the plugin unloads. Agents
// reach it through search_tools and call_tool, scripts through orca.host.tools.call, as
// "plugin.."; it is never in tools/list.
struct PluginOperation
@@ -36,8 +36,8 @@ class PluginOperations
public:
static PluginOperations& instance();
- // Keeps the operations a loading plugin declared and the person granted, replacing any it kept from
- // an earlier attempt; activate() offers them once the plugin has loaded.
+ // Keeps the operations a loading plugin declared, replacing any it kept from an earlier attempt;
+ // activate() offers them once the plugin has loaded.
void stage(const std::string& plugin_key, std::vector operations);
void activate(const std::string& plugin_key);
// Drops what a load that failed or was cancelled staged; operations already offered stay.
diff --git a/src/slic3r/plugin/PythonPluginBridge.cpp b/src/slic3r/plugin/PythonPluginBridge.cpp
index ea5e21775a..93bda77cdb 100644
--- a/src/slic3r/plugin/PythonPluginBridge.cpp
+++ b/src/slic3r/plugin/PythonPluginBridge.cpp
@@ -218,39 +218,18 @@ std::vector PythonPluginBridge::finalize_plugin_capture(cons
return {};
}
}
- // Calling tools is asked on its own, after the rest: a refusal leaves the plugin loading without it.
- if (requested_permissions.tools) {
- bool granted = false;
- {
- py::gil_scoped_release release;
- granted = PluginAuditManager::instance().request_tools_permission(plugin_key);
- }
- if (!granted)
- BOOST_LOG_TRIVIAL(info) << "Plugin " << plugin_key << " loads without the tools permission";
- }
- std::vector declared;
+ std::vector operations;
{
std::lock_guard lock(g_registry_mutex);
auto it = g_pending_operations.find(capture_key);
if (it != g_pending_operations.end()) {
- declared = std::move(it->second);
+ operations = std::move(it->second);
g_pending_operations.erase(it);
}
}
- std::vector granted_operations;
- for (PluginOperation& op : declared) {
- bool granted = false;
- {
- py::gil_scoped_release release;
- granted = PluginAuditManager::instance().request_operation_permission(plugin_key, op.name, op.description);
- }
- if (granted) {
- op.plugin_key = plugin_key;
- granted_operations.push_back(std::move(op));
- } else
- BOOST_LOG_TRIVIAL(info) << "Plugin " << plugin_key << " does not offer its operation " << op.name;
- }
- PluginOperations::instance().stage(plugin_key, std::move(granted_operations));
+ for (PluginOperation& op : operations)
+ op.plugin_key = plugin_key;
+ PluginOperations::instance().stage(plugin_key, std::move(operations));
} catch (py::error_already_set& err) {
log_python_exception_keep(err);
error = err.what();
@@ -761,12 +740,11 @@ not a capability.)pbdoc");
py::arg("changes") = true,
R"pbdoc(Offer an operation to AI agents and scripts while OrcaSlicer loads your module.
-The person is asked whether to allow each operation; an allowed one is reached as
-"plugin.." through call_tool and orca.host.tools.call. handler, which is required, is
-called as handler(args) with the arguments as a dict, validated against schema (a JSON Schema object,
-or None for an operation that takes no arguments); it runs under the plugin's identity and permissions
-and returns a JSON value. Pass handler by position after schema, or as handler= on its own.
-changes=False marks an operation that only reads.)pbdoc");
+It is reached as "plugin.." through call_tool and orca.host.tools.call once the plugin
+has loaded. handler, which is required, is called as handler(args) with the arguments as a dict,
+validated against schema (a JSON Schema object, or None for an operation that takes no arguments); it
+runs under the plugin's identity and permissions and returns a JSON value. Pass handler by position
+after schema, or as handler= on its own. changes=False marks an operation that only reads.)pbdoc");
m.def(
"request_permissions",
@@ -776,8 +754,7 @@ changes=False marks an operation that only reads.)pbdoc");
const std::vector& network_socket,
const std::vector& process,
bool threading,
- const std::vector& network,
- bool tools) {
+ const std::vector& network) {
if (g_active_plugin_key.empty())
throw py::value_error("request_permissions() called outside plugin discovery context");
@@ -828,7 +805,6 @@ changes=False marks an operation that only reads.)pbdoc");
if (threading && !requested.threading)
requested.threading = true;
- requested.tools = requested.tools || tools;
},
py::arg("fs_read") = std::vector{},
py::arg("fs_readwrite") = std::vector{},
@@ -837,7 +813,6 @@ changes=False marks an operation that only reads.)pbdoc");
py::arg("process") = std::vector{},
py::arg("threading") = false,
py::arg("network") = std::vector{},
- py::arg("tools") = false,
R"pbdoc(Request permissions while OrcaSlicer loads your module.
Each bucket takes the target strings the plugin expects the corresponding audit event to
@@ -845,9 +820,6 @@ report: filesystem paths for fs_read and fs_readwrite, URLs for network_http, so
for network_socket, and commands for process. threading=True requests permission to start
threads. Targets already granted to the plugin are not asked for again.
-tools=True asks, on its own, for permission to call OrcaSlicer's tools through orca.host.tools,
-with what an AI agent can do; when it is refused the plugin still loads and its tool calls fail.
-
A filesystem target may end in "/*" to grant a whole directory tree, for example
"/path/to/folder/*". That covers the folder itself and every path beneath it, at any depth.
"*" is the only wildcard and is recognized only as the final path component; a "*" anywhere
@@ -975,6 +947,7 @@ void install_python_thread_audit_shim()
} ended{nullptr, PyThread_get_thread_ident()};
if (run) {
bound.emplace(run, PythonRunThread::Started);
+ run->allow_folder_reads();
run->thread_started(ended.ident, waited);
ended.scope = run.get();
}
diff --git a/src/slic3r/plugin/PythonRunScope.cpp b/src/slic3r/plugin/PythonRunScope.cpp
index 08b23c833c..1738a307a5 100644
--- a/src/slic3r/plugin/PythonRunScope.cpp
+++ b/src/slic3r/plugin/PythonRunScope.cpp
@@ -27,6 +27,12 @@ bool PythonRunScope::owns_ui() const { return is_script_identity(m_identity); }
std::string PythonRunScope::ui_owner() const { return owns_ui() ? "script/" + std::to_string(m_id) : m_identity; }
+void PythonRunScope::allow_folder_reads() const
+{
+ if (is_script_identity(m_identity) && !m_file.empty())
+ PluginAuditManager::instance().add_scoped_allowed_root(m_file.parent_path(), /*allow_write=*/false);
+}
+
nlohmann::json PythonRunScope::call_tool(const std::string& tool, const nlohmann::json& args)
{
ToolBridge* bridge = nullptr;
diff --git a/src/slic3r/plugin/PythonRunScope.hpp b/src/slic3r/plugin/PythonRunScope.hpp
index 26df03e32b..9d21a36009 100644
--- a/src/slic3r/plugin/PythonRunScope.hpp
+++ b/src/slic3r/plugin/PythonRunScope.hpp
@@ -45,6 +45,9 @@ public:
// a plugin's run_script leaves them to the plugin, which closes them when it unloads.
bool owns_ui() const;
std::string ui_owner() const;
+ // Lets the calling thread's audit scope read the folder of a script's file, which its imports come from, as a
+ // plugin reads its own folder. Called inside the run's audit scope on each thread that works for it.
+ void allow_folder_reads() const;
// orca.host.tools from any thread of the run, called without the GIL. Throws std::runtime_error once the run
// has ended; a bridge's ToolCallError passes through.
diff --git a/src/slic3r/plugin/PythonScriptRunner.cpp b/src/slic3r/plugin/PythonScriptRunner.cpp
index 056f2b7449..46eb252c56 100644
--- a/src/slic3r/plugin/PythonScriptRunner.cpp
+++ b/src/slic3r/plugin/PythonScriptRunner.cpp
@@ -739,6 +739,7 @@ py::object run_work_item(const py::object& original, const py::handle& interrupt
{
ScopedPythonRun bound(run, PythonRunThread::Started);
ScopedPluginAuditContext audit(run->identity());
+ run->allow_folder_reads();
const unsigned long ident = PyThread_get_thread_ident();
run->task_running(ident);
try {
@@ -1319,6 +1320,7 @@ void host_python_session(const PythonSessionRequest& request, PythonSession& ses
Watcher::Reason reason = Watcher::Reason::None;
{
ScopedPluginAuditContext audit(request.identity);
+ scope->allow_folder_reads();
Watcher watcher(Watcher::Config{request.cancelled, request.budget, request.stop_calls, request.stop_closes_ui}, session, ident,
interrupt.ptr(), scope);
py::dict ns;
@@ -1792,6 +1794,7 @@ PoolInitializerBinding python_run_bind_pool_initializer(const py::handle& functi
worker_args[2] = py::cpp_function([initializer, run](const py::args& call_args) -> py::object {
ScopedPythonRun bound(run, PythonRunThread::Started);
ScopedPluginAuditContext audit(run->identity());
+ run->allow_folder_reads();
struct Target
{
PythonRunScope& run;
diff --git a/src/slic3r/plugin/host/PluginHostTools.cpp b/src/slic3r/plugin/host/PluginHostTools.cpp
index d6685bc9a6..b53ac486ce 100644
--- a/src/slic3r/plugin/host/PluginHostTools.cpp
+++ b/src/slic3r/plugin/host/PluginHostTools.cpp
@@ -128,8 +128,8 @@ void register_tools(py::module_& host)
"reply budget returns {status: \"running\" | \"blocked_by_dialog\", job}, as it does for an agent; follow it "
"with call(\"wait\", {\"for\": \"job\", \"job\": ...}). An error result raises ToolError, whose details "
"hold the result's data. A person's or an agent's script calls tools from its own code and from the threads and "
- "pool tasks it starts, while its run lasts, but not from its window callbacks; a plugin needs the tools "
- "permission and calls from a Script worker, never the UI thread.");
+ "pool tasks it starts, while its run lasts, but not from its window callbacks; a plugin calls from a "
+ "Script worker, never the UI thread.");
tools.def(
"run_replay",
[tools](const py::object& replay, const py::object& vars) mutable {
diff --git a/src/slic3r/plugin/host/PluginHostTools.hpp b/src/slic3r/plugin/host/PluginHostTools.hpp
index c0f81d36a5..5bec86a9c9 100644
--- a/src/slic3r/plugin/host/PluginHostTools.hpp
+++ b/src/slic3r/plugin/host/PluginHostTools.hpp
@@ -61,7 +61,7 @@ private:
// Calls a tool for the plugin `plugin_key`, as orca.host.tools does from a plugin's code: returns the
// result's data or a job envelope, throws ToolCallError for an error result and std::runtime_error when
-// the plugin may not call tools. Called without the GIL.
+// the call can't be run. Called without the GIL.
using PluginToolCaller = std::function;
// Set once the GUI can run tool calls; until then a plugin's calls fail.
void set_plugin_tool_caller(PluginToolCaller caller);
diff --git a/tests/slic3rutils/test_mcp_config.cpp b/tests/slic3rutils/test_mcp_config.cpp
index bccace2f22..3f1fe023f1 100644
--- a/tests/slic3rutils/test_mcp_config.cpp
+++ b/tests/slic3rutils/test_mcp_config.cpp
@@ -722,14 +722,14 @@ TEST_CASE("the preferences scope reads the keys it is given, as stored, and list
CHECK_THROWS_AS(preferences_settings(config, json{{"keys", {"region"}}, {"compare", ":saved"}}), ToolFailure);
}
-TEST_CASE("the Python scripts setting is off unless a person turned it on", "[Mcp]")
+TEST_CASE("Python scripts run restricted unless a person let them run unrestricted", "[Mcp]")
{
AppConfig config;
- CHECK_FALSE(python_scripts_allowed(config));
- config.set_bool(kPythonScriptsKey, true);
- CHECK(python_scripts_allowed(config));
- config.set_bool(kPythonScriptsKey, false);
- CHECK_FALSE(python_scripts_allowed(config));
+ CHECK_FALSE(python_scripts_unrestricted(config));
+ config.set_bool(kPythonUnrestrictedKey, true);
+ CHECK(python_scripts_unrestricted(config));
+ config.set_bool(kPythonUnrestrictedKey, false);
+ CHECK_FALSE(python_scripts_unrestricted(config));
}
namespace {
diff --git a/tests/slic3rutils/test_plugin_audit.cpp b/tests/slic3rutils/test_plugin_audit.cpp
index d227cf4d5c..6ff135ecd5 100644
--- a/tests/slic3rutils/test_plugin_audit.cpp
+++ b/tests/slic3rutils/test_plugin_audit.cpp
@@ -2471,57 +2471,6 @@ with open(os.path.join(DENIED_DIR, "token.txt"), "w") as f:
CHECK(violation.reason == "denied path");
}
-TEST_CASE("The tools permission is saved in the install state and read back", "[audit]")
-{
- ScopedTemporaryDir dir("orca-plugin-tools-permission");
- PluginInstallState state;
- state.installed_from = "local";
- state.installed_version = "1.0";
- state.plugin_name = "ToolsPlugin";
- state.permissions.tools = true;
- REQUIRE(write_install_state(dir.path(), state));
-
- PluginInstallState read;
- REQUIRE(read_install_state(dir.path(), read));
- CHECK(read.permissions.tools);
-
- state.permissions.tools = false;
- REQUIRE(write_install_state(dir.path(), state));
- REQUIRE(read_install_state(dir.path(), read));
- CHECK_FALSE(read.permissions.tools);
-}
-
-TEST_CASE("The tools permission is asked on its own, saved when granted, and not asked again", "[audit][Python]")
-{
- AuditHarness harness;
- if (!harness.initialized)
- SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
- harness.add_plugin(PLUGIN);
- std::vector messages;
- bool answer = false;
- PluginAuditManager::set_permission_message_prompt_for_testing([&](const std::string& message) {
- messages.push_back(message);
- return answer;
- });
-
- CHECK_FALSE(PluginAuditManager::instance().request_tools_permission(PLUGIN));
- REQUIRE(messages.size() == 1);
- CHECK_THAT(messages[0], Catch::Matchers::ContainsSubstring("tools"));
- PluginInstallState state;
- REQUIRE(PluginManager::instance().get_install_state(PLUGIN, state));
- CHECK_FALSE(state.permissions.tools);
-
- answer = true;
- CHECK(PluginAuditManager::instance().request_tools_permission(PLUGIN));
- REQUIRE(PluginManager::instance().get_install_state(PLUGIN, state));
- CHECK(state.permissions.tools);
-
- // Granted once, it is not asked again.
- CHECK(PluginAuditManager::instance().request_tools_permission(PLUGIN));
- CHECK(messages.size() == 2);
- PluginAuditManager::set_permission_message_prompt_for_testing(nullptr);
-}
-
TEST_CASE("A plugin named after a script identity is refused before any of its code runs", "[audit][Python]")
{
ScopedDataDir data{"plugin-reserved-key"};
@@ -2531,7 +2480,7 @@ TEST_CASE("A plugin named after a script identity is refused before any of its c
const fs::path marker = outside.path() / "ran.txt";
const fs::path root = data.plugins_dir() / "mcp";
fs::create_directories(root);
- // Run as "mcp", this write would be allowed: a marker means the plugin's code ran.
+ // The module writes a marker as it is imported: one means the plugin's code ran.
std::ofstream((root / "mcp.py").string(), std::ios::binary) << "open(r'" << marker.generic_string() << "', 'w').write('ran')\n";
PluginInstallState state;
state.installed_from = "local";
diff --git a/tests/slic3rutils/test_python_script_runner.cpp b/tests/slic3rutils/test_python_script_runner.cpp
index 691a908a39..2f611b5c79 100644
--- a/tests/slic3rutils/test_python_script_runner.cpp
+++ b/tests/slic3rutils/test_python_script_runner.cpp
@@ -50,16 +50,18 @@ namespace py = pybind11;
namespace {
-// The production interpreter, as the app brings it up, with a data folder of its own. No permission
-// prompt may show: one would mean the identity was judged as a plugin's.
+// The production interpreter, as the app brings it up, with a data folder of its own. Scripts run
+// unrestricted unless the test says otherwise: what the runner's tests do (threads, pools, files anywhere)
+// needs it. No permission prompt may show for a script either way: nothing is ever asked for one.
struct RunnerHarness
{
ScopedDataDir data{"python-script-runner"};
bool initialized = PluginManager::instance().initialize();
std::vector prompts;
- RunnerHarness()
+ explicit RunnerHarness(bool unrestricted = true)
{
+ PluginAuditManager::instance().set_scripts_unrestricted(unrestricted);
PluginAuditManager::set_permission_prompt_for_testing([this](const std::string& event, const std::vector&) {
prompts.push_back(event);
return false;
@@ -68,6 +70,7 @@ struct RunnerHarness
~RunnerHarness()
{
PluginAuditManager::set_permission_prompt_for_testing(nullptr);
+ PluginAuditManager::instance().set_scripts_unrestricted(false);
PluginManager::instance().shutdown();
}
};
@@ -648,7 +651,7 @@ TEST_CASE("a script that never returns is cancelled, or stopped at its budget",
CHECK(run("result = 5").result == 5);
}
-TEST_CASE("an agent's script may touch any file but the categorically denied ones, without prompts", "[PythonScript][Python]")
+TEST_CASE("an unrestricted script may touch any file but the categorically denied ones, without prompts", "[PythonScript][Python]")
{
RunnerHarness harness;
if (!harness.initialized)
@@ -670,6 +673,58 @@ TEST_CASE("an agent's script may touch any file but the categorically denied one
CHECK(PluginAuditManager::instance().current_plugin().empty());
}
+TEST_CASE("a restricted script is denied what a plugin would be asked for, without prompts", "[PythonScript][Python]")
+{
+ RunnerHarness harness(/*unrestricted=*/false);
+ if (!harness.initialized)
+ SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
+
+ ScopedTemporaryDir outside("orca-python-script-restricted");
+ const std::string file = (outside.path() / "note.txt").generic_string();
+ const PythonRunOutcome refused = run("open(args['file'], 'w')", json{{"file", file}});
+ CHECK(refused.status == "raised");
+ CHECK_THAT(refused.message, ContainsSubstring("PermissionError"));
+ // The error says where the restriction is lifted.
+ CHECK_THAT(refused.message, ContainsSubstring("Preferences"));
+ CHECK_FALSE(boost::filesystem::exists(file));
+
+ const PythonRunOutcome thread = run("import threading\nthreading.Thread(target=print).start()");
+ CHECK(thread.status == "raised");
+ CHECK_THAT(thread.message, ContainsSubstring("PermissionError"));
+
+ // OrcaSlicer's own data folder is open to it, as it is to a plugin. install_hook() granted the folder of the
+ // test that first started Python, so this test's folder is granted here.
+ PluginAuditManager::instance().add_global_allowed_root(harness.data.dir);
+ const std::string inside = (harness.data.dir / "note.txt").generic_string();
+ const PythonRunOutcome wrote = run("open(args['file'], 'w').write('x')\nresult = open(args['file']).read()", json{{"file", inside}});
+ CHECK(wrote.status == "finished");
+ CHECK(wrote.result == "x");
+
+ CHECK(harness.prompts.empty());
+}
+
+TEST_CASE("a restricted script's file run reads its own folder and writes nothing there", "[PythonScript][Python]")
+{
+ RunnerHarness harness(/*unrestricted=*/false);
+ if (!harness.initialized)
+ SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error());
+
+ MacroDir macros;
+ macros.write("helper.py", "VALUE = 7\n");
+ const std::string reads = "import helper\nresult = [helper.VALUE, 'helper' in open(__file__).read()]\n";
+ const PythonRunOutcome read = run_file(macros.write("reads.py", reads), reads);
+ CHECK(read.status == "finished");
+ CHECK(read.result == json::array({7, true}));
+
+ const std::string writes = "import os\nopen(os.path.join(os.path.dirname(__file__), 'out.txt'), 'w')\n";
+ const PythonRunOutcome refused = run_file(macros.write("writes.py", writes), writes);
+ CHECK(refused.status == "raised");
+ CHECK_THAT(refused.message, ContainsSubstring("PermissionError"));
+ CHECK_FALSE(boost::filesystem::exists(macros.dir / "out.txt"));
+
+ CHECK(harness.prompts.empty());
+}
+
namespace {
// Answers tool calls as the MCP core would for a run: get_app_state and run_replay succeed, anything else is
diff --git a/tools/mcp/README.md b/tools/mcp/README.md
index 81586b20ab..61a52b7e02 100644
--- a/tools/mcp/README.md
+++ b/tools/mcp/README.md
@@ -7,7 +7,7 @@ Python. It uses only the standard library. `docs/HLSD/mcp-server.md` covers the
| Command | What it does |
|---|---|
-| `launch [--headless [kwin\|mutter] \| --xvfb] [--cad] [--python-scripts] [--printer "@"] [--vendor V] [--filament F] [--datadir DIR] [--port N] [--bin PATH] [--print-config] [-- app args]` | Start OrcaSlicer with `--mcp`, wait until it is ready, print the session |
+| `launch [--headless [kwin\|mutter] \| --xvfb] [--cad] [--unrestricted-scripts] [--printer "@"] [--vendor V] [--filament F] [--datadir DIR] [--port N] [--bin PATH] [--print-config] [-- app args]` | Start OrcaSlicer with `--mcp`, wait until it is ready, print the session |
| `call TOOL [''] [--wait]` | Call a tool and print its JSON result; `--wait` follows a returned job to its result |
| `tools` | List the tools, with the first line of each description |
| `widgets ['']` | Print the `list_widgets` tree |
@@ -20,8 +20,8 @@ an `OrcaSlicer.conf` that has a finished setup wizard and one printer and filame
Carbon 0.4 by default), with update checks and daily tips turned off. `--cad` turns the Design
(CAD) tab on, which `call_cad_tool` needs: it sets `enable_cad_feature` in a fresh datadir's
`OrcaSlicer.conf`, and in a reused one too, since the app creates the Design tab only at startup, when that setting is on.
-`--python-scripts` allows Python scripts (`run_script`) the same way, by setting `mcp_python_scripts`,
-since no tool can turn them on. The token comes from
+`--unrestricted-scripts` lets Python scripts (`run_script`) run unrestricted the same way, by setting
+`mcp_python_unrestricted`, since no tool can turn that on. The token comes from
`ORCA_MCP_TOKEN` or is generated, and it reaches the app through the environment, not the command
line. On Linux, `launch` also sets `SSL_CERT_FILE`, so a fresh datadir doesn't prompt for a CA
bundle. On Windows, it gives the instance its own WebView2 profile in the datadir, apart from the one
@@ -132,25 +132,24 @@ screenshots in the output directory. `tests/replay_basic.json` is the smallest s
change a setting, slice and capture.
`test_plugin_tools.py` checks a plugin's calls into the tools in the running app: it side-loads
-`tests/plugins/mcp_tools_fixture` into a fresh data folder and launches three times: over MCP without the
-plugin's tools permission (its calls are refused; its operation is still reached through `search_tools`
-and `call_tool`, and stays out of `tools/list`); over MCP with it granted (calls from its Script worker and a
-thread it starts reach the tools, an auto-answer rule it sets is the plugin's, `export_replay` is refused,
-nothing it calls is journaled, a script is refused its progress dialog handle's methods,
-`tests/plugins/mcp_tools_broken`, whose load fails, offers none of its granted operations, and unticking the
+`tests/plugins/mcp_tools_fixture` into a fresh data folder and launches twice: over MCP (its operation is
+reached through `search_tools` and `call_tool`, and stays out of `tools/list`, calls from its Script worker
+and a thread it starts reach the tools, an auto-answer rule it sets is the plugin's, `export_replay` is
+refused, nothing it calls is journaled, a script that finds its progress dialog handle can use it,
+`tests/plugins/mcp_tools_broken`, whose load fails, offers none of its operations, and unticking the
plugin in the Plugins dialog withdraws its operation and ends its rule); and without MCP,
-where a `--mcp-run` runs the plugin's script and its rule is still the plugin's. Run it as `python tools/mcp/test_plugin_tools.py`. The permission's own
-prompt opens while the app starts, before MCP can answer it, so the first launch sets
-`ORCA_MCP_TOOLS_FIXTURE_ASK=0` and the plugin doesn't ask; the prompt is covered by the unit tests. The
+where a `--mcp-run` runs the plugin's script and its rule is still the plugin's. Run it as
+`python tools/mcp/test_plugin_tools.py`. The
Run Script panel's `.py` files are not driven from here: the panel is hidden from automation and opens its
files through a file picker, so how it reads and saves them is covered by the unit tests of
`decode_python_source()` and `encode_python_source()`.
A `.py` file given to `--mcp-run` runs as a Python script (`run_script`) instead, exiting 0 when it
-finishes and 1 when it raises, is cancelled or runs out of time; its traceback goes to the log. Python
-scripts run only once the setting allows them: set `"mcp_python_scripts": "true"` in the `app` section
-of the datadir's `OrcaSlicer.conf` before the launch, as `orca_mcp.py launch --python-scripts` does, since
-no tool can turn it on.
+finishes and 1 when it raises, is cancelled or runs out of time; its traceback goes to the log. A
+script's own file access is held to OrcaSlicer's folders, and it starts no programs or threads and reaches
+no network, until the setting lets scripts run unrestricted: set `"mcp_python_unrestricted": "true"` in the
+`app` section of the datadir's `OrcaSlicer.conf` before the launch, as
+`orca_mcp.py launch --unrestricted-scripts` does, since no tool can turn it on.
A `.py` file runs as Python runs it (`python file.py`), with the whole plugin API: `__name__` is
`"__main__"`, `__file__` and `sys.argv` name it, the modules beside it import (afresh each run, so an edit
@@ -422,7 +421,7 @@ that a window screenshot is the size the reply gives and skips positions, which
nor takes. On X11 it reads the X server's stacking order through libX11 to check that the main window,
restored and raised while Preferences is open, stays under it.
-`test_action_replay_hidden.py`, on an instance launched with `--python-scripts`, opens Action Replay
+`test_action_replay_hidden.py` opens Action Replay
and checks that the GUI tools don't see it: `list_widgets` lists no window for it, `run_javascript`
without a target behaves as before it opened, and a key sent without a target never reaches it. It
then shows the Run Script panel on
diff --git a/tools/mcp/orca_mcp.py b/tools/mcp/orca_mcp.py
index 09ff7e1bf0..27a21c8dc8 100755
--- a/tools/mcp/orca_mcp.py
+++ b/tools/mcp/orca_mcp.py
@@ -10,7 +10,7 @@ Standard library only. Two halves:
tools/mcp/orca_mcp.py launch --headless # fresh datadir on a private headless desktop (Linux), wait until ready
tools/mcp/orca_mcp.py launch --xvfb # on a private Xvfb display, for a Linux machine without a desktop
tools/mcp/orca_mcp.py launch --cad # with the Design (CAD) tab on, for the CAD tools (list_cad_tools, call_cad_tool)
- tools/mcp/orca_mcp.py launch --python-scripts # with Python scripts allowed, for run_script
+ tools/mcp/orca_mcp.py launch --unrestricted-scripts # with Python scripts (run_script) unrestricted
tools/mcp/orca_mcp.py call get_app_state
tools/mcp/orca_mcp.py call open_files '{"paths": ["/abs/model.stl"]}'
tools/mcp/orca_mcp.py screenshot /tmp/shot.png --target canvas
@@ -254,18 +254,18 @@ def write_conf(conf, data):
f.write("\n")
-def seed_datadir(datadir, printer, cad=False, python_scripts=False):
+def seed_datadir(datadir, printer, cad=False, unrestricted_scripts=False):
"""Seed a fresh datadir's OrcaSlicer.conf. A datadir that has one keeps it, except for the settings
- cad and python_scripts turn on, which only the file can: the app creates the Design tab only at
- startup, when its setting is on, and no tool allows Python scripts."""
+ cad and unrestricted_scripts turn on, which only the file can: the app creates the Design tab only at
+ startup, when its setting is on, and no tool lets Python scripts run unrestricted."""
vendor, model, nozzle, filament = printer
os.makedirs(datadir, exist_ok=True)
conf = os.path.join(datadir, "OrcaSlicer.conf")
switches = {}
if cad:
switches["enable_cad_feature"] = True
- if python_scripts:
- switches["mcp_python_scripts"] = "true"
+ if unrestricted_scripts:
+ switches["mcp_python_unrestricted"] = "true"
if os.path.exists(conf):
if switches:
with open(conf, encoding="utf-8") as f:
@@ -463,7 +463,7 @@ def launch(args):
if args.printer:
model, _, nozzle = args.printer.partition("@")
printer = (args.vendor, model, nozzle or "0.4", args.filament or DEFAULT_PRINTER[3])
- seed_datadir(datadir, printer, args.cad, args.python_scripts)
+ seed_datadir(datadir, printer, args.cad, args.unrestricted_scripts)
env = dict(os.environ, ORCA_MCP_TOKEN=token)
binary = find_binary(args.bin)
@@ -535,7 +535,8 @@ def main():
p.add_argument("--vendor", default="BBL")
p.add_argument("--filament")
p.add_argument("--cad", action="store_true", help="turn the Design (CAD) tab on, for the CAD tools (list_cad_tools, call_cad_tool)")
- p.add_argument("--python-scripts", action="store_true", help="allow Python scripts (run_script), which no tool can turn on")
+ p.add_argument("--unrestricted-scripts", action="store_true",
+ help="let Python scripts (run_script) run unrestricted, which no tool can turn on")
p.add_argument("--timeout", type=int, default=120)
p.add_argument("--print-config", action="store_true", help="print client setup commands")
p.add_argument("extra", nargs="*", help="extra orca-slicer arguments after --")
diff --git a/tools/mcp/test_action_replay_hidden.py b/tools/mcp/test_action_replay_hidden.py
index 9a5ae1f651..b323f4e2c1 100755
--- a/tools/mcp/test_action_replay_hidden.py
+++ b/tools/mcp/test_action_replay_hidden.py
@@ -2,7 +2,7 @@
"""Checks that the Action Replay window and the Run Script panel stay out of reach of the GUI tools, so a
replay or a script can't act on them.
- tools/mcp/orca_mcp.py launch --python-scripts
+ tools/mcp/orca_mcp.py launch
tools/mcp/test_action_replay_hidden.py
With Action Replay open: list_widgets lists no window for it, a window screenshot still works,
diff --git a/tools/mcp/test_plugin_tools.py b/tools/mcp/test_plugin_tools.py
index 11c50bc97c..c206814e96 100644
--- a/tools/mcp/test_plugin_tools.py
+++ b/tools/mcp/test_plugin_tools.py
@@ -1,13 +1,10 @@
"""Checks a plugin's calls into the MCP tools and the operations it offers, in the running app.
-Launches OrcaSlicer on a fresh data folder with tests/plugins/mcp_tools_fixture side-loaded: over MCP
-without the plugin's tools permission, then with it granted (and tests/plugins/mcp_tools_broken, whose load
-fails after declaring an operation), then once without MCP, running a replay with --mcp-run, so the
-plugin's calls go to the catalog-only service. The second launch ends by unticking the fixture in the Plugins
-dialog, as a person unloads it. Run it as python tools/mcp/test_plugin_tools.py [--bin PATH].
-The permission's own prompt opens while the app starts, before MCP can answer it, so the first launch has
-the plugin not ask (ORCA_MCP_TOOLS_FIXTURE_ASK=0) and the second grants it in the plugin's saved state; the
-prompt itself is covered by the unit tests.
+Launches OrcaSlicer on a fresh data folder with tests/plugins/mcp_tools_fixture side-loaded, and
+tests/plugins/mcp_tools_broken, whose load fails after declaring an operation: over MCP, then once without
+MCP, running a replay with --mcp-run, so the plugin's calls go to the catalog-only service. The first launch
+ends by unticking the fixture in the Plugins dialog, as a person unloads it. Run it as
+python tools/mcp/test_plugin_tools.py [--bin PATH].
"""
import json
import os
@@ -43,27 +40,27 @@ def check(name, ok, detail=""):
print(("PASS " if ok else "FAIL ") + name + ("" if ok else " " + str(detail)[:400]), flush=True)
-def install(datadir, tools):
- """Side-loads the fixture enabled, with its operation and threads granted and the tools permission as given."""
+def install(datadir):
+ """Side-loads the fixture enabled, with its threads granted."""
dest = os.path.join(datadir, "orca_plugins", PLUGIN)
os.makedirs(dest, exist_ok=True)
shutil.copy(os.path.join(FIXTURE, PLUGIN + ".py"), dest)
with open(os.path.join(dest, ".install_state.json"), "w", encoding="utf-8") as f:
json.dump({"installed_from": "local", "installed_version": "1.0.0", "plugin_name": "MCP Tools Fixture", "enabled": True,
"capabilities": [{name: True} for name in CAPABILITIES],
- "permissions": {"threading": ["thread"], "tools": tools, "operations": ["measure"]}}, f, indent=2)
+ "permissions": {"threading": ["thread"]}}, f, indent=2)
# Where orca.host.plugin.storage() puts the plugin's files, and the scripts their outcomes.
return os.path.join(datadir, "orca_plugins", "plugin_data", PLUGIN)
def install_broken(datadir):
- """Side-loads the plugin whose load fails, with its operation granted."""
+ """Side-loads the plugin whose load fails."""
dest = os.path.join(datadir, "orca_plugins", BROKEN)
os.makedirs(dest, exist_ok=True)
shutil.copy(os.path.join(HERE, "tests", "plugins", BROKEN, BROKEN + ".py"), dest)
with open(os.path.join(dest, ".install_state.json"), "w", encoding="utf-8") as f:
json.dump({"installed_from": "local", "installed_version": "1.0.0", "plugin_name": "MCP Tools Broken Fixture", "enabled": True,
- "capabilities": [{"MCP tools broken fixture": True}], "permissions": {"operations": ["measure"]}}, f, indent=2)
+ "capabilities": [{"MCP tools broken fixture": True}]}, f, indent=2)
def wait_for(predicate, timeout):
@@ -112,29 +109,20 @@ def main():
datadir = tempfile.mkdtemp(prefix="orca-plugin-tools-")
env = dict(os.environ, ORCA_MCP_SESSION=os.path.join(datadir, "session.json"), ORCA_MCP_TOKEN=TOKEN)
try:
- # --- Without the tools permission: the plugin loads, its calls are refused, its operation is offered. ---
- plugin_dir = install(datadir, tools=False)
- orca = launch(dict(env, ORCA_MCP_TOOLS_FIXTURE_ASK="0"), datadir, extra)
- refused = run_plugin_script(orca, plugin_dir, "call", CAPABILITIES[0])
- check("a plugin without the tools permission is refused", refused.get("ok") is False and
- "tools permission" in refused.get("error", ""), refused)
+ # --- Over MCP: the plugin's operation and its tool calls, beside a plugin whose load fails. ---
+ plugin_dir = install(datadir)
+ install_broken(datadir)
+ orca = launch(env, datadir, extra)
described = orca.call_raw("search_tools", {"tool": f"plugin.{PLUGIN}.measure"})
- check("search_tools describes the plugin's granted operation", not described.get("isError") and
+ check("search_tools describes the plugin's operation", not described.get("isError") and
"\"a\"" in described["content"][0]["text"], described)
called = orca.call_raw("call_tool", {"tool": f"plugin.{PLUGIN}.measure", "args": {"a": 2}})
check("call_tool runs the plugin's operation", not called.get("isError") and
json.loads(called["content"][0]["text"]) == {"twice": 4}, called)
listed = [t["name"] for t in orca.request("tools/list")["tools"]]
check("the operation is not in tools/list", f"plugin.{PLUGIN}.measure" not in listed)
- harness(env, "stop")
- time.sleep(3)
-
- # --- With the tools permission granted, Python scripts allowed, and a plugin whose load fails. ---
- plugin_dir = install(datadir, tools=True)
- install_broken(datadir)
- orca = launch(env, datadir, ["--python-scripts"] + extra)
called = run_plugin_script(orca, plugin_dir, "call", CAPABILITIES[0])
- check("a plugin with the tools permission calls a tool from its Script worker", called == {"ok": True, "result": True}, called)
+ check("a plugin calls a tool from its Script worker", called == {"ok": True, "result": True}, called)
threaded = run_plugin_script(orca, plugin_dir, "thread", CAPABILITIES[1])
check("a thread its Script worker starts calls a tool too", threaded == {"ok": True, "result": True}, threaded)
rule = run_plugin_script(orca, plugin_dir, "rule", CAPABILITIES[2])
@@ -167,7 +155,7 @@ def main():
check("a plugin's calls are not in the agent's journal", not any(s["tool"] == "auto_answer_dialogs" for s in journal),
journal)
broken = orca.call_raw("search_tools", {"tool": f"plugin.{BROKEN}.measure"})
- check("a plugin whose load failed offers none of its granted operations", broken.get("isError"), broken)
+ check("a plugin whose load failed offers none of its operations", broken.get("isError"), broken)
held = run_plugin_script(orca, plugin_dir, "handle", CAPABILITIES[4])
check("the plugin opens a progress dialog and keeps its handle", held.get("ok") is True, held)
grab = orca.await_job(orca.call("run_script", code=GRAB_HANDLE))
@@ -187,7 +175,7 @@ def main():
time.sleep(3)
# --- Without MCP: a launch replay runs the plugin's script, whose calls reach the catalog-only service. ---
- install(datadir, tools=True) # enabled again: unticking it saved it disabled
+ install(datadir) # enabled again: unticking it saved it disabled
steps = os.path.join(datadir, "plugin_rule.json")
with open(steps, "w", encoding="utf-8") as f:
json.dump({"orca_replay": 1, "name": "a plugin's rule without MCP", "steps": [
diff --git a/tools/mcp/tests/plugins/mcp_tools_fixture/mcp_tools_fixture.py b/tools/mcp/tests/plugins/mcp_tools_fixture/mcp_tools_fixture.py
index 9057817b15..40821bb76e 100644
--- a/tools/mcp/tests/plugins/mcp_tools_fixture/mcp_tools_fixture.py
+++ b/tools/mcp/tests/plugins/mcp_tools_fixture/mcp_tools_fixture.py
@@ -11,12 +11,11 @@
Side-load it into a test data directory (test_plugin_tools.py does) and run its scripts from run_action.
Each script writes what happened to out_.json in the plugin's storage folder, which the test reads back:
-{"ok": true, "result": ...} or {"ok": false, "error": "...", "details": ...}. It asks for the tools
-permission unless ORCA_MCP_TOOLS_FIXTURE_ASK is 0. "call" calls get_app_state,
+{"ok": true, "result": ...} or {"ok": false, "error": "...", "details": ...}. "call" calls get_app_state,
"thread" calls it from a thread the script starts, "rule" registers an auto-answer rule, "export" asks for
export_replay, which a plugin is refused, and "handle" opens a progress dialog and keeps its handle in
-HANDLE, for a script to find and use. The plugin also offers the operation "measure", which
-doubles its argument a.
+HANDLE, for a script to find and use. The plugin also offers the operation "measure", which doubles its
+argument a.
"""
import json
import os
@@ -113,10 +112,6 @@ def measure(args):
@orca.plugin
class FixturePackage(orca.base):
def register_capabilities(self):
- # The prompt for it opens while the app starts, before MCP can answer it, so the test that checks a
- # plugin without the permission sets ORCA_MCP_TOOLS_FIXTURE_ASK=0 and the plugin does not ask.
- if os.environ.get("ORCA_MCP_TOOLS_FIXTURE_ASK", "1") != "0":
- orca.request_permissions(tools=True)
orca.register_operation("measure", "Doubles a.", {"type": "object", "properties": {"a": {"type": "number"}}}, measure,
changes=False)
for capability in (CallTool, CallFromThread, SetRule, ExportReplay, HoldHandle):
diff --git a/tools/mcp/tests/scene.json b/tools/mcp/tests/scene.json
index c998305a8a..ce05fd4732 100644
--- a/tools/mcp/tests/scene.json
+++ b/tools/mcp/tests/scene.json
@@ -78,7 +78,7 @@
{"tool": "select_objects", "args": {"parts": [[0, 1]]},
"expect": {"/canvas": {"eq": "3d"}, "/objects": {"eq": [0]}, "/instances": {"eq": [[0, 0]]}, "/parts": {"eq": [[0, 1]]}}},
{"tool": "get_app_state", "expect": {"/selection/parts": {"eq": [[0, 1]]}, "/python/available": {"eq": true},
- "/python/scripts_allowed": {"ne": null}, "/design_tab": {"ne": null}}},
+ "/python/scripts_unrestricted": {"ne": null}, "/design_tab": {"ne": null}}},
{"tool": "run_action", "args": {"id": "orca_command:obj_mirror_x:orca"}},
{"tool": "list_objects", "expect": {"/plates/0/objects/0/parts/1/mirrored": {"eq": true}, "/plates/0/objects/0/instances/0/mirrored": {"eq": false}}},
// a whole instance lists no parts