Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: MCP servers keep display, git and registry settings

ogsamratfc882595965e
diff --git a/apps/server/src/mcp-allow/PARITY.sha256 b/apps/server/src/mcp-allow/PARITY.sha256
index e6a72dbe..587db842 100644
--- a/apps/server/src/mcp-allow/PARITY.sha256
+++ b/apps/server/src/mcp-allow/PARITY.sha256
@@ -1,4 +1,4 @@
# The MCP allowlist module: the same files in omnirush-cli (src/mcp/) and omnirush-gui (apps/server/src/mcp-allow/).
# A change to one must be ported to the other and this list updated in both.
-11ed03b69f22891a9cd9397123cdc8946b318e8c1ddb7042d4eae8989b628515 mcp-allow.mjs
+07210e6d093e3850a3e0515b0ffd6cffc253a0b64c24ee6771fb2465becb9f20 mcp-allow.mjs
3cd05cf4c762ef50667a2539f8fc8d8dffadc75ca9fd963cdb20cc32ea457dc3 mcp-allow.d.mts
diff --git a/apps/server/src/mcp-allow/mcp-allow.mjs b/apps/server/src/mcp-allow/mcp-allow.mjs
index 92590579..8ce695d0 100644
--- a/apps/server/src/mcp-allow/mcp-allow.mjs
+++ b/apps/server/src/mcp-allow/mcp-allow.mjs
@@ -136,7 +136,7 @@ export function validRange(range) {
// engine starts a server with its whole environment plus the entry's `environment`, so every other
// variable it has (the app's tokens, the engine's password, the person's other keys) is set empty for
// the server (mcpServerEnvironment). The server's own path_env / fixed_env and the key its rules name
-// (secret_env) are added on top.
+// (secret_env) are added on top. A name the engine does not have is never set, not even empty.
export const MCP_ENV_ALLOW = Object.freeze([
"PATH", "HOME", "USER", "LOGNAME", "SHELL", "TMPDIR", "TMP", "TEMP", "LANG", "LANGUAGE", "TZ", "TERM", "COLORTERM",
"SYSTEMROOT", "WINDIR", "COMSPEC", "PATHEXT", "USERPROFILE", "USERNAME", "USERDOMAIN", "APPDATA", "LOCALAPPDATA", "PROGRAMDATA",
@@ -148,8 +148,15 @@ export const MCP_ENV_ALLOW = Object.freeze([
"NODE_EXTRA_CA_CERTS", "SSL_CERT_FILE", "SSL_CERT_DIR", "REQUESTS_CA_BUNDLE",
"NPM_CONFIG_REGISTRY", "NPM_CONFIG_CAFILE", "NPM_CONFIG_PROXY", "NPM_CONFIG_HTTPS_PROXY", "NPM_CONFIG_NOPROXY", "NPM_CONFIG_STRICT_SSL",
"UV_INDEX_URL", "UV_DEFAULT_INDEX", "UV_NATIVE_TLS", "PIP_INDEX_URL",
+ "UV_INDEX", "UV_EXTRA_INDEX_URL", "UV_INSECURE_HOST", "CURL_CA_BUNDLE", "PIP_CERT", "NPM_CONFIG_USERCONFIG",
+ // The desktop session, so a server can open a window (a headed browser on Linux).
+ "DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS", "PLAYWRIGHT_BROWSERS_PATH",
]);
-const MCP_ENV_ALLOW_PREFIX = /^(?:LC_|XDG_)/i;
+// Locale, desktop folders, Volta and git's own settings (identity, config file, ssh, certificates).
+const MCP_ENV_ALLOW_PREFIX = /^(?:LC_|XDG_|VOLTA_|GIT_)/i;
+// Git settings that can carry a login or start a helper that hands one out (http.extraHeader through
+// GIT_CONFIG_*, an askpass or credential helper): empty for a server like every other variable.
+const MCP_ENV_GIT_CREDENTIAL = /^GIT_(?:ASKPASS$|CREDENTIAL|HTTP_EXTRAHEADER|CONFIG_PARAMETERS$|CONFIG_COUNT$|CONFIG_KEY_|CONFIG_VALUE_)|(?:^|_)(?:TOKEN|SECRET|PASSWORD|PASSWD|PASS|AUTH|CREDENTIALS?|ASKPASS|COOKIE|KEY)(?:_|$)/i;
// Never reaches a server, whatever its rules say.
const MCP_ENV_NEVER = /^(?:OMNIRUSH_|OPENCODE_SERVER_|OPENCODE_PASSWORD$)/i;
@@ -163,11 +170,15 @@ export function mcpServerEnvironment(engineEnv, own = {}, keep = [], platform =
const norm = (k) => (platform === "win32" ? k.toUpperCase() : k);
const allowed = new Set(MCP_ENV_ALLOW.map((k) => k.toUpperCase()));
const kept = new Set(keep.filter((k) => !MCP_ENV_NEVER.test(k)).map(norm));
+ const ownKeys = new Set(Object.keys(own).map(norm));
const out = {};
- for (const key of Object.keys(engineEnv ?? {})) {
- if (Object.hasOwn(own, key)) continue;
+ for (const [key, value] of Object.entries(engineEnv ?? {})) {
+ // Only a variable the engine has (set, not empty) is emptied: an empty one would change what a
+ // program does when it is not set at all (git's identity, Volta's home).
+ if (typeof value !== "string" || value === "") continue;
+ if (ownKeys.has(norm(key))) continue;
const upper = key.toUpperCase();
- const basic = (allowed.has(upper) || MCP_ENV_ALLOW_PREFIX.test(key)) && !MCP_ENV_NEVER.test(key);
+ const basic = (allowed.has(upper) || (MCP_ENV_ALLOW_PREFIX.test(key) && !MCP_ENV_GIT_CREDENTIAL.test(key))) && !MCP_ENV_NEVER.test(key);
if (basic || kept.has(norm(key))) continue;
out[key] = "";
}
diff --git a/apps/server/src/mcp-allow/state.test.ts b/apps/server/src/mcp-allow/state.test.ts
index edc4bfa9..636fdd35 100644
--- a/apps/server/src/mcp-allow/state.test.ts
+++ b/apps/server/src/mcp-allow/state.test.ts
@@ -268,6 +268,23 @@ describe("MCP server environment", () => {
expect(environment).toMatchObject({ OMNIRUSH_BOX_HOME: "/custom/box-home", OMNIRUSH_BOX_TIMING_LOG: "/tmp/t.log", OMNIRUSH_BOX_KEY: "k1", OMNIRUSH_ACCESS_TOKEN: "" });
});
+ test("a server keeps the desktop session, git, Volta and registry settings; git logins and absent names are never set", () => {
+ const env: Record<string, string | undefined> = {
+ DISPLAY: ":99", WAYLAND_DISPLAY: "wayland-0", XAUTHORITY: "/home/u/.Xauthority", DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/1000/bus", PLAYWRIGHT_BROWSERS_PATH: "/p",
+ GIT_AUTHOR_NAME: "A", GIT_COMMITTER_EMAIL: "[email protected]", GIT_SSH_COMMAND: "ssh -i k", GIT_CONFIG_GLOBAL: "/g", GIT_SSL_CAINFO: "/ca", VOLTA_HOME: "/v",
+ UV_INDEX: "u", UV_EXTRA_INDEX_URL: "u", UV_INSECURE_HOST: "h", CURL_CA_BUNDLE: "/ca", PIP_CERT: "/ca", NPM_CONFIG_USERCONFIG: "/n",
+ GIT_ASKPASS: "/h", GIT_CONFIG_COUNT: "1", GIT_CONFIG_KEY_0: "http.extraHeader", GIT_CONFIG_VALUE_0: "Authorization: x", GIT_CONFIG_PARAMETERS: "x", GIT_HTTP_EXTRAHEADER: "x", GIT_CREDENTIAL_HELPER: "s", GIT_TOKEN: "x",
+ UV_PUBLISH_TOKEN: "x", OMNIRUSH_ACCESS_TOKEN: "t", OPENCODE_SERVER_PASSWORD: "p", EMPTY_ONE: "", UNSET_ONE: undefined,
+ };
+ const out = mcpServerEnvironment(env, {}, [], "linux");
+ expect(Object.keys(out).sort()).toEqual(["GIT_ASKPASS", "GIT_CONFIG_COUNT", "GIT_CONFIG_KEY_0", "GIT_CONFIG_PARAMETERS", "GIT_CONFIG_VALUE_0", "GIT_CREDENTIAL_HELPER", "GIT_HTTP_EXTRAHEADER", "GIT_TOKEN", "OMNIRUSH_ACCESS_TOKEN", "OPENCODE_SERVER_PASSWORD", "UV_PUBLISH_TOKEN"]);
+ expect(new Set(Object.values(out))).toEqual(new Set([""]));
+ });
+
+ test("Windows: a server's own variable wins over the engine's whatever the case", () => {
+ expect(mcpServerEnvironment({ memory_file_path: "C:\\other" }, { MEMORY_FILE_PATH: "C:\\work\\m" }, [], "win32")).toEqual({ MEMORY_FILE_PATH: "C:\\work\\m" });
+ });
+
test("Windows: mixed-case names are matched whatever their case", () => {
expect(mcpServerEnvironment({ Path: "C:\\Windows", SystemRoot: "C:\\Windows", Omnirush_Access_Token: "t", opencode_server_password: "p", Aws_Secret: "a" }, {}, [], "win32"))
.toEqual({ Omnirush_Access_Token: "", opencode_server_password: "", Aws_Secret: "" });