Skip to content

fix(config): drop blocking uvx preflight and realign fork-only helpers with upstream - #11

Merged
onlyfeng merged 6 commits into
betafrom
fix/fork-alignment-cleanup
Oct 9, 2026
Merged

onlyfeng merged 6 commits into
betafrom
fix/fork-alignment-cleanup

Conversation

@onlyfeng

@onlyfeng onlyfeng commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Summary

Cleans up fork-only changes that either regressed after merging upstream or are now covered by upstream, while keeping the two automatic behaviors users rely on.

Regressions / bugs

  • Editor startup stall: the stdio preflight ran uvx ... mcp-for-unity --help synchronously on the main thread with a 60s timeout. Upstream's StartupConfigRewrite (added 2026-05-18) calls the config write path for every stale client on Editor startup, so after a package upgrade stdio users could see the Editor stall for up to 60s per client. The probe is replaced by a cheap check (McpConfigurationHelper.GetStdioLauncherError) that rejects a missing uvx (invalid override with no system fallback; previously Claude registration removed existing registrations and then ran claude mcp add ... -- "") and Windows .bat/.cmd shims.
  • Corporate CA flag is chosen by uv version: auto-detection (SSL_CERT_FILE, REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE, NODE_EXTRA_CA_CERTS) and the MCPForUnity.UseSystemCertificates override (always/never, unchanged key) are kept. uv 0.11 renamed --native-tls to --system-certs (deprecated alias, identical behavior per the 0.11.0 changelog), and older uv rejects the new name outright. The uv version is probed (only when the flag is needed, cached per uvx path): uv >= 0.11 or unknown gets --system-certs, so configs for users already running this fork stay byte-identical; only uv < 0.11 gets --native-tls.
  • QuoteCommandLineArg doubled every backslash (C:\My Path\Server → "C:\\My Path\\Server"). It now follows Windows argv rules: only backslash runs before a quote are escaped.

pyenv-win shims resolved automatically

  • When no uvx.exe/uv.exe is found on Windows, the resolver asks pyenv-win (pyenv which uvx, then uv) for the real executable behind shims\uvx.bat and writes that .exe into client configs. The answer is cached for the domain because pyenv-win is slow to start. pyenv which output format was checked against pyenv-win's pyenv.vbs (CommandWhich echoes the full path, exits 1 on failure).
  • If pyenv-win can't resolve one, the first uvx/uv .bat/.cmd shim on PATH (or in pyenv-win's shims folder) is returned instead of the bare uvx fallback, so stdio configs reject it with a clear message rather than persisting a command the client would run through cmd.exe.
  • A uvx override that points at a .bat/.cmd shim is still rejected for stdio configs; the message now suggests clearing it so the shim is resolved automatically.

Realigned with upstream

Behavior changes to note

  • Stdio config writes no longer verify that the server launches; launch failures show up in the MCP client instead.

Test plan

  • Roslyn semantic check of all changed C# files (including method bodies): only missing-Unity/NUnit-type diagnostics remain
  • QuoteCommandLineArg cases verified against a CommandLineToArgvW round-trip simulation
  • ResolveUvxBehindPyenvShim + ExecPath.TryRun, extracted verbatim, run against a fake pyenv on macOS: all 7 PathResolverPyenvTests scenarios (including FindUvShim) pass
  • Full EditMode run in Unity 2022.3.62f3 (macOS, batchmode, copy of TestProjects/UnityMCPTests): 1591 cases, 1513 passed, 0 failed, 78 skipped (Windows-only). UvxLaunchArgsTests 22/22, PathResolverPyenvTests 7/7, WriteToConfigTests 10/10
  • Deployed-user parity: in Unity, BuildUvxServerLaunchArgs with REQUESTS_CA_BUNDLE set produces byte-identical args on this branch and on fork beta (dabf4699): --system-certs --prerelease explicit --from mcpforunityserver>=0.0.0a0 mcp-for-unity --transport stdio (uv 0.12.19); identical without the CA variable too
  • Manual (Windows + pyenv-win with uv installed via pip): configure a stdio client and confirm the config points at versions\<ver>\Scripts\uvx.exe
  • Manual: configure a stdio client and confirm no startup stall after a package version bump

No Windows machine was available, so the pyenv-win path is covered only by the cross-platform fake-pyenv tests.

🤖 Generated with Claude Code

…s with upstream

- Replace the stdio preflight (a synchronous `uvx ... --help` run with a 60s
  timeout on the main thread) with a path-only check for Windows .bat/.cmd
  shims. Upstream's StartupConfigRewrite calls the config write path for every
  stale client on Editor startup, so the probe could stall startup by up to
  60s per client.
- Remove the auto-injected `uvx --system-certs` flag and its
  UseSystemCertificates pref. The pref had no UI, the decision depended on the
  Editor's environment at configure time, and uv builds that predate the flag
  reject it outright. UV_SYSTEM_CERTS covers the same need and older uv ignores it.
- Fix QuoteCommandLineArg doubling every backslash; only runs before a quote
  are escaped under Windows argv rules.
- Restore upstream PathResolverService/IPathResolverService: shim discovery,
  the unused ResolvedUvxIsShim/IsShimPath members and the uncalled
  IsPythonDetected change are gone (upstream CoplayDev#1324 covers pyenv-win).
- Remove BackupStaleClientConfigIfNeeded and the duplicate shim guard in
  RegisterWithCapturedValues (its only caller already checks).
- Skill sync reads .claude/skills/unity-mcp-skill again, matching upstream
  now that CoplayDev#1442 merged the two skill copies; drop the fallback directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T03:02:50.127843Z 9396737 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ef3398084

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 70 to 72
string[] commandNames = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? new[] { "uvx.exe", "uv.exe", "uvx.bat", "uvx.cmd", "uv.bat", "uv.cmd" }
? new[] { "uvx.exe", "uv.exe" }
: new[] { "uvx", "uv" };

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve batch shim paths so the safety check can reject them

On Windows installations where uv is available only through a pyenv-style uvx.bat/uv.cmd, restricting discovery to .exe files makes ResolveUvxFromSystem return null, after which GetUvxPath falls back to the bare string uvx. GetStdioShimError cannot recognize that bare command as a shim, so stdio configurators accept and persist it; the MCP client then resolves the same batch shim at launch and can misinterpret the mcpforunityserver>=0.0.0a0 argument. Continue resolving batch paths so they can be explicitly rejected, or avoid returning a bare command when only a shim is present.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 759f3c0. When no uvx.exe/uv.exe is found and pyenv-win cannot resolve the real executable, the resolver now returns the first uvx/uv .bat/.cmd shim on PATH (or in pyenv-win's shims folder) instead of letting GetUvxPath fall back to bare uvx, so GetStdioLauncherError rejects it explicitly. The lookup is a plain File.Exists scan, cached per domain together with the pyenv result. Covered by PathResolverPyenvTests.FindUvShim_*.

- Restore automatic TLS handling behind corporate proxies: when SSL_CERT_FILE,
  REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE or NODE_EXTRA_CA_CERTS is set, the uvx
  launch args include --native-tls. The old flag name is used on purpose:
  current uv still accepts it (verified on 0.12.19), while uv builds that
  predate the --system-certs rename reject the new name.
- On Windows, when no uvx.exe/uv.exe is found, resolve pyenv-win's uvx.bat /
  uv.bat shim to the real executable via `pyenv which` (cached per domain),
  so stdio configs get a launchable .exe instead of the bare "uvx" fallback.
- The shim error now also suggests clearing an override that points at a
  pyenv-win shim.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 868cf8ef71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 262 to 263
if (!useStdio || !IsWindowsShellShimCommand(uvxPath))
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject null uvx paths before registering Claude

When an invalid uvx override is set and no system fallback exists, GetUvxPath() returns null, but this condition now returns no error. Both Claude registration paths therefore continue with an empty command; RegisterWithCapturedValues first removes registrations from every scope and then invokes claude mcp add ... -- "", which either leaves no registration or persists a broken one. Preserve the former missing-uvx check before allowing stdio registration.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 759f3c0. GetStdioShimError is now GetStdioLauncherError and returns "uv package manager not found" for a null/blank uvx path when writing stdio, so both Claude registration paths (the synchronous Register() and the UI pre-check before RegisterWithCapturedValues) stop before removing existing registrations. Covered by UvxLaunchArgsTests.GetStdioLauncherError_RejectsMissingUvx.

// .claude/skills can drift (fewer reference files, stale SKILL.md) and is only a fallback.
private const string SkillSubdir = "unity-mcp-skill";
private const string FallbackSkillSubdir = ".claude/skills/unity-mcp-skill";
private const string SkillSubdir = ".claude/skills/unity-mcp-skill";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain the top-level skill fallback for custom repositories

The installer exposes an editable Repo URL, so users can sync forks whose main or beta branch still contains only the previously canonical top-level unity-mcp-skill directory. Hard-coding the nested .claude copy makes both the GitHub API and sparse-clone paths report “Remote directory not found” for those otherwise compatible repositories; upstream merging the two copies does not update existing forks. Prefer the nested source if desired, but retain the top-level fallback.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adopting this one. .claude/skills/unity-mcp-skill was added on 2026-02-10 (CoplayDev#707), three weeks before SkillSyncService itself existed (2026-03-02, CoplayDev#845), and upstream has never had a top-level fallback in either the GitHub API or the sparse-clone path. A repo that has only the top-level copy would have to be a snapshot from the 2026-02-03..02-10 window, or a fork that deleted the nested copy. Re-adding a fallback to both paths for that case is not worth diverging from upstream again; the "Remote directory not found" error already names the missing path.

…"uvx"

Addresses Codex review on #11:
- When no uvx.exe/uv.exe is found and pyenv-win can't resolve one, return
  the first uvx/uv .bat/.cmd shim on PATH (or in pyenv-win's shims folder)
  instead of letting GetUvxPath fall back to bare "uvx". Stdio configurators
  then reject it with a clear message rather than persisting a command the
  MCP client would resolve to the same shim and run through cmd.exe.
- GetStdioShimError -> GetStdioLauncherError, which also rejects a missing
  uvx (invalid override, no system fallback). Previously Claude registration
  removed existing registrations and then ran `claude mcp add ... -- ""`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 759f3c0ddb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +340 to +345
foreach (string name in CorporateCaEnvVars)
{
try
{
string value = Environment.GetEnvironmentVariable(name);
if (!string.IsNullOrEmpty(value))
return true;
}
catch { }
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable(name)))
return new[] { "--native-tls" };
}
return false;
}

/// <summary>
/// Returns the uvx system-cert flag arguments as a list. Empty when disabled.
/// </summary>
public static IReadOnlyList<string> GetSystemCertsArgsList()
{
return ShouldUseSystemCerts() ? new[] { "--system-certs" } : Array.Empty<string>();
}

/// <summary>
/// Returns the uvx system-cert flag as a trailing-space string, suitable for
/// concatenation into command-line builders (mirrors <see cref="GetUvxDevFlags()"/>).
/// </summary>
public static string GetSystemCertsArgs()
{
return ShouldUseSystemCerts() ? "--system-certs " : string.Empty;
return Array.Empty<string>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the explicit native-TLS override

When a corporate proxy's CA is installed only in the OS trust store, none of these environment variables is necessarily set. Users who previously selected MCPForUnity.UseSystemCertificates=always then lose their explicit override because this commit removes that preference and emits --native-tls only after environment-variable detection, causing uv package downloads to fail again in that environment. Retain the always/never preference behavior while emitting the backward-compatible flag.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 918e607. MCPForUnity.UseSystemCertificates is read again: always forces --native-tls, never suppresses it, anything else keeps the environment-variable auto-detection. The key name is unchanged so existing overrides keep working, and the emitted flag stays the backward-compatible --native-tls. Covered by UvxLaunchArgsTests.BuildUvxServerLaunchArgs_AlwaysOverride_* / _NeverOverride_*.

@onlyfeng onlyfeng Oct 9, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up in 12a3d75: the flag is now chosen by uv version. uv 0.11 renamed --native-tls to --system-certs (deprecated alias, identical behavior per the 0.11.0 changelog). Users already running with --system-certs have uv >= 0.11, so they keep getting exactly --system-certs (configs stay byte-identical and survive the alias's eventual removal); only uv < 0.11 gets --native-tls. The version comes from TryValidateUvxExecutable, probed only when the flag is needed and cached per uvx path.

Addresses Codex review on #11: when a corporate proxy's CA lives only in the
OS trust store, no environment variable reveals it, so auto-detection alone
misses it. Read MCPForUnity.UseSystemCertificates again ("always"/"never",
default auto-detect) and keep emitting the backward-compatible --native-tls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 918e607e16

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 264 to 267
if (string.IsNullOrWhiteSpace(uvxPath))
return "uvx not found. Install uv/uvx or set the override in Advanced Settings.";

if (IsWindowsShellShimCommand(uvxPath))
{
return "Refusing to write Unity MCP stdio config with a Windows batch shim. " +
$"Detected '{uvxPath}', which can corrupt arguments such as mcpforunityserver>=0.0.0a0. " +
"Install uv so a real uvx.exe/uv.exe is available, or set the uvx path override to the real executable.";
}

var args = new List<string>(AssetPathUtility.BuildUvxServerLaunchArgs(packageName, includeTransportStdio: false))
{
"--help"
};
string argsString = string.Join(" ", args.ConvertAll(AssetPathUtility.QuoteCommandLineArg));

if (ExecPath.TryRun(uvxPath, argsString, null, out _, out string stderr, timeoutMs: 60000))
return "uv package manager not found. Please install uv first.";
if (!IsWindowsShellShimCommand(uvxPath))
return null;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject the unresolved bare uvx fallback

When no override is configured and system discovery finds neither uvx nor uv, PathResolverService.GetUvxPath() returns the bare string "uvx". This value is nonblank and is not a Windows shim, so this replacement for the executable preflight returns no error and stdio configurators persist a command that cannot launch; this can also overwrite an existing config during startup rewriting after uv has been removed. Treat the resolver's unresolved bare fallback as missing, or have the resolver return null when discovery fails.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not adopting this one. The bare uvx fallback is deliberate upstream behavior: Unity launched from the Hub/Dock often has a much narrower PATH than the MCP client, so discovery can miss a uv the client resolves fine (e.g. ~/.pyenv/shims/uvx on macOS, which EnumerateCommandCandidates does not probe). Rejecting the fallback would stop those currently working users from configuring at all. The fork only rejected it before as a side effect of the blocking uvx --help probe that this PR removes on purpose; a truly absent uv still fails visibly in the client.

… uv version

uv 0.11 renamed --native-tls to --system-certs; the old name is deprecated
but behaves identically (uv 0.11.0 changelog). Users already running this
fork with corporate CAs have uv >= 0.11, since their --system-certs configs
work. Emitting --native-tls would rewrite those configs and break them once
uv drops the deprecated name.

Probe the uv version (TryValidateUvxExecutable, cached per uvx path, only
when the flag is needed) and emit --system-certs on uv >= 0.11 or an unknown
version, --native-tls only on older uv. Configs for deployed users stay
byte-identical to what earlier builds wrote.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 12a3d75468

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +96 to +97
_windowsShimFallback = ResolveUvxBehindPyenvShim(pyenvRoot) ?? FindUvShim(shimDirs);
_windowsShimFallbackResolved = true;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not cache a failed shim lookup for the whole domain

When the first Windows lookup occurs before uv has been installed into pyenv, this sets _windowsShimFallbackResolved even though _windowsShimFallback is null. If the user then installs uv or changes pyenv versions without restarting Unity, every subsequent lookup skips shim resolution; because the real executable normally is not on PATH, GetUvxPath() falls back to bare uvx, which the MCP client resolves to the newly created batch shim and launches with corrupted metacharacter arguments. This differs from the deliberate narrow-PATH fallback because discovery already ran and permanently cached an absence; cache only successful results or provide invalidation when dependencies are refreshed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9396737. A miss is no longer cached: it never runs pyenv (pyenv which only runs when a uv shim exists, and then the shim itself is returned), so repeating it is just a few File.Exists checks and uv installed into pyenv later is found on the next lookup. A resolved .exe is reused only while it still exists, and a bare shim result (pyenv could not resolve it) is re-checked after 30 seconds, so fixing pyenv is picked up without a domain reload. Verified the install-after-miss, deleted-exe and shim-recheck sequences against the extracted code with a fake pyenv.

Addresses Codex review on #11: a miss before uv was installed into pyenv
was cached until the next domain reload, so a later install was ignored and
GetUvxPath fell back to bare "uvx", which the client resolves to the new
batch shim. A miss never runs pyenv and is cheap to repeat, so it is no
longer cached. A resolved .exe is reused while it still exists; a bare shim
(pyenv could not resolve it) is re-checked after 30 seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@onlyfeng
onlyfeng merged commit a115635 into beta Oct 9, 2026
10 checks passed
@onlyfeng
onlyfeng deleted the fix/fork-alignment-cleanup branch October 9, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant