fix(acp): disable host MCP discovery in ACP session factory

ACP clients own MCP server configuration via session/new.mcpServers and AcpAgent#configureMcpServers. The ACP session factory previously left enableMCP at its default (true), so createAgentSession ran discoverAndLoadMCPTools on every session/new and the resulting host MCP tools landed in the session tool registry alongside the client-supplied ones. search_tool_bm25 then surfaced only the host tools.

Force enableMCP: false on every session created through createAcpSessionFactory so on-disk discovery is bypassed in ACP mode. Non-ACP modes (omp interactive, print, RPC) keep auto-discovery.

Fixes #1234
This commit is contained in:
roboomp
2026-05-20 21:40:43 +00:00
parent e82b6d70ab
commit 185615497c
3 changed files with 93 additions and 2 deletions
+13 -2
View File
@@ -199,7 +199,7 @@ function applyExtensionFlagValues(session: AgentSession, rawArgs: string[]): Map
type AcpSessionFactory = (cwd: string) => Promise<AgentSession>;
interface AcpSessionFactoryOptions {
export interface AcpSessionFactoryOptions {
baseOptions: CreateAgentSessionOptions;
settings: Settings;
sessionDir?: string;
@@ -210,7 +210,17 @@ interface AcpSessionFactoryOptions {
createSession: (options: CreateAgentSessionOptions) => Promise<CreateAgentSessionResult>;
}
function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSessionFactory {
/**
* Build the per-`session/new` factory used by ACP mode.
*
* MCP servers in ACP sessions are owned exclusively by the ACP client, which
* supplies them through `session/new.mcpServers` and re-applies them via
* {@link AcpAgent#configureMcpServers}. We therefore force `enableMCP: false`
* on every session created here so {@link createAgentSession} skips the on-disk
* `.mcp.json` discovery path — otherwise host MCP tools land in the session's
* tool registry and shadow the client-supplied servers (issue #1234).
*/
export function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSessionFactory {
return async cwd => {
const nextSettings = await args.settings.cloneForCwd(cwd);
const nextSessionManager = SessionManager.create(cwd, args.sessionDir);
@@ -224,6 +234,7 @@ function createAcpSessionFactory(args: AcpSessionFactoryOptions): AcpSessionFact
modelRegistry: args.modelRegistry,
agentId,
hasUI: false,
enableMCP: false,
});
if (args.parsedArgs.apiKey && !args.baseOptions.model && nextSession.model) {
args.authStorage.setRuntimeApiKey(nextSession.model.provider, args.parsedArgs.apiKey);