From 90bb0e6192575ce36850f436d007a2933eeb9369 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Tue, 10 Nov 2026 01:08:26 +0800 Subject: [PATCH] Describe orca_mcp.py's macOS datadir lookup as the stdio bridge's --- tools/mcp/README.md | 8 +++++--- tools/mcp/orca_mcp.py | 10 ++++++---- tools/mcp/test_orca_mcp_attach.py | 26 ++++++++++++++++---------- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/tools/mcp/README.md b/tools/mcp/README.md index d684dc2d41..77e4a5c84e 100644 --- a/tools/mcp/README.md +++ b/tools/mcp/README.md @@ -76,9 +76,11 @@ when it starts. Without a datadir it takes `default_datadir()`: `%APPDATA%\OrcaS `~/.config/OrcaSlicer`) on Linux. A portable install keeps its datadir in `data_dir` beside the binary (beside the `.app` on macOS) and is found only when that datadir is given, or the binary as `from_datadir(exe=...)`; a symlink to the binary is resolved on Linux, as the app resolves its own, -and taken as it is on Windows and macOS. When the file is missing, or a ping to the port it names -fails (nothing listens there, or another server answers), `from_datadir()` raises `McpError` saying -so, with the failure as its cause. +and taken as it is on Windows, as the app takes it. On macOS it is taken as it is, as the stdio +bridge (`McpStdioBridge.cpp`) takes it; whether the app itself resolves a symlinked binary there is +unverified, which matters only for a symlinked binary. When the file is missing, or a ping to the +port it names fails (nothing listens there, or another server answers), `from_datadir()` raises +`McpError` saying so, with the failure as its cause. `call_cad_tool(tool, **args)` calls `call_cad_tool {tool, args}`, follows a running job to its end and returns the CAD tool's `result`. A dialog that blocks the call fails it at once, naming the diff --git a/tools/mcp/orca_mcp.py b/tools/mcp/orca_mcp.py index f7945224d4..4880c65ab4 100755 --- a/tools/mcp/orca_mcp.py +++ b/tools/mcp/orca_mcp.py @@ -54,10 +54,12 @@ def default_datadir(exe=None): """The datadir OrcaSlicer uses without --datadir, as McpStdioBridge.cpp's default_datadir() picks it. A portable install keeps it in data_dir beside the binary `exe` (beside the .app on macOS), which - is looked for only when `exe` is given; otherwise it is the platform's configuration folder. The - binary is located as the app locates itself: on Linux through /proc/self/exe, which resolves - symlinks, so a symlinked `exe` is resolved too; on Windows (GetModuleFileName) and macOS - (_NSGetExecutablePath) by the path it was started by, symlinks left as they are.""" + is looked for only when `exe` is given; otherwise it is the platform's configuration folder. On + Linux the binary is located as the app locates itself, through /proc/self/exe, which resolves + symlinks, so a symlinked `exe` is resolved too; on Windows by GetModuleFileName, which leaves them. + On macOS it follows the stdio bridge, whose _NSGetExecutablePath takes the path as given; whether + the app itself resolves a symlinked binary there (its lookup goes through the main bundle) is + unverified, which matters only for a symlinked binary.""" if exe: exe = os.path.abspath(exe) if sys.platform in ("win32", "darwin") else os.path.realpath(exe) folder = os.path.dirname(exe) diff --git a/tools/mcp/test_orca_mcp_attach.py b/tools/mcp/test_orca_mcp_attach.py index 6def9f77db..8d79cae570 100755 --- a/tools/mcp/test_orca_mcp_attach.py +++ b/tools/mcp/test_orca_mcp_attach.py @@ -5,12 +5,13 @@ default_datadir() takes a portable data_dir beside the binary (beside the .app on macOS) and otherwise the platform's configuration folder; it resolves a symlinked binary on Linux, as the app -does through /proc/self/exe, and nowhere else (skipped where no symlink can be made). from_datadir() -refuses a datadir without mcp/server.json, and one whose server.json names a port where nothing -listens or where another server answers (HTTP 401, a reply that is not JSON), naming the file, giving -the --mcp advice and chaining the cause. call_cad_tool(), against a stubbed call(), fails at once on -a dialog, follows a running job, prefixes its errors with the CAD tool's name and returns the tool's -result. Exits 0 when every check passes. +does through /proc/self/exe, and takes it as given on Windows, as the app does, and on macOS, as the +stdio bridge does (skipped where no symlink can be made). from_datadir() refuses a datadir without +mcp/server.json, and one whose server.json names a port where nothing listens or where another +server answers (HTTP 401, a reply that is not JSON), naming the file, giving the --mcp advice and +chaining the cause. call_cad_tool(), against a stubbed call(), fails at once on a dialog, follows a +running job, prefixes its errors with the CAD tool's name and returns the tool's result. Exits 0 +when every check passes. """ import http.server @@ -96,13 +97,18 @@ def check_symlinked_binary(): except (OSError, NotImplementedError) as e: print(f"skip - default_datadir() with a symlinked binary: no symlink can be made here ({e})") return - if sys.platform in ("win32", "darwin"): - expected, how = os.path.join(linked, "data_dir"), "takes a symlinked binary as it is" + if sys.platform == "darwin": + # As McpStdioBridge.cpp's _NSGetExecutablePath; whether the app's own lookup (the main + # bundle's) resolves a symlinked binary is unverified. + expected, how = linked, "takes a symlinked binary as given, as the stdio bridge does" + elif sys.platform == "win32": + expected, how = linked, "takes a symlinked binary as given, as the app does" else: - expected, how = os.path.join(real, "data_dir"), "resolves a symlinked binary" + expected, how = real, "resolves a symlinked binary, as the app does" + expected = os.path.join(expected, "data_dir") got = orca_mcp.default_datadir(link) assert same_path(got, expected), f"{sys.platform}: {got} != {expected}" - ok(f"default_datadir() {how} on {sys.platform}, as the app does") + ok(f"default_datadir() {how} on {sys.platform}") def datadir_naming(port, prefix):