Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

fix: MCP runner on Windows without the batch file

Samrat Talukdar7cb511fa3c2d
diff --git a/apps/server/src/mcp-allow/PARITY.sha256 b/apps/server/src/mcp-allow/PARITY.sha256
index 8b9b26fc..748b8be7 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.
-fcd4fb27e77050003719ea06f2f1cb4dceb4c7d981c2c8ef881bb1d86581e620 mcp-allow.mjs
-3a548e530931a24d040fb804aae72607339b38791dafb63b4be02b9cf2933dd3 mcp-allow.d.mts
+7f82f94b85cc5bddec044c4f45d586616976229ef9b5614251ca9c4977489601 mcp-allow.mjs
+77027a1b0cdd8b07124cfec9f1a2809f25b60e23963a12898dfe62a37831c4a4 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 73712bf2..b85aac1b 100644
--- a/apps/server/src/mcp-allow/mcp-allow.d.mts
+++ b/apps/server/src/mcp-allow/mcp-allow.d.mts
@@ -69,7 +69,7 @@ export type McpDecision = {
export type McpBox = { shell: string; key: string; croot?: string | null };
-export type McpIgnored = { kind: "plugin" | "lsp" | "formatter"; name: string; source: 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 McpLaunch = {
@@ -91,6 +91,7 @@ export function normalizePolicy(block: unknown): McpPolicy | null;
export function splitSpec(spec: string, runtime: McpRuntime): { name: string; version: string | null } | null;
export function parseLaunch(command: unknown): McpLaunch | null;
export function launchCommand(entry: McpAllowEntry, launch: McpLaunch, version: string, npmPrefix: string): string[];
+export function windowsDirect(found: string, platform?: string, exists?: (file: string) => boolean): string[] | null;
export function resolveRunner(runner: string, options?: { root?: string | null; platform?: string; env?: Record<string, string | undefined>; exists?: (file: string) => boolean }): string | null;
export function projectCodeIgnored(cfg: unknown): McpIgnored[];
export function describeIgnored(items: McpIgnored[] | null | undefined): string | null;
@@ -100,7 +101,7 @@ export function shellQuote(word: string): 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 }) => string | null },
+ ctx?: { root?: string; platform?: string; box?: McpBox | null; npmPrefix?: string; resolveRunner?: (runner: string, options: { root: string; platform: string }) => string | null; exists?: (file: string) => 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">;
diff --git a/apps/server/src/mcp-allow/mcp-allow.mjs b/apps/server/src/mcp-allow/mcp-allow.mjs
index 48c6b3a6..48229c20 100644
--- a/apps/server/src/mcp-allow/mcp-allow.mjs
+++ b/apps/server/src/mcp-allow/mcp-allow.mjs
@@ -294,6 +294,21 @@ export function launchCommand(entry, launch, version, npmPrefix) {
return ["uvx", "--no-config", ...(launch.bin ? ["--from", `${entry.package}==${version}`, launch.bin] : [`${entry.package}@${version}`])];
}
+/**
+ * The program words that start `runner` (an absolute path from resolveRunner). On Windows npx is a batch
+ * file (npx.cmd): cmd.exe re-reads its arguments, and the batch first runs npm's prefix lookup in the current
+ * folder (the project, whose .npmrc could point it at a copy of npx inside the project). So the batch never
+ * runs: npm's own `node.exe` beside it runs `node_modules/npm/bin/npx-cli.js` directly. null when they are
+ * not there. Anything else is started as found.
+ */
+export function windowsDirect(found, platform = process.platform, exists = existsSync) {
+ if (platform !== "win32" || !/\.(cmd|bat)$/i.test(found)) return [found];
+ const dir = path.win32.dirname(found);
+ const node = path.win32.join(dir, "node.exe");
+ const cli = path.win32.join(dir, "node_modules", "npm", "bin", `${path.win32.basename(found).replace(/\.(cmd|bat)$/i, "")}-cli.js`);
+ return exists(node) && exists(cli) ? [node, cli] : null;
+}
+
/**
* `runner` (npx, uvx) as an absolute path from PATH: only absolute PATH
* folders outside the project (after links) count, never the current
@@ -540,8 +555,13 @@ export function evaluateMcp(mcpMap, policy, ctx = {}) {
// By absolute path: the engine starts the server in the project folder, and on Windows a bare name
// is looked up there before PATH (a repo's own npx.cmd would run instead).
const found = (ctx.resolveRunner ?? resolveRunner)(argv[0], { root, platform });
- if (!found) { decisions.push(blocked(name, "runner_missing", { ...base, version })); continue; }
- argv[0] = found;
+ const program = found ? windowsDirect(found, platform, ctx.exists ?? existsSync) : null;
+ if (!program) { decisions.push(blocked(name, "runner_missing", { ...base, version })); continue; }
+ if (platform === "win32" && argv.slice(1).some((a) => /["\r\n%]/.test(a))) {
+ decisions.push(blocked(name, "invalid", { ...base, version, reason: `${MCP_REASONS.invalid} (an argument holds a quote, % or a line break)` }));
+ continue;
+ }
+ argv.splice(0, 1, ...program);
}
const next = { ...raw, type: "local" };
if (box) {
@@ -680,7 +700,7 @@ export function readReport(dir, root) {
export function projectCodeIgnored(cfg) {
const list = isRecord(cfg) && Array.isArray(cfg.omnirush_ignored) ? cfg.omnirush_ignored : [];
return list
- .filter((x) => isRecord(x) && ["plugin", "lsp", "formatter"].includes(x.kind) && typeof x.name === "string")
+ .filter((x) => isRecord(x) && ["plugin", "lsp", "formatter", "provider"].includes(x.kind) && typeof x.name === "string")
.slice(0, 50)
.map((x) => ({ kind: x.kind, name: x.name.slice(0, 200), source: typeof x.source === "string" ? x.source.slice(0, 400) : null }));
}
@@ -694,10 +714,12 @@ export function describeIgnored(items) {
const plugins = what("plugin");
const lsp = what("lsp");
const fmt = what("formatter");
+ const providers = what("provider");
if (plugins.length) parts.push(`plugins ${plugins.slice(0, 3).join(", ")}${plugins.length > 3 ? " ..." : ""}`);
if (lsp.length) parts.push(`language servers ${lsp.slice(0, 3).join(", ")}`);
if (fmt.length) parts.push(`formatters ${fmt.slice(0, 3).join(", ")}`);
- return `Not loaded from this project's config: ${parts.join("; ")}. A project's own plugins and commands could run code just by opening it; the built-in language servers and formatters still work, and your own settings in ~/.config/omnirush apply as usual.`;
+ if (providers.length) parts.push("model provider settings");
+ return `Not loaded from this project's config: ${parts.join("; ")}. A project's own plugins, tools, commands and providers could run code just by opening it; the built-in language servers and formatters still work, and your own (user-level) settings apply as usual.`;
}
/** One line per decision, for a terminal or a notice. */