Compare commits

...
Author SHA1 Message Date
陈大猫 19ff28528d fix(ai): keep CodeBuddy MCP discovery isolated 2026-11-21 12:17:23 +08:00
陈大猫 bb81b72ff0 fix(ai): avoid empty CodeBuddy tools whitelist that hides MCP tools (#4214)
Omit tools in MCP mode and explicitly disallow CodeBuddy built-ins, preserving injected MCP visibility and the skills-mode Bash whitelist.

Fixes #4214
2026-11-12 14:13:14 +08:00
2 changed files with 37 additions and 7 deletions

No files matched your search

@@ -254,19 +254,25 @@ function buildCodebuddyQueryOptions({
elicitation, canUseTool,
}) {
const builtinTools = codebuddyBuiltinTools(toolIntegrationMode);
const mcpMode = builtinTools.length === 0;
const mcpServers = toSdkMcpServers(injectedMcpServers);
if (mcpMode) {
// These are only the app-managed servers. Show their tools directly without
// enabling the CLI’s general-purpose discovery tools.
for (const server of Object.values(mcpServers)) {
if (server.type !== "sdk") server.defer_loading = false;
}
}
const options = {
cwd,
includePartialMessages: true,
permissionMode: "bypassPermissions",
allowDangerouslySkipPermissions: true,
extraArgs: { "dangerously-skip-permissions": null },
mcpServers: toSdkMcpServers(injectedMcpServers),
mcpServers,
...(mcpMode ? { strictMcpConfig: true } : {}),
// Keep unrelated CLI built-ins disabled by default, including future tools.
tools: builtinTools,
// `tools` is the built-in tool whitelist. In mcp mode it is [], so CodeBuddy
// built-ins stay disabled while injected Netcatty MCP tools remain visible.
// Do not mirror that empty list into allowedTools: the SDK treats
// allowedTools as an auto-approval list, and allowedTools: [] prevents MCP
// tool calls from running under bypassPermissions.
disallowedTools: [...UI_DISALLOWED_TOOLS],
// Keep the SDK isolated from user/project settings so local hooks, plugins,
// or extra MCP servers cannot expand Netcatty's controlled tool boundary.
@@ -60,14 +60,38 @@ test("buildCodebuddyQueryOptions wires SDK options in isolated mode", () => {
assert.equal(opts.abortController, ac);
assert.equal(opts.resume, "sess-1");
assert.deepEqual(opts.tools, []);
// allowedTools must stay unset in mcp mode: tools:[] disables built-ins, while
// allowedTools:[] would prevent injected Netcatty MCP tools from running.
assert.ok(!("allowedTools" in opts));
assert.equal(opts.strictMcpConfig, true);
assert.equal(opts.mcpServers["netcatty-remote-hosts"].defer_loading, false);
assert.ok(opts.disallowedTools.includes("AskUserQuestion"));
assert.equal(opts.mcpServers["netcatty-remote-hosts"].type, "stdio");
assert.deepEqual(opts.mcpServers["netcatty-remote-hosts"].env, { NETCATTY_MCP_PORT: "1" });
});
test("mcp and default mode allow only the app-managed MCP configuration", () => {
for (const toolIntegrationMode of ["mcp", undefined]) {
const opts = buildCodebuddyQueryOptions({
toolIntegrationMode,
injectedMcpServers: [{ name: "netcatty", command: "/abs/electron" }],
});
assert.deepEqual(opts.tools, []);
assert.ok(!("allowedTools" in opts));
assert.deepEqual(opts.settingSources, []);
assert.equal(opts.strictMcpConfig, true);
assert.equal(opts.mcpServers.netcatty.command, "/abs/electron");
assert.equal(opts.mcpServers.netcatty.defer_loading, false);
}
});
test("skills mode keeps the Bash whitelist and UI exclusions", () => {
const opts = buildCodebuddyQueryOptions({ toolIntegrationMode: "skills" });
assert.deepEqual(opts.tools, ["Bash"]);
assert.deepEqual(opts.disallowedTools, ["AskUserQuestion"]);
assert.ok(!opts.disallowedTools.includes("Bash"));
assert.ok(!("allowedTools" in opts));
});
test("built-in tools are mode-aware", () => {
assert.deepEqual(codebuddyBuiltinTools("mcp"), []);
assert.deepEqual(codebuddyBuiltinTools(undefined), []);