@@ -426,14 +426,18 @@ export async function configureGuardrails(cli?: CodacyCli, params?: RepositoryPa
426426 await configureMCP ( params )
427427}
428428
429- function installMCPForVSCode ( server : MCPServerConfiguration ) {
429+ async function installMCPForVSCode ( server : MCPServerConfiguration ) : Promise < void > {
430430 // Implement the logic for installing MCP for VSCode using native User Settings API
431431 const mcpConfig = vscode . workspace . getConfiguration ( 'mcp' )
432- const mcpServers = mcpConfig . has ( 'servers' ) ? mcpConfig . get ( 'servers' ) : mcpConfig . update ( 'servers' , { } , true )
432+ let mcpServers = mcpConfig . get ( 'servers' )
433+
434+ if ( ! mcpServers ) {
435+ mcpServers = { }
436+ }
433437
434438 if ( mcpServers !== undefined && typeof mcpServers === 'object' && mcpServers !== null ) {
435439 const modifiedConfig = set ( mcpServers , 'codacy' , server )
436- vscode . workspace . getConfiguration ( 'mcp' ) . update ( 'servers' , modifiedConfig , true )
440+ await vscode . workspace . getConfiguration ( 'mcp' ) . update ( 'servers' , modifiedConfig , true )
437441 } else {
438442 Logger . error ( 'MCP configuration not found in VS Code settings' )
439443 }
@@ -510,7 +514,7 @@ export async function configureMCP(params?: RepositoryParams, isUpdate = false)
510514 }
511515
512516 if ( ide === 'vscode' || ide === 'insiders' ) {
513- installMCPForVSCode ( codacyServer )
517+ await installMCPForVSCode ( codacyServer )
514518 } else if ( ide === 'cursor' || ide === 'windsurf' ) {
515519 installMCPForOthers ( codacyServer )
516520 } else {
@@ -525,6 +529,7 @@ export async function configureMCP(params?: RepositoryParams, isUpdate = false)
525529 if ( ide === 'windsurf' ) {
526530 createWindsurfWorkflows ( )
527531 }
532+ updateMCPState ( )
528533 } catch ( error ) {
529534 throw new CodacyError ( 'Failed to configure MCP server' , error as Error , 'MCP' )
530535 }
0 commit comments