summaryrefslogtreecommitdiff
path: root/packages/cli/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/cli/src')
-rw-r--r--packages/cli/src/config/config.test.ts17
-rw-r--r--packages/cli/src/config/config.ts9
2 files changed, 25 insertions, 1 deletions
diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts
index 4042bf93..6aab4487 100644
--- a/packages/cli/src/config/config.test.ts
+++ b/packages/cli/src/config/config.test.ts
@@ -840,6 +840,7 @@ describe('loadCliConfig ideMode', () => {
// Explicitly delete TERM_PROGRAM and SANDBOX before each test
delete process.env.TERM_PROGRAM;
delete process.env.SANDBOX;
+ delete process.env.GEMINI_CLI_IDE_SERVER_PORT;
});
afterEach(() => {
@@ -876,6 +877,7 @@ describe('loadCliConfig ideMode', () => {
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);
@@ -885,6 +887,7 @@ describe('loadCliConfig ideMode', () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments();
process.env.TERM_PROGRAM = 'vscode';
+ process.env.GEMINI_CLI_IDE_SERVER_PORT = '3000';
const settings: Settings = { ideMode: true };
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getIdeMode()).toBe(true);
@@ -894,6 +897,7 @@ describe('loadCliConfig ideMode', () => {
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 = { ideMode: false };
const config = await loadCliConfig(settings, [], 'test-session', argv);
expect(config.getIdeMode()).toBe(true);
@@ -932,6 +936,7 @@ describe('loadCliConfig ideMode', () => {
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);
@@ -941,4 +946,16 @@ describe('loadCliConfig ideMode', () => {
expect(mcpServers['_ide_server'].description).toBe('IDE connection');
expect(mcpServers['_ide_server'].trust).toBe(false);
});
+
+ it('should throw an error if ideMode is true and no port is set', async () => {
+ process.argv = ['node', 'script.js', '--ide-mode'];
+ const argv = await parseArguments();
+ process.env.TERM_PROGRAM = 'vscode';
+ const settings: Settings = {};
+ await expect(
+ loadCliConfig(settings, [], 'test-session', argv),
+ ).rejects.toThrow(
+ "Could not run in ide mode, make sure you're running in vs code integrated terminal. Try running in a fresh terminal.",
+ );
+ });
});
diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts
index bf76fa4c..69708a61 100644
--- a/packages/cli/src/config/config.ts
+++ b/packages/cli/src/config/config.ts
@@ -306,13 +306,20 @@ export async function loadCliConfig(
}
if (ideMode) {
+ const companionPort = process.env.GEMINI_CLI_IDE_SERVER_PORT;
+ if (!companionPort) {
+ throw new Error(
+ "Could not run in ide mode, make sure you're running in vs code integrated terminal. Try running in a fresh terminal.",
+ );
+ }
+ const httpUrl = `http://localhost:${companionPort}/mcp`;
mcpServers[IDE_SERVER_NAME] = new MCPServerConfig(
undefined, // command
undefined, // args
undefined, // env
undefined, // cwd
undefined, // url
- 'http://localhost:3000/mcp', // httpUrl
+ httpUrl, // httpUrl
undefined, // headers
undefined, // tcp
undefined, // timeout