diff --git a/docs/subsystems/library.md b/docs/subsystems/library.md index 0371ec053..aa140f59b 100644 --- a/docs/subsystems/library.md +++ b/docs/subsystems/library.md @@ -65,7 +65,7 @@ Pi's extensions and packages. - An MCP OAuth sign-in canceled or timed out before its callback commits never saves a late token or changes an existing sign-in. The callback's write and the flow's ending share a lock (`flow.keep` in [`mcpauth.go`](../../internal/mcpauth/mcpauth.go)); if the write wins first, it completes and tells the agents before saying done. A cancellation is not a sign-out of credentials already committed. - A server an agent can't reach is not written there, and `mcpFile.supports` says why. For example, Claude Desktop takes no remote server, and Codex, Goose, dsh, Grok, Command Code and Zed take no SSE. - A server's headers (remote) or environment (command) can name a variable as `${NAME}` (#1250). `library.json` keeps the placeholder, and `refsOf` gives each MCP format the agent's own syntax, with the agent's source cited beside it: `${NAME}` for most, `{env:NAME}` for OpenCode and MiMo, `${env:NAME}` for Cursor, and Codex's own keys (`bearer_token_env_var`, `env_http_headers`, `env_vars`). Goose gets `${NAME}` plus `env_keys`. dsh (DeepSeek Harness) gets a `!!js` expression it evaluates as it loads the server (#1435): a whole `${NAME}` is `!!js process.env.NAME`, and a value mixing text and variables is the text as JSON string literals joined with `(process.env.NAME ?? "")`, so the user's text is never run as code and an unset variable inside it is empty. A whole variable that isn't set makes dsh leave the server out as invalid. magpie reads only those forms back as `${NAME}`; any other `!!js` keeps the entry the user's. An agent with no syntax (Claude Desktop, Antigravity, Kimi, Cline, ZCode, Zed, Devin, Alma, Pi with pi-mcp-extension) is never written the value: `refsProblem` makes `supports` refuse the server, a magpie entry already there is taken out, and `AgentView.NoEnvRefs` greys its chip with the reason. Codex and Goose's extra keys are magpie's only while the server names a variable there (`refKeys`), so the user's own `env_vars` or `env_keys` are kept. `CheckServers`, the router (`dialHub`) and Codex's run through the gateway (`specOf`) expand the variable in memory (`expandAll`): from magpie's own environment, else from what a terminal opened now has (`proc.LoginVars`: what the login shell, or fish or nushell, exports, kept a minute; the registry's user then machine variables on Windows), since a magpie opened from the Finder has none of the profile's variables and a server whose token was exported in .zshrc showed no tools (Cyrus on Discord, `TestEnvRefsFromLoginShell`, `TestLoginVars`). The value is never set in magpie's environment, written to library.json or an agent's file, or logged. One set nowhere is `novar`, naming it. The page paints that as not checked (a ring, `lib-health unknown`), not red: it says nothing of the server, which the agent may start with the variable set, as Codex does its host-only `codex_app` (#2308). It starts a command server in home, with `PWD` set to it (not on Windows), as an agent started from home would, never in magpie's own working folder: a magpie started from the Windows Start menu has `C:\Windows\system32`, where a server that writes into `.` exits before it answers (#1727, `TestCheckStdio`). -- A command server's command and args can name a variable as `$NAME` or `${NAME}`, or start with `~` (math_milian on Discord: `$HOME/bin/x` on a Mac and on Linux). `library.json` keeps them as written; `withCmdVars` (cmdvars.go) makes the copy each agent is written, after `runVia`, in sync and in a project's files. An agent that expands a reference in a command and its args itself (`cmdRefs`: Claude Code, CodeBuddy and WorkBuddy, Grok, Gemini, omp/Qoder/AtomCode, OpenCode as `{env:NAME}`, Cursor as `${env:NAME}`) is given the reference in its syntax, `$NAME` written `${NAME}`, so a token in an arg stays out of its file. Every other agent (Droid by `NoCmdRefs`, though it shares Claude Code's format; Codex, Kiro, Crush, Copilot, Goose, Pi, Hermes, dsh and those reading none) starts the command as written, with no shell, so it is given the values: `HOME` as its own home, the rest from magpie's environment or a terminal's (`lookCmdVar`); one in WSL gets the distro's home (`mcpFile.Home`) and no variable of magpie's. A `~` is put in for every agent. A variable nothing has is left as written. The comparison a sync makes is against that copy, so a second sync rewrites nothing (`TestCmdVarsSync`). magpie starting the command itself does the same (`launchCmd`): the check and the router (`startServer`, a distro's home asked of its login shell, `distroHome`) and Codex's run through the gateway (`specOf`) (`TestCmdVarsLaunch`). +- A command server's command and args can name a variable as `$NAME` or `${NAME}`, or start with `~` (math_milian on Discord: `$HOME/bin/x` on a Mac and on Linux). `library.json` keeps them as written; `withCmdVars` (cmdvars.go) makes the copy each agent is written, after `runVia`, in sync and in a project's files. An agent that expands a reference in a command and its args itself (`cmdRefs`: Claude Code, CodeBuddy and WorkBuddy, Grok, Gemini, omp/Qoder/AtomCode, OpenCode as `{env:NAME}`, Cursor as `${env:NAME}`) is given the reference in its syntax, `$NAME` written `${NAME}`, so a token in an arg stays out of its file. Every other agent (Droid by `NoCmdRefs`, though it shares Claude Code's format; Codex, Kiro, Crush, Copilot, Goose, Pi, Hermes, dsh and those reading none) starts the command as written, with no shell, so it is given the values: `HOME` as its own home, the rest from magpie's environment or a terminal's (`lookCmdVar`); one in WSL gets the distro's home (`mcpFile.Home`) and no variable of magpie's. A `~` (or `~\`) is put in for every agent. A variable nothing has is left as written. The home has one meaning on every system (0xBCD18E on X: `%USERPROFILE%\AppData\…` on computers whose users have different names): `HOME` and `USERPROFILE` are both the home, as `$NAME`, `${NAME}` or cmd.exe's `%NAME%` (either case), so an agent that reads references is given the home's own variable where it runs, `${USERPROFILE}` on Windows (an agent there seldom has `HOME`) and `${HOME}` elsewhere and in WSL, and every other agent and magpie's own start get the home itself. Any other `%NAME%` is a variable on Windows only (`cmdOS`) and left as written elsewhere, so `100%` or `%Y%` in an arg stays as it is. In a command's environment a leading `~` and `%USERPROFILE%` or `%HOME%` are put in as the home for every agent and for magpie's own start (`homeEnv`); `${NAME}` there stays envref's (`TestCmdVarsUserProfile`, `TestCmdVarsUserProfileLaunch`). The comparison a sync makes is against that copy, so a second sync rewrites nothing (`TestCmdVarsSync`). magpie starting the command itself does the same (`launchCmd`): the check and the router (`startServer`, a distro's home asked of its login shell, `distroHome`) and Codex's run through the gateway (`specOf`) (`TestCmdVarsLaunch`). - A command server is checked where the agents given it run (loong on Discord: a WSL program, given only to agents in WSL, was checked on Windows and "exited (1)"). `checkSides` reads each agent id's `@wsl:`: with none, or off Windows, or a Windows path for the command (`windowsPath`, magpie's own image server among them), or Settings' Detect agents in WSL off, it is this computer as before. Otherwise each distro is a side, after this computer when an agent here has it too. In a distro the command is found as the agents' shell finds it (`wslrun.In`: a login shell, then an interactive one for nvm's node, the probe `wslrun.Find` uses) and started through `wslrun.Tool.Command` (`wsl.exe -d D --exec /usr/bin/env PATH=… args`), its env passed by `WSLENV`. A distro that isn't running is never started for a check: it is `wsldown`, naming the distro, painted as not checked like `novar`; beside a side that was checked it is left out. `ServerHealth.Checked` lists where it started, `""` for this computer; the first failure ends the check and is the last place's, which the row names (" · WSL Ubuntu") and the tooltip says (`TestCheckWSLOnlyServerInItsDistro`, `TestCheckWindowsServerHere`, `TestCheckMixedServerEachSide`, `library-mcp-health-wsl.test.cjs`). Agents moved between sides is a check anew (`healthKey`, both sides). In a distro the command runs in the folder wsl.exe gives it (the Windows home under `/mnt`), not the Linux home. - A server's tools turned off on the page (nf1qaz2w on Discord) are kept by their names as the server gives them, in `Server.DisabledTools`, and written only to the agents that read a setting for it (`toolsOffOf`), each in its own form, checked against its source: - Codex: `disabled_tools` in the server's table in config.toml (`codex-rs/config/src/mcp_types.rs`, applied by `ToolFilter` in `codex-rs/codex-mcp/src/tools.rs`, openai/codex cc7ba336). diff --git a/internal/library/cmdvars.go b/internal/library/cmdvars.go index ba95d2204..eb0e09d75 100644 --- a/internal/library/cmdvars.go +++ b/internal/library/cmdvars.go @@ -14,9 +14,21 @@ package library // what magpie's environment or a terminal has. A ~ is put in for every // agent: none of them reads one. A variable nothing has is left as // written. +// +// A home is named the same way on every system (0xBCD18E on X: one +// command on computers whose users have different names): HOME and +// USERPROFILE are both the home, as $NAME, ${NAME} or Windows' %NAME%, +// and so is a leading ~ or ~\. An agent that reads references is given +// the home's own variable where it runs, ${USERPROFILE} on Windows (where +// an agent seldom has HOME) and ${HOME} elsewhere (where none has +// USERPROFILE). Any other %NAME% is a variable on Windows only; elsewhere +// it is left as written, as cmd.exe's syntax means nothing there. In a +// command's environment a leading ~ and %USERPROFILE% or %HOME% are put +// in as the home for every agent; $NAME and ${NAME} there are envref.go's. import ( "os" + "runtime" "strings" "sync" "time" @@ -25,20 +37,70 @@ import ( "github.com/yetone/magpie/internal/wslrun" ) -// cmdVar is a variable in a command or an arg: ${NAME} or $NAME. -var cmdVar = lazyre.New(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)`) +// cmdVar is a variable in a command or an arg: ${NAME}, $NAME, or +// %NAME% as cmd.exe writes one (ProgramFiles(x86) has parentheses). +var cmdVar = lazyre.New(`\$\{([A-Za-z_][A-Za-z0-9_]*)\}|\$([A-Za-z_][A-Za-z0-9_]*)|%([A-Za-z_][A-Za-z0-9_()]*)%`) -// hasCmdVars says whether the command or any arg has a variable or a -// leading ~. +// cmdOS is the system magpie and the agents it writes for (WSL's aside) +// run on; a var for tests. +var cmdOS = runtime.GOOS + +// varOf is the name a cmdVar match names, and whether it is %NAME%. +func varOf(m []string) (string, bool) { + if m[3] != "" { + return m[3], true + } + return m[1] + m[2], false +} + +// homeVar says whether a variable is the home: HOME or USERPROFILE, in +// either case as %NAME%, which Windows reads without one. +func homeVar(n string, pct bool) bool { + if pct { + return strings.EqualFold(n, "HOME") || strings.EqualFold(n, "USERPROFILE") + } + return n == "HOME" || n == "USERPROFILE" +} + +// hasCmdVars says whether the command, an arg or a value of its +// environment has a variable or a leading ~ to put in. func hasCmdVars(s *Server) bool { for _, v := range append([]string{s.Command}, s.Args...) { if cmdVar.MatchString(v) || tildeRest(v) != "" || v == "~" { return true } } + return hasHomeEnv(s.Env) +} + +// envHome is a home in a value of a command's environment: %USERPROFILE% +// or %HOME%, as cmd.exe writes it. +var envHome = lazyre.New(`(?i)%(?:USERPROFILE|HOME)%`) + +// hasHomeEnv says whether a value of env names the home as homeEnv puts +// it in. +func hasHomeEnv(env map[string]string) bool { + for _, v := range env { + if v == "~" || tildeRest(v) != "" || envHome.MatchString(v) { + return true + } + } return false } +// homeEnv is env with a leading ~ and each %USERPROFILE% or %HOME% in its +// values put in as home; env itself when it has none, or no home is known. +func homeEnv(env map[string]string, home string) map[string]string { + if home == "" || !hasHomeEnv(env) { + return env + } + out := make(map[string]string, len(env)) + for k, v := range env { + out[k] = envHome.ReplaceAllLiteralString(homeOf(home, v), home) + } + return out +} + // tildeRest is what follows a leading ~/ (or ~\), with its slash; "" for // a value with none. func tildeRest(v string) string { @@ -88,14 +150,30 @@ func (f *mcpFile) withCmdVars(s *Server) *Server { // the distro's variables aren't magpie's: only its HOME is known look = func(string) (string, bool) { return "", false } } + win := cmdOS == "windows" && !f.WSL + // the home as the agent reads it where it runs + hv := "HOME" + if win { + hv = "USERPROFILE" + } syntax := f.cmdRefs() put := func(v string) string { if syntax != refNone { - return toAgent(syntax, homeOf(h, cmdVar.ReplaceAllString(v, "$${$1$2}"))) + return toAgent(syntax, homeOf(h, cmdVar.ReplaceAllStringFunc(v, func(r string) string { + n, pct := varOf(cmdVar.FindStringSubmatch(r)) + switch { + case homeVar(n, pct): + return "${" + hv + "}" + case pct && !win: + return r + } + return "${" + n + "}" + }))) } - return expandCmd(v, h, look) + return expandCmd(v, h, win, look) } c := *s + c.Env = homeEnv(s.Env, h) c.Command = put(s.Command) if s.Args != nil { c.Args = make([]string, len(s.Args)) @@ -120,16 +198,19 @@ func homeOf(home, v string) string { return v } -// expandCmd is v with a leading ~ and each variable put in: HOME as home, -// any other as look has it; one it hasn't is left as written. -func expandCmd(v, home string, look func(string) (string, bool)) string { +// expandCmd is v with a leading ~ and each variable put in: HOME and +// USERPROFILE as home, any other as look has it, a %NAME% only on Windows +// (win); one it hasn't is left as written. +func expandCmd(v, home string, win bool, look func(string) (string, bool)) string { v = homeOf(home, v) return cmdVar.ReplaceAllStringFunc(v, func(r string) string { - m := cmdVar.FindStringSubmatch(r) - n := m[1] + m[2] - if n == "HOME" && home != "" { + n, pct := varOf(cmdVar.FindStringSubmatch(r)) + if homeVar(n, pct) && home != "" { return home } + if pct && !win { + return r + } if x, ok := look(n); ok { return x } @@ -148,20 +229,21 @@ func lookCmdVar(n string) (string, bool) { } // launchCmd is s's command and args as magpie starts it on this machine, -// or in distro (whose HOME is distroHome's): each ~ and variable put in. -func launchCmd(s *Server, distro string) (string, []string) { +// or in distro (whose HOME is distroHome's), and its environment's home +// (homeEnv): each ~ and variable put in. +func launchCmd(s *Server, distro string) (string, []string, map[string]string) { if !hasCmdVars(s) { - return s.Command, s.Args + return s.Command, s.Args, s.Env } - h, look := home(), lookCmdVar + h, look, win := home(), lookCmdVar, cmdOS == "windows" if distro != "" { - h, look = distroHome(distro), func(string) (string, bool) { return "", false } + h, look, win = distroHome(distro), func(string) (string, bool) { return "", false }, false } args := make([]string, len(s.Args)) for i, a := range s.Args { - args[i] = expandCmd(a, h, look) + args[i] = expandCmd(a, h, win, look) } - return expandCmd(s.Command, h, look), args + return expandCmd(s.Command, h, win, look), args, homeEnv(s.Env, h) } var homes struct { diff --git a/internal/library/cmdvars_test.go b/internal/library/cmdvars_test.go index a12bec08a..1456f787c 100644 --- a/internal/library/cmdvars_test.go +++ b/internal/library/cmdvars_test.go @@ -2,8 +2,10 @@ package library import ( "context" + "maps" "os" "path/filepath" + "runtime" "slices" "strings" "testing" @@ -21,7 +23,11 @@ func TestCmdVarsPerAgent(t *testing.T) { os.Unsetenv("MAGPIE_T_UNSET") lv := loginVars loginVars = func([]string) map[string]string { return nil } - t.Cleanup(func() { loginVars = lv }) + // the home's variable as on a Mac or Linux (Windows': + // TestCmdVarsUserProfile) + was := cmdOS + cmdOS = "linux" + t.Cleanup(func() { loginVars, cmdOS = lv, was }) s := &Server{Name: "x", Transport: "stdio", Command: "$HOME/bin/x", Args: []string{"--notes", "~/notes", "${MAGPIE_T_SET}", "$MAGPIE_T_UNSET", "$1", "a~/b", "~"}} @@ -70,8 +76,8 @@ func TestCmdVarsPerAgent(t *testing.T) { } // The library keeps $HOME/bin/x as written; Claude Code's file has -// ${HOME}/bin/x, Codex's this home's path, and a second sync rewrites -// neither. +// ${HOME}/bin/x (${USERPROFILE}/bin/x on Windows), Codex's this home's +// path, and a second sync rewrites neither. func TestCmdVarsSync(t *testing.T) { h := sandbox(t) s := Server{Name: "mine", Transport: "stdio", Command: "$HOME/bin/x", Args: []string{"~/notes"}, @@ -87,7 +93,11 @@ func TestCmdVarsSync(t *testing.T) { t.Errorf("the library has %+v", got) } claude := read(t, filepath.Join(h, ".claude.json")) - if !strings.Contains(claude, `"${HOME}/bin/x"`) || !strings.Contains(claude, filepath.ToSlash(h)+`/notes"`) && !strings.Contains(claude, strings.ReplaceAll(h, `\`, `\\`)+`/notes"`) { + hv := `"${HOME}/bin/x"` + if runtime.GOOS == "windows" { + hv = `"${USERPROFILE}/bin/x"` + } + if !strings.Contains(claude, hv) || !strings.Contains(claude, filepath.ToSlash(h)+`/notes"`) && !strings.Contains(claude, strings.ReplaceAll(h, `\`, `\\`)+`/notes"`) { t.Errorf("claude:\n%s", claude) } codex := read(t, filepath.Join(h, ".codex/config.toml")) @@ -135,3 +145,99 @@ func TestCmdVarsLaunch(t *testing.T) { t.Errorf("spec: %+v", spec) } } + +// 0xBCD18E on X: %USERPROFILE%\AppData\…\pinky.exe in the library, on +// computers whose users have different names. HOME and USERPROFILE are the +// home on every system, in each syntax; an agent that reads references is +// given the home's own variable where it runs; any other %NAME% is a +// variable on Windows only; a command's environment gets its home put in. +func TestCmdVarsUserProfile(t *testing.T) { + h := t.TempDir() + t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) + t.Setenv("MAGPIE_T_AD", `C:\AD`) + t.Setenv("Y", "set") + lv := loginVars + loginVars = func([]string) map[string]string { return nil } + t.Setenv("TOKEN", "tk") + was := cmdOS + t.Cleanup(func() { loginVars, cmdOS = lv, was }) + + s := &Server{Name: "pinky", Transport: "stdio", Command: `%USERPROFILE%\AppData\Local\Programs\Pinky\pinky.exe`, + Args: []string{`~\x`, "$USERPROFILE/y", `%MAGPIE_T_AD%\z`, "%userprofile%", "%Y%", "100%", "%20"}, + Env: map[string]string{"CFG": `%USERPROFILE%\c`, "D": "~/d", "T": "${TOKEN}", "P": "50%"}} + env := map[string]string{"CFG": h + `\c`, "D": h + "/d", "T": "${TOKEN}", "P": "50%"} + for _, c := range []struct { + os, name string + f mcpFile + want []string + }{ + {"windows", "codex", mcpFile{Format: fmtCodex}, + []string{h + `\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, h + "/y", `C:\AD\z`, h, "set", "100%", "%20"}}, + {"windows", "claude", mcpFile{Format: fmtClaude}, + []string{`${USERPROFILE}\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, "${USERPROFILE}/y", `${MAGPIE_T_AD}\z`, "${USERPROFILE}", "${Y}", "100%", "%20"}}, + {"windows", "cursor", mcpFile{Format: fmtCursor}, + []string{`${env:USERPROFILE}\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, "${env:USERPROFILE}/y", `${env:MAGPIE_T_AD}\z`, "${env:USERPROFILE}", "${env:Y}", "100%", "%20"}}, + {"darwin", "codex", mcpFile{Format: fmtCodex}, + []string{h + `\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, h + "/y", `%MAGPIE_T_AD%\z`, h, "%Y%", "100%", "%20"}}, + {"darwin", "claude", mcpFile{Format: fmtClaude}, + []string{`${HOME}\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, "${HOME}/y", `%MAGPIE_T_AD%\z`, "${HOME}", "%Y%", "100%", "%20"}}, + {"linux", "opencode", mcpFile{Format: fmtOpenCode}, + []string{`{env:HOME}\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, "{env:HOME}/y", `%MAGPIE_T_AD%\z`, "{env:HOME}", "%Y%", "100%", "%20"}}, + {"linux", "codex", mcpFile{Format: fmtCodex}, + []string{h + `\AppData\Local\Programs\Pinky\pinky.exe`, h + `\x`, h + "/y", `%MAGPIE_T_AD%\z`, h, "%Y%", "100%", "%20"}}, + // an agent in WSL, from Windows: the distro's HOME, no variable of + // Windows' + {"windows", "claude in WSL", mcpFile{Format: fmtClaude, WSL: true, Home: "/home/me"}, + []string{`${HOME}\AppData\Local\Programs\Pinky\pinky.exe`, `/home/me\x`, "${HOME}/y", `%MAGPIE_T_AD%\z`, "${HOME}", "%Y%", "100%", "%20"}}, + } { + t.Run(c.os+" "+c.name, func(t *testing.T) { + cmdOS = c.os + got := c.f.withCmdVars(s) + if have := append([]string{got.Command}, got.Args...); !slices.Equal(have, c.want) { + t.Errorf("got %q\nwant %q", have, c.want) + } + want := env + if c.f.WSL { + want = map[string]string{"CFG": `/home/me\c`, "D": "/home/me/d", "T": "${TOKEN}", "P": "50%"} + } + if !maps.Equal(got.Env, want) { + t.Errorf("env %q, want %q", got.Env, want) + } + }) + } + if s.Command != `%USERPROFILE%\AppData\Local\Programs\Pinky\pinky.exe` || s.Args[0] != `~\x` || s.Env["CFG"] != `%USERPROFILE%\c` { + t.Errorf("the library's server was changed: %+v", s) + } + cmdOS = was + // magpie starting it: the home's variables are this home on every + // system + spec, ok := specOf(s) + if !ok || !strings.HasPrefix(spec.Command, h+`\AppData`) || spec.Args[1] != h+"/y" || spec.Args[3] != h || spec.Env["CFG"] != h+`\c` || spec.Env["D"] != h+"/d" { + t.Errorf("spec: %+v", spec) + } +} + +// The reporter's server: %USERPROFILE% then the program, started by the +// check (and so the router) on this system. +func TestCmdVarsUserProfileLaunch(t *testing.T) { + fake := fakeStdio(t, "ok", nil) + base := filepath.Base(fake.Command) + h := t.TempDir() + b, err := os.ReadFile(fake.Command) + if err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(h, base), b, 0o755); err != nil { + t.Fatal(err) + } + t.Setenv("HOME", h) + t.Setenv("USERPROFILE", h) + for _, c := range []string{"%USERPROFILE%" + string(filepath.Separator) + base, "%HOME%/" + base, "$USERPROFILE/" + base} { + s := *fake + s.Command = c + if got := CheckServer(context.Background(), &s); got.State != "ok" || got.Tools != 3 { + t.Errorf("%s: %+v", c, got) + } + } +} diff --git a/internal/library/mcp_check.go b/internal/library/mcp_check.go index 69a7520f4..c4cddc4c5 100644 --- a/internal/library/mcp_check.go +++ b/internal/library/mcp_check.go @@ -551,11 +551,11 @@ func startServer(ctx context.Context, s *Server, distro, dir string) (tree *proc fail := func(h ServerHealth) (*proc.Tree, io.WriteCloser, io.ReadCloser, *tail, func(), *ServerHealth) { return nil, nil, nil, nil, nil, &h } - env, unset := expandAll(s.Env) + command, args, own := launchCmd(s, distro) + env, unset := expandAll(own) if len(unset) > 0 { return fail(failed("novar", strings.Join(unset, ", "))) } - command, args := launchCmd(s, distro) var cmd *exec.Cmd var t wslrun.Tool stop = func() {} diff --git a/internal/library/mcp_run.go b/internal/library/mcp_run.go index a6ba7eff8..109626a05 100644 --- a/internal/library/mcp_run.go +++ b/internal/library/mcp_run.go @@ -64,11 +64,11 @@ func specOf(s *Server) (runSpec, bool) { if s.Remote() || s.Command == "" { return runSpec{}, false } - env, unset := expandAll(s.Env) + cmd, args, own := launchCmd(s, "") + env, unset := expandAll(own) if len(unset) > 0 { return runSpec{}, false } - cmd, args := launchCmd(s, "") return runSpec{Command: cmd, Args: slices.Clone(args), Env: env}, true }