Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(copilot): keep MCP servers out of the reserved browser/computer namespaces

AdityaUmale926d36629e94
diff --git a/server/drivers/acp/copilot.test.ts b/server/drivers/acp/copilot.test.ts
index 917056cfea..5bfc9ab726 100644
--- a/server/drivers/acp/copilot.test.ts
+++ b/server/drivers/acp/copilot.test.ts
@@ -12,7 +12,7 @@ import { BUILT_IN_DRIVERS } from "../builtIn.ts";
import { SPAWNED_PROXIES } from "../../proxy-paths.ts";
import { startFakeHttpMcp } from "../../testing/fake-http-mcp-server.ts";
import {
- classifyCopilotError, CopilotAgentDriver, copilotModelLabel, copilotSignedIn, forgetCopilotDiscoverySession, resolveCopilotModels,
+ classifyCopilotError, CopilotAgentDriver, copilotModelLabel, copilotServerNames, copilotSignedIn, forgetCopilotDiscoverySession, resolveCopilotModels,
} from "./copilot.ts";
const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "../../testing/fake-acp-cli.ts");
@@ -289,10 +289,20 @@ describe("GitHub Copilot ACP driver", () => {
expect(text).toContain("agents:");
expect(text).toContain("trigger");
expect(text).toContain("trigger_info");
- expect(text).toContain("browser: agent_browser_open");
+ // Copilot refuses functions in its reserved `browser` namespace, so the built-in browser server is renamed for it.
+ expect(text).toContain("maus_browser: agent_browser_open");
+ const launch = JSON.parse(readFileSync(join(scratch, "launch.json"), "utf8"));
+ const path = launch.argv[launch.argv.indexOf("--additional-mcp-config") + 1].slice(1) as string;
+ expect(Object.keys(JSON.parse(readFileSync(path, "utf8")).mcpServers).sort()).toEqual(["agents", "maus_browser"]);
} finally { await browser.close(); }
});
+ it("keeps Copilot's MCP server names out of its reserved browser and computer namespaces", () => {
+ expect(copilotServerNames(["agents", "browser", "computer", "data"])).toEqual(["agents", "maus_browser", "maus_computer", "data"]);
+ expect(copilotServerNames(["browser", "maus_browser", "Computer"])).toEqual(["maus_browser_2", "maus_browser", "maus_Computer"]);
+ expect(copilotServerNames(["agents", "my_browser", "computers"])).toEqual(["agents", "my_browser", "computers"]);
+ });
+
it("isolates native MCP configuration by thread and refreshes scoped tools and credentials on resume", async () => {
const launches = join(scratch, "launches.txt");
const { instance, recorder } = await create({ FAKE_ACP_MODE: "mcp-tools", FAKE_ACP_LAUNCH_COUNT_FILE: launches });
diff --git a/server/drivers/acp/copilot.ts b/server/drivers/acp/copilot.ts
index ba3cf8fe19..f988598f66 100644
--- a/server/drivers/acp/copilot.ts
+++ b/server/drivers/acp/copilot.ts
@@ -226,6 +226,22 @@ const SUPPORT: AcpSupport = {
buildPromptText: (turn) => (turn.system ? `${turn.system}\n\n${turn.text}` : turn.text),
};
+// Copilot refuses every function in the reserved `browser` and `computer` namespaces with an HTTP 400 on each turn,
+// and names an MCP server's namespace after its config key: only those two keys get a prefix, so other servers keep theirs.
+const COPILOT_RESERVED_SERVER_NAMES: ReadonlySet<string> = new Set(["browser", "computer"]);
+
+/** The config key Copilot gets for each server, in order: a reserved name becomes `maus_<name>` (numbered if taken). */
+export function copilotServerNames(names: readonly string[]): string[] {
+ const taken = new Set(names);
+ return names.map((name) => {
+ if (!COPILOT_RESERVED_SERVER_NAMES.has(name.toLowerCase())) return name;
+ let key = `maus_${name}`;
+ for (let n = 2; taken.has(key); n++) key = `maus_${name}_${n}`;
+ taken.add(key);
+ return key;
+ });
+}
+
export const CopilotAgentDriver = {
...createAcpDriver(SUPPORT),
/** Creates an instance with thread-isolated launcher config files, removed when the instance is disposed. */
@@ -238,7 +254,8 @@ export const CopilotAgentDriver = {
...SUPPORT,
applyTurnEnv(env, { threadId, mcpServers }) {
const path = join(directory, `${createHash("sha256").update(threadId).digest("hex")}.json`);
- const servers = Object.fromEntries(mcpServers.map((server) => [server.name, "command" in server
+ const names = copilotServerNames(mcpServers.map((server) => server.name));
+ const servers = Object.fromEntries(mcpServers.map((server, index) => [names[index], "command" in server
? { type: "local", command: server.command, args: server.args,
env: Object.fromEntries(server.env.map(({ name, value }) => [name, value])), tools: ["*"] }
: { type: server.type, url: server.url,