Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: MCP entries holding app keys refused, env-only servers

ogsamrat72e25adf9e2b
diff --git a/apps/server/src/computer-use/desktop.test.ts b/apps/server/src/computer-use/desktop.test.ts
index a5933e0a..d677a6d4 100644
--- a/apps/server/src/computer-use/desktop.test.ts
+++ b/apps/server/src/computer-use/desktop.test.ts
@@ -95,6 +95,10 @@ describe("engine MCP plugin", () => {
expect(Object.keys(mcp)).toEqual(["computer-use"]);
expect(mcp["computer-use"]?.command).toEqual([process.execPath, "/x/relay.mjs", "/x/c.json"]);
expect(Object.entries(config.permission as Record<string, string>).at(-1)).toEqual(["computer-use_*", "allow"]);
+ // The built-in server gets the allowlist's environment too: the engine's tokens empty for it, its own kept.
+ const builtinEnv = (config.mcp as Record<string, { environment: Record<string, string> }>)["computer-use"]!.environment;
+ expect(builtinEnv.OMNIRUSH_COMPUTER_USE_COMMAND).toBe("");
+ expect(builtinEnv.OMNIRUSH_MCP_REPORT_DIR).toBe("");
const agents = config.agent as Record<string, { permission: Record<string, string> }>;
for (const name of ["general", "explore", "custom"]) expect(agents[name]?.permission["computer-use_*"]).toBe("deny");
const report = JSON.parse(readFileSync(path.join(reports, readdirName(reports)), "utf8")) as { decisions: Array<{ name: string; code: string }> };
diff --git a/apps/server/src/managed-opencode-v2.ts b/apps/server/src/managed-opencode-v2.ts
index bf309a39..c1e3d412 100644
--- a/apps/server/src/managed-opencode-v2.ts
+++ b/apps/server/src/managed-opencode-v2.ts
@@ -127,6 +127,10 @@ export async function createManagedOpencodeV2Server(
OPENCODE_CONFIG_DIR: configDir,
// No session sharing to an outside share service.
OPENCODE_DISABLE_SHARE: "1",
+ // A project's own config files are not read: this engine has no MCP filter, and it starts a project's
+ // MCP servers (with this environment, the password included) as soon as it opens the folder.
+ OPENCODE_DISABLE_PROJECT_CONFIG: "1",
+ OPENCODE_CONFIG_PROJECT_DISABLE: "1",
OPENCODE_AUTO_SHARE: "false",
...(opencodeModelsUrl === undefined ? {} : { OPENCODE_MODELS_URL: opencodeModelsUrl }),
...(disableModelsFetch === undefined ? {} : { OPENCODE_DISABLE_MODELS_FETCH: disableModelsFetch }),
diff --git a/apps/server/src/managed-opencode.test.ts b/apps/server/src/managed-opencode.test.ts
index 7a78e659..c25ad612 100644
--- a/apps/server/src/managed-opencode.test.ts
+++ b/apps/server/src/managed-opencode.test.ts
@@ -51,6 +51,22 @@ describe("managed OpenCode startup", () => {
} finally { await managed.close(); }
});
+ test("the next engine reads no project config (it would start a project's MCP servers unfiltered)", async () => {
+ const root = await createRoot();
+ const bin = await writeExecutable(root, "project-config-env.mjs", [
+ "const server = Bun.serve({ hostname: '127.0.0.1', port: 0, fetch(request) {",
+ " if (new URL(request.url).pathname === '/env') return Response.json({ a: process.env.OPENCODE_DISABLE_PROJECT_CONFIG ?? null, b: process.env.OPENCODE_CONFIG_PROJECT_DISABLE ?? null });",
+ " return Response.json({ healthy: true, version: 'test', pid: process.pid });",
+ "} });",
+ "console.log(`opencode server listening on http://127.0.0.1:${server.port}`);",
+ "process.on('SIGTERM', () => { server.stop(true); process.exit(0); });",
+ ]);
+ const managed = await createManagedOpencodeV2Server({ bin, rootDir: root, env: {} });
+ try {
+ expect(await managed.fetchJson("/env")).toEqual({ status: 200, json: { a: "1", b: "1" } });
+ } finally { await managed.close(); }
+ });
+
test("passes the model-catalog fetch switch to the next engine", async () => {
const root = await createRoot();
const bin = await writeExecutable(root, "catalog-env.mjs", [
diff --git a/apps/server/src/mcp-allow/PARITY.sha256 b/apps/server/src/mcp-allow/PARITY.sha256
index ac89cdff..909b3113 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.
-c1af272ae82090c87413d425d9f777bae8674e529e16c6fff8d893b43a07af7b mcp-allow.mjs
-3cd05cf4c762ef50667a2539f8fc8d8dffadc75ca9fd963cdb20cc32ea457dc3 mcp-allow.d.mts
+bad379b4cf7987cf858c6b557567c0ecdac199c7c65e681be7346a17657e1440 mcp-allow.mjs
+fe81f4d8eb0360fe47a086f59dace916f5138713073df7b1ffda7bf0dc846591 mcp-allow.d.mts
diff --git a/apps/server/src/mcp-allow/mcp-allow.d.mts b/apps/server/src/mcp-allow/mcp-allow.d.mts
index a2f45dfe..b0a68c1f 100644
--- a/apps/server/src/mcp-allow/mcp-allow.d.mts
+++ b/apps/server/src/mcp-allow/mcp-allow.d.mts
@@ -8,7 +8,7 @@ export const MCP_REASONS: Record<McpDecisionCode, string>;
export type McpRuntime = "npm" | "pypi" | "remote";
export type McpDecisionCode =
| "allowed" | "disabled" | "remote" | "unknown_command" | "not_allowed" | "denied"
- | "version" | "outside_project" | "missing_flag" | "missing_arg" | "flag" | "duplicate" | "invalid" | "runner_missing" | "secret_missing" | "remote_settings";
+ | "version" | "outside_project" | "missing_flag" | "missing_arg" | "flag" | "duplicate" | "invalid" | "runner_missing" | "secret_missing" | "remote_settings" | "protected_value";
export type McpRules = {
path_args?: "positional";
@@ -116,11 +116,15 @@ export function shellQuote(word: string): string;
/** The engine variables allowed through to a local MCP server (the rest are set empty for it). */
export const MCP_ENV_ALLOW: readonly string[];
/** The `environment` a local MCP server gets: `own`, every other engine variable empty except the basics and `keep`. */
-export function mcpServerEnvironment(engineEnv: Record<string, string | undefined> | undefined, own?: Record<string, string>, keep?: string[], platform?: string): Record<string, string>;
+export function mcpServerEnvironment(engineEnv: Record<string, string | undefined> | undefined, own?: Record<string, string>, keep?: string[], platform?: string, options?: { envOnly?: boolean }): Record<string, string>;
+export const MCP_ENV_ONLY_MARK: unique symbol;
+export const MCP_ENV_VALUES_MARK: unique symbol;
+export function engineStartsServersEnvOnly(): boolean;
+export function protectedValues(engineEnv: Record<string, string | undefined> | undefined): string[];
export function evaluateMcp(
mcpMap: unknown,
policy: McpPolicy | null,
- ctx?: { root?: string; platform?: string; box?: McpBox | null; npmPrefix?: string; resolveRunner?: (runner: string, options: { root: string; platform: string; accept?: (file: string) => boolean }) => string | null; exists?: (file: string) => boolean; env?: Record<string, string | undefined> },
+ ctx?: { root?: string; platform?: string; box?: McpBox | null; npmPrefix?: string; resolveRunner?: (runner: string, options: { root: string; platform: string; accept?: (file: string) => boolean }) => string | null; exists?: (file: string) => boolean; env?: Record<string, string | undefined>; envOnly?: boolean },
): { mcp: Record<string, Record<string, unknown>>; decisions: McpDecision[] };
export function toolPrefix(name: string): string;
export function mcpPermissionRules(decisions: McpDecision[] | null | undefined, mode: unknown): Record<string, "allow" | "ask">;
@@ -136,6 +140,7 @@ export function readReport(dir: string, root: string): McpReport | null;
export function describeDecision(d: McpDecision): string;
export function createMcpPolicyHooks(options?: {
directory?: string;
+ envOnly?: boolean;
policyFile?: string | null;
reportDir?: string | null;
box?: McpBox | null | ((root: string) => McpBox | null);
diff --git a/apps/server/src/mcp-allow/mcp-allow.mjs b/apps/server/src/mcp-allow/mcp-allow.mjs
index 853f6946..b2ec43d0 100644
--- a/apps/server/src/mcp-allow/mcp-allow.mjs
+++ b/apps/server/src/mcp-allow/mcp-allow.mjs
@@ -55,6 +55,7 @@ export const MCP_REASONS = {
runner_missing: "npx or uvx was not found on this computer outside the project folder, so the server does not start.",
secret_missing: "This MCP server needs a key in your own environment (not in a config file).",
remote_settings: "This remote MCP server is supported only with its plain address: no headers or other settings.",
+ protected_value: "This MCP server entry holds one of the app's own keys (in its command, variables or folder), so it does not start.",
};
const ID = /^[a-z0-9][a-z0-9-]{0,39}$/;
@@ -164,14 +165,72 @@ const MCP_ENV_GIT_CREDENTIAL = /^GIT_(?:ASKPASS$|CREDENTIAL|HTTP_EXTRAHEADER|CON
const MCP_ENV_NEVER = /^(?:OMNIRUSH_|OPENCODE_SERVER_|OPENCODE_PASSWORD$)/i;
/**
- * The `environment` a local MCP server gets from the app: `own` (its
- * path_env / fixed_env values), every other variable of `engineEnv` set empty
- * (the engine merges its own environment under it), except the allowed
- * basics (MCP_ENV_ALLOW) and the keys in `keep` (the server's secret_env).
+ * The engine sets MCP_ENV_ONLY_MARK (on globalThis) when it can start a filtered server with only its basics
+ * plus the server's `environment`; the filter then gives each server the values it needs (envOnly) and marks
+ * the config with MCP_ENV_VALUES_MARK, and only then does the engine leave the rest of its environment out.
+ * Either side alone keeps the older way (the whole environment, the other variables emptied).
*/
-export function mcpServerEnvironment(engineEnv, own = {}, keep = [], platform = process.platform) {
+export const MCP_ENV_ONLY_MARK = Symbol.for("omnirush.mcp.envOnly");
+export const MCP_ENV_VALUES_MARK = Symbol.for("omnirush.mcp.envValues");
+
+/** Whether this engine starts a filtered server without the rest of its own environment (set by the engine). */
+export function engineStartsServersEnvOnly() {
+ return globalThis[MCP_ENV_ONLY_MARK] === true;
+}
+
+function allowedName(key) {
+ const upper = key.toUpperCase();
+ return (MCP_ENV_ALLOW_UPPER.has(upper) || (MCP_ENV_ALLOW_PREFIX.test(key) && !MCP_ENV_GIT_CREDENTIAL.test(key))) && !MCP_ENV_NEVER.test(key);
+}
+const MCP_ENV_ALLOW_UPPER = new Set(MCP_ENV_ALLOW.map((k) => k.toUpperCase()));
+
+// The engine's values a server's entry must not hold anywhere (its command, variables or folder): the app's
+// tokens and the engine's password, from 8 characters on. A project config could copy them in ({env:...}).
+const PROTECTED_VALUE_NAME = /^(?:OPENCODE_SERVER_|OPENCODE_PASSWORD$)|^OMNIRUSH_.*(?:TOKEN|SECRET|PASSWORD|PASSWD|KEY|AUTH|CREDENTIAL|COOKIE|SESSION)/i;
+export function protectedValues(engineEnv) {
+ return [...new Set(Object.entries(engineEnv ?? {})
+ .filter(([k, v]) => typeof v === "string" && v.length >= 8 && PROTECTED_VALUE_NAME.test(k))
+ .map(([, v]) => v))];
+}
+
+function holdsProtected(raw, values) {
+ if (!values.length) return false;
+ const words = [
+ ...(Array.isArray(raw.command) ? raw.command : []),
+ ...(isRecord(raw.environment) ? Object.entries(raw.environment).flat() : []),
+ raw.cwd,
+ raw.url,
+ ].filter((w) => typeof w === "string");
+ return words.some((w) => values.some((v) => w.includes(v)));
+}
+
+/**
+ * The `environment` a local MCP server gets from the app. `own`: its
+ * path_env / fixed_env values; `keep`: the keys its rules name (secret_env).
+ * `envOnly` (the engine starts the server with its basics plus this, nothing
+ * else of its own environment): the allowed basics (MCP_ENV_ALLOW) and the
+ * kept keys with their values, then `own`; nothing empty. Otherwise (the
+ * engine merges its whole environment under this): every other variable the
+ * engine has is set empty.
+ */
+export function mcpServerEnvironment(engineEnv, own = {}, keep = [], platform = process.platform, { envOnly = false } = {}) {
+ if (envOnly) {
+ const norm = (k) => (platform === "win32" ? k.toUpperCase() : k);
+ 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, value] of Object.entries(engineEnv ?? {})) {
+ if (typeof value !== "string" || value === "" || ownKeys.has(norm(key))) continue;
+ if (allowedName(key) || kept.has(norm(key))) out[key] = value;
+ }
+ for (const [key, value] of Object.entries(own)) if (!MCP_ENV_NEVER.test(key) && typeof value === "string") out[key] = value;
+ return out;
+ }
+ return blankedEnvironment(engineEnv, own, keep, platform);
+}
+
+function blankedEnvironment(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 = {};
@@ -180,13 +239,15 @@ export function mcpServerEnvironment(engineEnv, own = {}, keep = [], platform =
// 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_GIT_CREDENTIAL.test(key))) && !MCP_ENV_NEVER.test(key);
- if (basic || kept.has(norm(key))) continue;
+ if (allowedName(key) || kept.has(norm(key))) continue;
out[key] = "";
}
- // A name the app keeps from every server is empty even when the server's own variables name it.
- for (const [key, value] of Object.entries(own)) out[key] = MCP_ENV_NEVER.test(key) ? "" : value;
+ // A name the app keeps from every server is empty even when the server's own variables name it (and left
+ // out when the engine does not have it).
+ for (const [key, value] of Object.entries(own)) {
+ if (!MCP_ENV_NEVER.test(key)) out[key] = value;
+ else if (typeof engineEnv?.[key] === "string" && engineEnv[key] !== "") out[key] = "";
+ }
return out;
}
@@ -581,12 +642,15 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {
const root = ctx.root || process.cwd();
const platform = ctx.platform || process.platform;
const box = ctx.box && typeof ctx.box.shell === "string" && typeof ctx.box.key === "string" ? ctx.box : null;
+ const envOnly = ctx.envOnly ?? engineStartsServersEnvOnly();
+ const secretsHere = protectedValues(ctx.env ?? process.env);
const out = {};
const decisions = [];
const entries = isRecord(mcpMap) ? Object.entries(mcpMap) : [];
for (const [name, raw] of entries) {
if (!isRecord(raw)) { decisions.push(blocked(name, "invalid")); continue; }
if (!policy || !policy.enabled) { decisions.push(blocked(name, "disabled", policy?.message ? { reason: policy.message } : {})); continue; }
+ if (holdsProtected(raw, secretsHere)) { decisions.push(blocked(name, "protected_value")); continue; }
if (raw.type === "remote" || typeof raw.url === "string") {
const url = normalizeRemoteUrl(raw.url);
const remote = url ? policy.allow.find((e) => e.runtime === "remote" && e.url === url) : null;
@@ -764,12 +828,12 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {
// The box shell needs its key; the engine's other variables are empty for it (mcpServerEnvironment).
// Its own settings (OMNIRUSH_BOX_HOME and the like: where the box lives, not a credential) stay too.
const boxVars = Object.fromEntries(Object.entries(userEnv).filter(([k, v]) => /^OMNIRUSH_BOX_/i.test(k) && typeof v === "string"));
- next.environment = { ...mcpServerEnvironment(userEnv, {}, [], platform), ...boxVars, OMNIRUSH_BOX_KEY: box.key };
+ next.environment = { ...mcpServerEnvironment(userEnv, {}, [], platform, { envOnly }), ...boxVars, OMNIRUSH_BOX_KEY: box.key };
notes.push("runs in the sandbox");
} else {
next.command = argv;
// The engine's tokens and the person's other keys never reach the server (mcpServerEnvironment).
- next.environment = mcpServerEnvironment(userEnv, environment, secretNames, platform);
+ next.environment = mcpServerEnvironment(userEnv, environment, secretNames, platform, { envOnly });
if (!Object.keys(next.environment).length) delete next.environment;
}
if (secretNames.length) notes.push(`uses ${secretNames[0]} from your environment`);
@@ -945,10 +1009,11 @@ export function describeDecision(d) {
*/
export const MCP_FILTERED_MARK = Symbol.for("omnirush.mcp.filtered");
-function markFiltered(...configs) {
+function markFiltered(envValues, ...configs) {
for (const config of configs) {
if (isRecord(config)) {
try { Object.defineProperty(config, MCP_FILTERED_MARK, { value: true, enumerable: false, configurable: true }); } catch { /* frozen */ }
+ try { Object.defineProperty(config, MCP_ENV_VALUES_MARK, { value: envValues, enumerable: false, configurable: true }); } catch { /* frozen */ }
}
}
}
@@ -971,6 +1036,7 @@ function configTarget(input, output) {
export function createMcpPolicyHooks(options = {}) {
const root = path.resolve(options.directory || process.cwd());
const state = { localOnly: [], pathInputs: [], roots: [] };
+ const envOnly = () => (typeof options.envOnly === "boolean" ? options.envOnly : engineStartsServersEnvOnly());
const apply = (input, output) => {
const target = configTarget(input, output);
if (!target) return;
@@ -980,7 +1046,7 @@ export function createMcpPolicyHooks(options = {}) {
if (!box) {
try { mkdirSync(npmPrefix, { recursive: true }); } catch { /* npx makes it */ }
}
- const { mcp, decisions } = evaluateMcp(target.mcp, policy, { root, platform: options.platform, box, npmPrefix, ...(options.resolveRunner ? { resolveRunner: options.resolveRunner } : {}) });
+ const { mcp, decisions } = evaluateMcp(target.mcp, policy, { root, platform: options.platform, box, npmPrefix, envOnly: envOnly(), ...(options.resolveRunner ? { resolveRunner: options.resolveRunner } : {}) });
target.mcp = mcp;
const mode = typeof options.permissionMode === "function" ? options.permissionMode() : options.permissionMode ?? process.env.OMNIRUSH_PERMISSION_MODE;
const rules = mcpPermissionRules(decisions, mode);
@@ -1004,14 +1070,14 @@ export function createMcpPolicyHooks(options = {}) {
config: async (input, output) => {
try {
apply(input, output);
- markFiltered(input, output);
+ markFiltered(envOnly(), input, output);
} catch {
// Never leave the engine's own list in place: no servers at all.
const target = configTarget(input, output);
if (target) target.mcp = {};
state.localOnly = [];
state.pathInputs = [];
- markFiltered(input, output);
+ markFiltered(false, input, output);
}
},
"tool.execute.before": async (input, output) => {
diff --git a/apps/server/src/mcp-allow/state.test.ts b/apps/server/src/mcp-allow/state.test.ts
index 647272bb..2ceda988 100644
--- a/apps/server/src/mcp-allow/state.test.ts
+++ b/apps/server/src/mcp-allow/state.test.ts
@@ -296,6 +296,39 @@ describe("MCP server environment", () => {
expect(mcpServerEnvironment({ memory_file_path: "C:\\other" }, { MEMORY_FILE_PATH: "C:\\work\\m" }, [], "win32")).toEqual({ MEMORY_FILE_PATH: "C:\\work\\m" });
});
+ test("env-only engine: a server gets the allowed values, nothing empty, and no app value even when set later", () => {
+ const policy = normalizePolicy(policyFixture);
+ const engineEnv: Record<string, string> = { PATH: "/usr/bin", HOME: "/home/u", DISPLAY: ":0", HTTPS_PROXY: "http://proxy:3128", OMNIRUSH_ACCESS_TOKEN: "acc-0123456789", OPENCODE_SERVER_PASSWORD: "pw-0123456789", AWS_SECRET_ACCESS_KEY: "aws-0123456789" };
+ const base = (env: Record<string, string>) => Object.fromEntries(Object.entries(env).filter(([k]) => /^(?:PATH|HOME|TMPDIR|LANG|LC_\w+|XDG_\w+)$/i.test(k)));
+ for (const envOnly of [false, true]) {
+ const { mcp } = evaluateMcp({ filesystem: { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "."] } }, policy,
+ { root: "/work/app", platform: "linux", npmPrefix: "/state/npx", resolveRunner: (runner: string) => runner, env: engineEnv, envOnly });
+ const environment = (mcp as Record<string, { environment?: Record<string, string> }>).filesystem!.environment ?? {};
+ if (envOnly) expect(Object.values(environment)).not.toContain("");
+ const later = { ...engineEnv, OMNIRUSH_LATE_TOKEN: "late-0123456789" };
+ const spawned = envOnly ? { ...base(later), ...environment } : { ...later, ...environment };
+ for (const secret of ["acc-0123456789", "pw-0123456789", "aws-0123456789", ...(envOnly ? ["late-0123456789"] : [])]) expect(Object.values(spawned)).not.toContain(secret);
+ expect(spawned).toMatchObject({ PATH: "/usr/bin", HOME: "/home/u", DISPLAY: ":0", HTTPS_PROXY: "http://proxy:3128" });
+ }
+ });
+
+ test("an entry holding one of the app's values (args, variables, folder) does not start", () => {
+ const policy = normalizePolicy(policyFixture);
+ const env = { PATH: "/usr/bin", OMNIRUSH_ACCESS_TOKEN: "acc-0123456789", OPENCODE_SERVER_PASSWORD: "pw-0123456789", OMNIRUSH_PERMISSION_MODE: "careful" };
+ const ctx = { root: "/work/app", platform: "linux", npmPrefix: "/state/npx", resolveRunner: (runner: string) => runner, env };
+ for (const entry of [
+ { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "./acc-0123456789"] },
+ { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "."], environment: { X: "pw-0123456789" } },
+ { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "."], cwd: "pw-0123456789" },
+ ]) {
+ const { mcp, decisions } = evaluateMcp({ filesystem: entry }, policy, ctx);
+ expect(mcp).toEqual({});
+ expect(decisions[0]).toMatchObject({ status: "blocked", code: "protected_value" });
+ expect(JSON.stringify(decisions)).not.toContain("0123456789");
+ }
+ expect(evaluateMcp({ filesystem: { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "careful"] } }, policy, ctx).decisions[0]!.status).toBe("allowed");
+ });
+
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: "" });
diff --git a/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts b/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
index 51a98e3e..b732f782 100644
--- a/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
+++ b/apps/server/src/opencode-plugins/omnirush-mcp-policy.ts
@@ -17,7 +17,7 @@
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
import path from "node:path";
-import { createMcpPolicyHooks, reportPath, type McpBox } from "../mcp-allow/mcp-allow.mjs";
+import { createMcpPolicyHooks, engineStartsServersEnvOnly, mcpServerEnvironment, reportPath, type McpBox } from "../mcp-allow/mcp-allow.mjs";
import { readWorkspaceMcp } from "../mcp-allow/state.js";
import { computerUseBuiltins, COMPUTER_USE_DIR_ENV } from "../computer-use/desktop.js";
import { isComputerTool, SERVER_ID } from "../computer-use/shared/contract.mjs";
@@ -140,7 +140,11 @@ export default async function omnirushMcpPolicy(input?: { directory?: string; cl
if (reserved.length) reportReserved(root, reserved);
const builtin = target ? computerUseBuiltins(process.env[COMPUTER_USE_DIR_ENV])[SERVER_ID] : null;
if (target && builtin) {
- target.mcp = { ...(isRecord(target.mcp) ? target.mcp : {}), [SERVER_ID]: builtin };
+ // Like every server: the engine's tokens never reach it, only the variables the allowlist keeps plus
+ // the ones the app gives it.
+ const own = isRecord(builtin.environment) ? Object.fromEntries(Object.entries(builtin.environment).filter((entry): entry is [string, string] => typeof entry[1] === "string")) : {};
+ const environment = { ...mcpServerEnvironment(process.env, {}, [], process.platform, { envOnly: engineStartsServersEnvOnly() }), ...own };
+ target.mcp = { ...(isRecord(target.mcp) ? target.mcp : {}), [SERVER_ID]: { ...builtin, environment } };
// The host asks the person itself (never the engine's permission prompts), in every mode.
const permission: Record<string, unknown> = typeof target.permission === "string" ? { "*": target.permission } : isRecord(target.permission) ? { ...target.permission } : {};
delete permission[`${SERVER_ID}_*`];