@@ -147,8 +147,23 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
147147
148148 if ( git ) {
149149 // register events
150- git . onDidOpenRepository ( ( repo : GitRepository ) => {
151- codacyCloud . open ( repo )
150+ git . onDidOpenRepository ( async ( repo : GitRepository ) => {
151+ await codacyCloud . open ( repo )
152+ // Configure MCP after repository is opened and params are available
153+ if ( codacyCloud . params ) {
154+ configureMCP ( codacyCloud . params , isMCPConfigured ( ) ) . catch ( ( error ) => {
155+ Logger . warn ( `Failed to configure MCP: ${ error } ` )
156+ } )
157+ } else {
158+ Logger . debug ( 'Repository params not yet available, will configure MCP later' )
159+ }
160+ } )
161+
162+ // Configure MCP when repository is fully loaded and params are definitely available
163+ codacyCloud . onDidLoadRepository ( ( ) => {
164+ configureMCP ( codacyCloud . params , isMCPConfigured ( ) ) . catch ( ( error ) => {
165+ Logger . warn ( `Failed to configure MCP after repository load: ${ error } ` )
166+ } )
152167 } )
153168
154169 git . onDidCloseRepository ( ( repo : GitRepository ) => {
@@ -164,7 +179,13 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
164179 if ( state === 'initialized' ) {
165180 if ( git . repositories . length > 0 ) {
166181 Logger . debug ( `Git API initialized with ${ git . repositories . length } repositories` )
167- codacyCloud . open ( git . repositories [ 0 ] )
182+ await codacyCloud . open ( git . repositories [ 0 ] )
183+ // Configure MCP after repository is opened and params are available
184+ if ( codacyCloud . params ) {
185+ await configureMCP ( codacyCloud . params , isMCPConfigured ( ) )
186+ } else {
187+ Logger . debug ( 'Repository params not yet available, will configure MCP later' )
188+ }
168189 } else {
169190 Logger . appendLine ( 'Git API initialized but no repositories found' )
170191 codacyCloud . clear ( )
@@ -265,9 +286,6 @@ export async function activate(context: vscode.ExtensionContext) {
265286 }
266287 }
267288
268- // Configure MCP automatically
269- await configureMCP ( codacyCloud . params , isMCPConfigured ( ) )
270-
271289 await registerCommands ( context , codacyCloud )
272290
273291 // add views
@@ -337,7 +355,13 @@ export async function activate(context: vscode.ExtensionContext) {
337355 // check for open repository
338356 if ( gitProvider . state === 'initialized' && gitProvider . repositories . length > 0 ) {
339357 Logger . debug ( `Found ${ gitProvider . repositories . length } repositories, opening first one` )
340- codacyCloud . open ( gitProvider . repositories [ 0 ] )
358+ await codacyCloud . open ( gitProvider . repositories [ 0 ] )
359+ // Configure MCP after repository is opened and params are available
360+ if ( codacyCloud . params ) {
361+ await configureMCP ( codacyCloud . params , isMCPConfigured ( ) )
362+ } else {
363+ Logger . debug ( 'Repository params not yet available, will configure MCP later' )
364+ }
341365 } else if ( gitProvider . state === 'uninitialized' ) {
342366 Logger . debug ( 'Git API is still initializing, will wait for state change event' )
343367 } else {
0 commit comments