From 5cc54c48c8dfac064fbe8bcab1962b2cb74d23de Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sat, 24 Oct 2026 18:13:26 -0400 Subject: [PATCH 1/2] fix(isolation): detect the runtime of Windows launchers with an .exe/.cmd suffix DetectRuntimeType switched on the exact base name, so a Windows config naming uvx.exe, npx.cmd, npm.cmd, pip.exe or go.exe fell to the "binary" default. Docker isolation then picked the generic image and ran e.g. npx.cmd inside a Linux container, where it does not exist, so the server never started. Lowercase the base name and strip a .exe, .cmd or .bat suffix before matching. --- internal/upstream/core/isolation.go | 9 ++++-- .../core/isolation_windows_ext_test.go | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 internal/upstream/core/isolation_windows_ext_test.go diff --git a/internal/upstream/core/isolation.go b/internal/upstream/core/isolation.go index f7f610b54..2c3547e1f 100644 --- a/internal/upstream/core/isolation.go +++ b/internal/upstream/core/isolation.go @@ -220,8 +220,13 @@ func (im *IsolationManager) warnPerServerIgnoredOnce(serverName string) { // DetectRuntimeType detects the runtime type based on the command func (im *IsolationManager) DetectRuntimeType(command string) string { - // Extract just the command name without path - cmdName := filepath.Base(command) + // Extract just the command name without path or a Windows executable + // suffix (uvx.exe, npx.cmd), compared case-insensitively as Windows does. + cmdName := strings.ToLower(filepath.Base(command)) + switch filepath.Ext(cmdName) { + case ".exe", ".cmd", ".bat": + cmdName = strings.TrimSuffix(cmdName, filepath.Ext(cmdName)) + } // Handle common runtime commands switch cmdName { diff --git a/internal/upstream/core/isolation_windows_ext_test.go b/internal/upstream/core/isolation_windows_ext_test.go new file mode 100644 index 000000000..5df8a0a54 --- /dev/null +++ b/internal/upstream/core/isolation_windows_ext_test.go @@ -0,0 +1,30 @@ +package core + +import ( + "testing" + + "github.com/stretchr/testify/assert" + + "github.com/smart-mcp-proxy/mcpproxy-go/internal/config" +) + +// Windows configs name launchers with their executable suffix (uvx.exe, +// npx.cmd). Treating those as an unknown "binary" picks the generic image and +// runs "npx.cmd" inside a Linux container, where it does not exist. +func TestDetectRuntimeType_WindowsExecutableSuffix(t *testing.T) { + im := NewIsolationManager(config.DefaultDockerIsolationConfig()) + cases := map[string]string{ + "uvx.exe": cmdUvx, + "npx.cmd": cmdNpx, + "NPX.CMD": cmdNpx, + "npm.cmd": cmdNpm, + "yarn.cmd": cmdYarn, + "pip.exe": cmdPip, + "go.exe": cmdGo, + "uvx": cmdUvx, + "my-tool": "binary", + } + for cmd, want := range cases { + assert.Equal(t, want, im.DetectRuntimeType(cmd), cmd) + } +} From ea96febc6d95a3a8d345b8e1884a09f24e967de7 Mon Sep 17 00:00:00 2001 From: Algis Dumbris Date: Mon, 26 Oct 2026 13:20:37 +0200 Subject: [PATCH 2/2] fix(diagnostics): mirror Windows launcher suffix stripping in detectDockerRuntimeType Review finding on #1778: core.DetectRuntimeType now lowercases the command and strips .exe/.cmd/.bat, but its diagnostics mirror did not, so a uvx.exe server got remediation for a "uvx.exe" runtime and no git-dependency hint while spawn used the uvx image and the git-capable substitute. Co-Authored-By: Claude Opus 5.5 --- internal/diagnostics/remediation.go | 16 +++++++++---- .../remediation_runtime_gate_test.go | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/internal/diagnostics/remediation.go b/internal/diagnostics/remediation.go index cda0942fb..ae4e9d117 100644 --- a/internal/diagnostics/remediation.go +++ b/internal/diagnostics/remediation.go @@ -68,7 +68,14 @@ func RuntimeAwareRemediation(code Code, hints ClassifierHints) string { // fall back to the base command name so the message still names something // concrete rather than a generic "interpreter". func detectDockerRuntimeType(command string) string { - cmdName := filepath.Base(command) + base := filepath.Base(command) + // Mirror core.DetectRuntimeType: case-insensitive, with a Windows + // launcher suffix (.exe/.cmd/.bat) stripped. + cmdName := strings.ToLower(base) + switch filepath.Ext(cmdName) { + case ".exe", ".cmd", ".bat": + cmdName = strings.TrimSuffix(cmdName, filepath.Ext(cmdName)) + } switch cmdName { case "python", "python3", "python3.11", "python3.12", "python3.13": return "python" @@ -101,14 +108,13 @@ func detectDockerRuntimeType(command string) string { case "composer": return "composer" default: - lower := strings.ToLower(cmdName) - if strings.Contains(lower, "python") { + if strings.Contains(cmdName, "python") { return "python" } - if strings.Contains(lower, "node") { + if strings.Contains(cmdName, "node") { return "node" } - return cmdName + return base } } diff --git a/internal/diagnostics/remediation_runtime_gate_test.go b/internal/diagnostics/remediation_runtime_gate_test.go index 08f5786c6..6dd0293ce 100644 --- a/internal/diagnostics/remediation_runtime_gate_test.go +++ b/internal/diagnostics/remediation_runtime_gate_test.go @@ -72,3 +72,27 @@ func TestMirroredGitRuntimeGateMatchesConfig(t *testing.T) { } } } + +// The mirror has to normalise a Windows launcher name the way +// core.DetectRuntimeType does, or a uvx.exe/npx.cmd server gets remediation +// for a "uvx.exe" runtime and no git-dependency hint while the spawn path uses +// the uvx image and the git-capable substitute. +func TestDetectDockerRuntimeTypeWindowsLauncherSuffix(t *testing.T) { + cases := map[string]string{ + "uvx.exe": "uvx", + "npx.cmd": "npx", + "Uvx.EXE": "uvx", + "npm.bat": "npm", + "my-tool.exe": "my-tool.exe", + } + for command, want := range cases { + if got := detectDockerRuntimeType(command); got != want { + t.Errorf("detectDockerRuntimeType(%q) = %q, want %q", command, got, want) + } + } + + hints := ClassifierHints{DockerCommand: "uvx.exe", DockerArgs: []string{"git+https://x"}} + if !hintsHaveGitDependency(hints) { + t.Error("hintsHaveGitDependency(uvx.exe, git+) = false, want true") + } +}