A desktop coding agent with free access to frontier models.
TypeScript
fix: no local MCP servers on an older engine
ogsamrat847d7b15fe97
diff --git a/apps/app/tests/mcp-supported-panel.test.tsx b/apps/app/tests/mcp-supported-panel.test.tsxindex e4768bd9..93a257e2 100644--- a/apps/app/tests/mcp-supported-panel.test.tsx+++ b/apps/app/tests/mcp-supported-panel.test.tsx@@ -132,6 +132,11 @@ describe("Settings > MCP: supported servers", () => {.toMatchObject({ hint: "Install Node.js (for npx) or uv (for uvx), then restart the app." });});+ test("a server that needs a newer engine says to update", () => {+ expect(mcpServerState(server("x"), { name: "x", status: "blocked", code: "engine_update", reason: "This MCP server needs a newer engine; update OmniRush to use it." }))+ .toEqual({ kind: "blocked", reason: "This MCP server needs a newer engine; update OmniRush to use it.", hint: null });+ });+test("helpers", () => {expect(presetCommandLine({ command: ["uvx", "mcp-server-git", "--repository", "my repo"] })).toBe("uvx mcp-server-git --repository 'my repo'");expect(presetConfigured(filesystem, [], [{ name: "files", status: "allowed", code: "allowed", id: "filesystem" }])).toBe(true);diff --git a/apps/server/src/mcp-allow/PARITY.sha256 b/apps/server/src/mcp-allow/PARITY.sha256index 721b26c6..c4106b0e 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.-dee394bcb7d3cc00312389c4a1a8a9901c085ecc4256f3b11a4d17b28eb62e7e mcp-allow.mjs-fe81f4d8eb0360fe47a086f59dace916f5138713073df7b1ffda7bf0dc846591 mcp-allow.d.mts+01427642a75de22e2f256b1ee8bc7f429892da4170a5b8e99cbd147344ea4ad9 mcp-allow.mjs+5682977fead83beaeae5a55c6350cbb99d9312aabbf61d41c10ffabe233e34df mcp-allow.d.mtsdiff --git a/apps/server/src/mcp-allow/mcp-allow.d.mts b/apps/server/src/mcp-allow/mcp-allow.d.mtsindex b0a68c1f..2632ca30 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" | "protected_value";+ | "version" | "outside_project" | "missing_flag" | "missing_arg" | "flag" | "duplicate" | "invalid" | "runner_missing" | "secret_missing" | "remote_settings" | "protected_value" | "engine_update";export type McpRules = {path_args?: "positional";@@ -83,7 +83,7 @@ export type McpDecision = {export type McpBox = { shell: string; key: string; croot?: string | null };export type McpIgnored = { kind: "plugin" | "lsp" | "formatter" | "provider"; name: string; source: string | null };-export type McpReport = { v: 1; root: string; at: number; enabled: boolean; decisions: McpDecision[]; ignored?: McpIgnored[] };+export type McpReport = { v: 1; root: string; at: number; enabled: boolean; decisions: McpDecision[]; ignored?: McpIgnored[]; filter_required?: boolean; env_only?: boolean };export type McpLaunch = {runtime: McpRuntime;@@ -120,11 +120,12 @@ export function mcpServerEnvironment(engineEnv: Record<string, string | undefineexport const MCP_ENV_ONLY_MARK: unique symbol;export const MCP_ENV_VALUES_MARK: unique symbol;export function engineStartsServersEnvOnly(): boolean;+export function localServersNeedNewerEngine(options?: { filterRequired?: boolean; envOnly?: boolean }): 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>; envOnly?: boolean },+ 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; filterRequired?: 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">;@@ -141,6 +142,7 @@ export function describeDecision(d: McpDecision): string;export function createMcpPolicyHooks(options?: {directory?: string;envOnly?: boolean;+ filterRequired?: 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.mjsindex 647a15f3..28ea04ec 100644--- a/apps/server/src/mcp-allow/mcp-allow.mjs+++ b/apps/server/src/mcp-allow/mcp-allow.mjs@@ -56,6 +56,7 @@ export const MCP_REASONS = {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.",+ engine_update: "This MCP server needs a newer engine; update OmniRush to use it.",};const ID = /^[a-z0-9][a-z0-9-]{0,39}$/;@@ -178,6 +179,16 @@ export function engineStartsServersEnvOnly() {return globalThis[MCP_ENV_ONLY_MARK] === true;}+/**+ * Whether no local server may start: the engine requires this filter (OMNIRUSH_MCP_FILTER=required) but does not+ * start servers env-only. Such an engine resolves a project's {file:...} and {env:...} values itself, so they could+ * reach a local server; remote servers are unaffected.+ */+export function localServersNeedNewerEngine({ filterRequired, envOnly } = {}) {+ const required = typeof filterRequired === "boolean" ? filterRequired : process.env.OMNIRUSH_MCP_FILTER === "required";+ return required && (typeof envOnly === "boolean" ? envOnly : engineStartsServersEnvOnly()) !== 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);@@ -645,6 +656,7 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {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 olderEngine = localServersNeedNewerEngine({ filterRequired: ctx.filterRequired, envOnly });const secretsHere = protectedValues(ctx.env ?? process.env);const out = {};const decisions = [];@@ -683,6 +695,7 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {decisions.push(blocked(name, reason ? "denied" : "unknown_command", reason ? { reason } : {}));continue;}+ if (olderEngine) { decisions.push(blocked(name, "engine_update", { package: launch.name })); continue; }const denied = denyReason(policy, launch.name);if (denied) { decisions.push(blocked(name, "denied", { reason: denied, package: launch.name })); continue; }const entry = policy.allow.find((e) => e.runtime !== "remote" && e.runtime === launch.runtime && e.package.toLowerCase() === launch.name);@@ -1039,6 +1052,7 @@ 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 filterRequired = () => (typeof options.filterRequired === "boolean" ? options.filterRequired : process.env.OMNIRUSH_MCP_FILTER === "required");const apply = (input, output) => {const target = configTarget(input, output);if (!target) return;@@ -1048,7 +1062,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, envOnly: envOnly(), ...(options.resolveRunner ? { resolveRunner: options.resolveRunner } : {}) });+ const { mcp, decisions } = evaluateMcp(target.mcp, policy, { root, platform: options.platform, box, npmPrefix, envOnly: envOnly(), filterRequired: filterRequired(), ...(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);@@ -1063,7 +1077,7 @@ export function createMcpPolicyHooks(options = {}) {const file = reportPath(options.reportDir, root);mkdirSync(options.reportDir, { recursive: true });const tmp = `${file}.${process.pid}.tmp`;- writeFileSync(tmp, JSON.stringify({ v: MCP_POLICY_FILE_VERSION, root, at: (options.now ?? Date.now)(), enabled: Boolean(policy?.enabled), decisions, ignored: projectCodeIgnored(target) }), { mode: 0o600 });+ writeFileSync(tmp, JSON.stringify({ v: MCP_POLICY_FILE_VERSION, root, at: (options.now ?? Date.now)(), enabled: Boolean(policy?.enabled), decisions, ignored: projectCodeIgnored(target), filter_required: filterRequired(), env_only: envOnly() }), { mode: 0o600 });renameSync(tmp, file);} catch { /* the report is for display only */ }}diff --git a/apps/server/src/mcp-allow/state.test.ts b/apps/server/src/mcp-allow/state.test.tsindex 2ceda988..1bf4ca33 100644--- a/apps/server/src/mcp-allow/state.test.ts+++ b/apps/server/src/mcp-allow/state.test.ts@@ -5,7 +5,7 @@ import path from "node:path";import omnirushMcpPolicy from "../opencode-plugins/omnirush-mcp-policy.js";import { keyOf } from "../box/plugin-lib.js";-import { describeIgnored, evaluateMcp, mcpServerEnvironment, normalizePolicy, readPolicyFile } from "./mcp-allow.mjs";+import { describeIgnored, evaluateMcp, MCP_ENV_ONLY_MARK, MCP_REASONS, mcpServerEnvironment, normalizePolicy, readPolicyFile } from "./mcp-allow.mjs";import {decideMcpEntry,mcpEngineEnv,@@ -29,7 +29,8 @@ function temp(prefix: string): string {afterEach(() => {for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });- for (const key of ["OMNIRUSH_MCP_POLICY_FILE", "OMNIRUSH_MCP_REPORT_DIR", "OMNIRUSH_MCP_WORKSPACE_DIR", "OMNIRUSH_BOX_HOME", "PATH"]) {+ delete (globalThis as Record<symbol, unknown>)[MCP_ENV_ONLY_MARK];+ for (const key of ["OMNIRUSH_MCP_POLICY_FILE", "OMNIRUSH_MCP_REPORT_DIR", "OMNIRUSH_MCP_WORKSPACE_DIR", "OMNIRUSH_BOX_HOME", "OMNIRUSH_MCP_FILTER", "PATH"]) {if (saved[key] === undefined) delete process.env[key];else process.env[key] = saved[key];}@@ -90,6 +91,8 @@ describe("the engine plugin (omnirush-mcp-policy)", () => {const root = temp("mcp-root-");const env = mcpEngineEnv(state);Object.assign(process.env, env);+ // Not the engine's process: no filter mode and no env-only mark unless a test sets them.+ delete process.env.OMNIRUSH_MCP_FILTER;process.env.OMNIRUSH_BOX_HOME = path.join(state, "box-home");// The runners resolve to absolute paths on PATH, outside the project.const bin = temp("mcp-bin-");@@ -207,6 +210,46 @@ describe("the engine plugin (omnirush-mcp-policy)", () => {expect(readFileSync(path.join(reports, readdirSync(reports)[0] ?? ""), "utf8")).toContain("playwright");});+ test("an engine that requires the filter but does not start servers env-only starts no local server; remote ones still start", async () => {+ const { state, root } = setup();+ rememberMcpPolicy(state, { mcp: policyFixture });+ process.env.OMNIRUSH_MCP_FILTER = "required";+ delete (globalThis as Record<symbol, unknown>)[MCP_ENV_ONLY_MARK];+ const config = () => ({ mcp: {+ files: { type: "local", command: ["npx", "-y", "@modelcontextprotocol/server-filesystem", "{file:../outside.txt}"] },+ figma: { type: "remote", url: "http://127.0.0.1:3845/mcp" },+ } }) as Record<string, unknown>;+ const older = config();+ await (await omnirushMcpPolicy({ directory: root })).config({}, older);+ expect(Object.keys(older.mcp as object)).toEqual(["figma"]);+ let report = workspaceMcpReport(state, root);+ expect(report?.decisions[0]).toMatchObject({ name: "files", status: "blocked", code: "engine_update", reason: "This MCP server needs a newer engine; update OmniRush to use it." });+ expect(report?.decisions[1]).toMatchObject({ name: "figma", status: "allowed" });+ expect(report).toMatchObject({ filter_required: true, env_only: false });+ // The add route says the same while the last engine run was an older one.+ expect(decideMcpEntry(state, root, "filesystem", FILESYSTEM)).toMatchObject({ status: "blocked", code: "engine_update", reason: MCP_REASONS.engine_update });++ (globalThis as Record<symbol, unknown>)[MCP_ENV_ONLY_MARK] = true;+ const newer = config();+ newer.mcp = { files: FILESYSTEM, figma: (newer.mcp as Record<string, unknown>).figma };+ await (await omnirushMcpPolicy({ directory: root })).config({}, newer);+ expect(Object.keys(newer.mcp as object).sort()).toEqual(["figma", "filesystem"]);+ report = workspaceMcpReport(state, root);+ expect(report?.decisions.map((d) => d.status)).toEqual(["allowed", "allowed"]);+ expect(decideMcpEntry(state, root, "filesystem", FILESYSTEM)).toMatchObject({ status: "allowed" });+ });++ test("the filter not required: local servers start whatever the engine", async () => {+ const { state, root } = setup();+ rememberMcpPolicy(state, { mcp: policyFixture });+ delete process.env.OMNIRUSH_MCP_FILTER;+ delete (globalThis as Record<symbol, unknown>)[MCP_ENV_ONLY_MARK];+ const output = { mcp: { files: FILESYSTEM, figma: { type: "remote", url: "http://127.0.0.1:3845/mcp" } } } as Record<string, unknown>;+ await (await omnirushMcpPolicy({ directory: root })).config({}, output);+ expect(Object.keys(output.mcp as object).sort()).toEqual(["figma", "filesystem"]);+ expect(workspaceMcpReport(state, root)).toMatchObject({ filter_required: false, env_only: false });+ });+test("a missing or empty MCP plugin file is reported (the engine then starts no MCP server)", () => {const dir = mkdtempSync(path.join(tmpdir(), "mcp-filter-"));try {diff --git a/apps/server/src/mcp-allow/state.ts b/apps/server/src/mcp-allow/state.tsindex 36bc6103..6615c321 100644--- a/apps/server/src/mcp-allow/state.ts+++ b/apps/server/src/mcp-allow/state.ts@@ -172,7 +172,10 @@ export function workspaceMcpReport(stateDir: string, root: string): McpReport |* decision for it alone, with no sandbox (paths are checked the same way).*/export function decideMcpEntry(stateDir: string, root: string, name: string, entry: Record<string, unknown>): McpDecision {- const { decisions } = evaluateMcp({ [name]: entry }, currentMcpPolicy(stateDir), { root: path.resolve(root) });+ // An engine too old to start servers env-only (its last report says so) starts no local server.+ const last = workspaceMcpReport(stateDir, root);+ const olderEngine = last?.filter_required === true && last.env_only === false;+ const { decisions } = evaluateMcp({ [name]: entry }, currentMcpPolicy(stateDir), { root: path.resolve(root), filterRequired: olderEngine, ...(olderEngine ? { envOnly: false } : {}) });return decisions[0] ?? { name, status: "blocked", code: "invalid", reason: "This MCP server entry is not valid." };}