Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions internal/diagnostics/remediation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}

Expand Down
24 changes: 24 additions & 0 deletions internal/diagnostics/remediation_runtime_gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
9 changes: 7 additions & 2 deletions internal/upstream/core/isolation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions internal/upstream/core/isolation_windows_ext_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Loading