summaryrefslogtreecommitdiff
path: root/packages/cli/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src/config')
-rw-r--r--packages/cli/src/config/config.test.ts96
-rw-r--r--packages/cli/src/config/config.ts40
2 files changed, 7 insertions, 129 deletions
diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts
index c0e9c215..55780320 100644
--- a/packages/cli/src/config/config.test.ts
+++ b/packages/cli/src/config/config.test.ts
@@ -1011,100 +1011,4 @@ describe('loadCliConfig ideMode', () => {
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getIdeMode()).toBe(false);
});
-
- it('should add _ide_server when ideMode is true', async () => {
- process.argv = ['node', 'script.js', '--ide-mode'];
- const argv = await parseArguments();
- process.env.TERM_PROGRAM = 'vscode';
- process.env.GEMINI_CLI_IDE_SERVER_PORT = '3000';
- const settings: Settings = {};
- const config = await loadCliConfig(settings, [], 'test-session', argv);
- expect(config.getIdeMode()).toBe(true);
- const mcpServers = config.getMcpServers();
- expect(mcpServers['_ide_server']).toBeDefined();
- expect(mcpServers['_ide_server'].httpUrl).toBe('http://localhost:3000/mcp');
- expect(mcpServers['_ide_server'].description).toBe('IDE connection');
- expect(mcpServers['_ide_server'].trust).toBe(false);
- });
-
- it('should warn if ideMode is true and no port is set', async () => {
- const consoleWarnSpy = vi
- .spyOn(console, 'warn')
- .mockImplementation(() => {});
- process.argv = ['node', 'script.js', '--ide-mode'];
- const argv = await parseArguments();
- process.env.TERM_PROGRAM = 'vscode';
- const settings: Settings = {};
- await loadCliConfig(settings, [], 'test-session', argv);
- expect(consoleWarnSpy).toHaveBeenCalledWith(
- '[WARN]',
- 'Could not connect to IDE. Make sure you have the companion VS Code extension installed from the marketplace or via /ide install.',
- );
- consoleWarnSpy.mockRestore();
- });
-
- it('should warn and overwrite if settings contain the reserved _ide_server name and ideMode is active', async () => {
- const consoleWarnSpy = vi
- .spyOn(console, 'warn')
- .mockImplementation(() => {});
-
- process.argv = ['node', 'script.js', '--ide-mode'];
- const argv = await parseArguments();
- process.env.TERM_PROGRAM = 'vscode';
- process.env.GEMINI_CLI_IDE_SERVER_PORT = '3000';
- const settings: Settings = {
- mcpServers: {
- _ide_server: new ServerConfig.MCPServerConfig(
- undefined,
- undefined,
- undefined,
- undefined,
- 'http://malicious:1234',
- ),
- },
- };
-
- const config = await loadCliConfig(settings, [], 'test-session', argv);
-
- expect(consoleWarnSpy).toHaveBeenCalledWith(
- '[WARN]',
- 'Ignoring user-defined MCP server config for "_ide_server" as it is a reserved name.',
- );
-
- const mcpServers = config.getMcpServers();
- expect(mcpServers['_ide_server']).toBeDefined();
- expect(mcpServers['_ide_server'].httpUrl).toBe('http://localhost:3000/mcp');
-
- consoleWarnSpy.mockRestore();
- });
-
- it('should NOT warn if settings contain the reserved _ide_server name and ideMode is NOT active', async () => {
- const consoleWarnSpy = vi
- .spyOn(console, 'warn')
- .mockImplementation(() => {});
-
- process.argv = ['node', 'script.js'];
- const argv = await parseArguments();
- const settings: Settings = {
- mcpServers: {
- _ide_server: new ServerConfig.MCPServerConfig(
- undefined,
- undefined,
- undefined,
- undefined,
- 'http://malicious:1234',
- ),
- },
- };
-
- const config = await loadCliConfig(settings, [], 'test-session', argv);
-
- expect(consoleWarnSpy).not.toHaveBeenCalled();
-
- const mcpServers = config.getMcpServers();
- expect(mcpServers['_ide_server']).toBeDefined();
- expect(mcpServers['_ide_server'].url).toBe('http://malicious:1234');
-
- consoleWarnSpy.mockRestore();
- });
});
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts
index 650f3aa2..27e3ec09 100644
--- a/packages/cli/src/config/config.ts
+++ b/packages/cli/src/config/config.ts
@@ -19,8 +19,7 @@ import {
FileDiscoveryService,
TelemetryTarget,
FileFilteringOptions,
- MCPServerConfig,
- IDE_SERVER_NAME,
+ IdeClient,
} from '@google/gemini-cli-core';
import { Settings } from './settings.js';
@@ -264,6 +263,11 @@ export async function loadCliConfig(
process.env.TERM_PROGRAM === 'vscode' &&
!process.env.SANDBOX;
+ let ideClient: IdeClient | undefined;
+ if (ideMode) {
+ ideClient = new IdeClient();
+ }
+
const allExtensions = annotateActiveExtensions(
extensions,
argv.extensions || [],
@@ -355,37 +359,6 @@ export async function loadCliConfig(
}
}
- if (ideMode) {
- if (mcpServers[IDE_SERVER_NAME]) {
- logger.warn(
- `Ignoring user-defined MCP server config for "${IDE_SERVER_NAME}" as it is a reserved name.`,
- );
- }
- const companionPort = process.env.GEMINI_CLI_IDE_SERVER_PORT;
- if (companionPort) {
- const httpUrl = `http://localhost:${companionPort}/mcp`;
- mcpServers[IDE_SERVER_NAME] = new MCPServerConfig(
- undefined, // command
- undefined, // args
- undefined, // env
- undefined, // cwd
- undefined, // url
- httpUrl, // httpUrl
- undefined, // headers
- undefined, // tcp
- undefined, // timeout
- false, // trust
- 'IDE connection', // description
- undefined, // includeTools
- undefined, // excludeTools
- );
- } else {
- logger.warn(
- 'Could not connect to IDE. Make sure you have the companion VS Code extension installed from the marketplace or via /ide install.',
- );
- }
- }
-
const sandboxConfig = await loadSandboxConfig(settings, argv);
return new Config({
@@ -450,6 +423,7 @@ export async function loadCliConfig(
noBrowser: !!process.env.NO_BROWSER,
summarizeToolOutput: settings.summarizeToolOutput,
ideMode,
+ ideClient,
});
}