@@ -20,7 +20,7 @@ import {
2020} from '@google/gemini-cli-core' ;
2121import { Settings } from './settings.js' ;
2222
23- import { Extension } from './extension.js' ;
23+ import { Extension , filterActiveExtensions } from './extension.js' ;
2424import { getCliVersion } from '../utils/version.js' ;
2525import { loadSandboxConfig } from './sandboxConfig.js' ;
2626
@@ -49,6 +49,8 @@ interface CliArgs {
4949 telemetryOtlpEndpoint : string | undefined ;
5050 telemetryLogPrompts : boolean | undefined ;
5151 'allowed-mcp-server-names' : string | undefined ;
52+ extensions : string [ ] | undefined ;
53+ listExtensions : boolean | undefined ;
5254}
5355
5456async function parseArguments ( ) : Promise < CliArgs > {
@@ -133,6 +135,18 @@ async function parseArguments(): Promise<CliArgs> {
133135 type : 'string' ,
134136 description : 'Allowed MCP server names' ,
135137 } )
138+ . option ( 'extensions' , {
139+ alias : 'e' ,
140+ type : 'array' ,
141+ string : true ,
142+ description :
143+ 'A list of extensions to use. If not provided, all extensions are used.' ,
144+ } )
145+ . option ( 'list-extensions' , {
146+ alias : 'l' ,
147+ type : 'boolean' ,
148+ description : 'List all available extensions and exit.' ,
149+ } )
136150 . version ( await getCliVersion ( ) ) // This will enable the --version flag based on package.json
137151 . alias ( 'v' , 'version' )
138152 . help ( )
@@ -174,6 +188,11 @@ export async function loadCliConfig(
174188 const argv = await parseArguments ( ) ;
175189 const debugMode = argv . debug || false ;
176190
191+ const activeExtensions = filterActiveExtensions (
192+ extensions ,
193+ argv . extensions || [ ] ,
194+ ) ;
195+
177196 // Set the context filename in the server's memoryTool module BEFORE loading memory
178197 // TODO(b/343434939): This is a bit of a hack. The contextFileName should ideally be passed
179198 // directly to the Config constructor in core, and have core handle setGeminiMdFilename.
@@ -185,7 +204,9 @@ export async function loadCliConfig(
185204 setServerGeminiMdFilename ( getCurrentGeminiMdFilename ( ) ) ;
186205 }
187206
188- const extensionContextFilePaths = extensions . flatMap ( ( e ) => e . contextFiles ) ;
207+ const extensionContextFilePaths = activeExtensions . flatMap (
208+ ( e ) => e . contextFiles ,
209+ ) ;
189210
190211 const fileService = new FileDiscoveryService ( process . cwd ( ) ) ;
191212 // Call the (now wrapper) loadHierarchicalGeminiMemory which calls the server's version
@@ -196,8 +217,8 @@ export async function loadCliConfig(
196217 extensionContextFilePaths ,
197218 ) ;
198219
199- let mcpServers = mergeMcpServers ( settings , extensions ) ;
200- const excludeTools = mergeExcludeTools ( settings , extensions ) ;
220+ let mcpServers = mergeMcpServers ( settings , activeExtensions ) ;
221+ const excludeTools = mergeExcludeTools ( settings , activeExtensions ) ;
201222
202223 if ( argv [ 'allowed-mcp-server-names' ] ) {
203224 const allowedNames = new Set (
@@ -262,6 +283,11 @@ export async function loadCliConfig(
262283 bugCommand : settings . bugCommand ,
263284 model : argv . model ! ,
264285 extensionContextFilePaths,
286+ listExtensions : argv . listExtensions || false ,
287+ activeExtensions : activeExtensions . map ( ( e ) => ( {
288+ name : e . config . name ,
289+ version : e . config . version ,
290+ } ) ) ,
265291 } ) ;
266292}
267293
0 commit comments