Skip to content

Commit 1febd3a

Browse files
Merge pull request #135 from codacy/fix-install-mcp
fix: vscode not immediately detecting mcp installation
2 parents 376286e + bc4ada4 commit 1febd3a

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/commands/configureMCP.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/extension.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,12 @@ const registerCommands = async (context: vscode.ExtensionContext, codacyCloud: C
5252
},
5353
'codacy.configureMCP': async () => {
5454
await configureMCP(codacyCloud.params)
55-
updateMCPState()
5655
},
5756
'codacy.configureGuardrails': async () => {
5857
await configureGuardrails(codacyCloud.cli, codacyCloud.params)
59-
updateMCPState()
6058
},
6159
'codacy.configureMCP.reset': async () => {
6260
await configureMCP(codacyCloud.params, true)
63-
updateMCPState()
6461
},
6562
'codacy.onboarding.complete': () => {
6663
const { provider, organization } = codacyCloud.params!

0 commit comments

Comments
 (0)