@@ -155,8 +155,16 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
155155
156156 if ( git ) {
157157 // register events
158- git . onDidOpenRepository ( ( repo : GitRepository ) => {
159- codacyCloud . open ( repo )
158+ git . onDidOpenRepository ( async ( repo : GitRepository ) => {
159+ try {
160+ await codacyCloud . open ( repo )
161+ // update MCP after repository is opened and params are available
162+ updateMCPConfig ( codacyCloud . params ) . catch ( ( error ) => {
163+ Logger . warn ( `Failed to update MCP config: ${ error instanceof Error ? error . message : String ( error ) } ` )
164+ } )
165+ } catch ( error ) {
166+ Logger . error ( `Failed to open repository: ${ error instanceof Error ? error . message : String ( error ) } ` )
167+ }
160168 } )
161169
162170 git . onDidCloseRepository ( ( repo : GitRepository ) => {
@@ -172,7 +180,9 @@ const registerGitProvider = async (context: vscode.ExtensionContext, codacyCloud
172180 if ( state === 'initialized' ) {
173181 if ( git . repositories . length > 0 ) {
174182 Logger . debug ( `Git API initialized with ${ git . repositories . length } repositories` )
175- codacyCloud . open ( git . repositories [ 0 ] )
183+ await codacyCloud . open ( git . repositories [ 0 ] )
184+ // Update MCP config after repository is opened and params are available
185+ await updateMCPConfig ( codacyCloud . params )
176186 } else {
177187 Logger . appendLine ( 'Git API initialized but no repositories found' )
178188 codacyCloud . clear ( )
@@ -350,7 +360,7 @@ export async function activate(context: vscode.ExtensionContext) {
350360 // check for open repository
351361 if ( gitProvider . state === 'initialized' && gitProvider . repositories . length > 0 ) {
352362 Logger . debug ( `Found ${ gitProvider . repositories . length } repositories, opening first one` )
353- codacyCloud . open ( gitProvider . repositories [ 0 ] )
363+ await codacyCloud . open ( gitProvider . repositories [ 0 ] )
354364 } else if ( gitProvider . state === 'uninitialized' ) {
355365 Logger . debug ( 'Git API is still initializing, will wait for state change event' )
356366 } else {
0 commit comments