Skip to content

Commit a24e943

Browse files
fix: resolve MCP settings not displaying in welcome dialog
1 parent d35e787 commit a24e943

File tree

5 files changed

+33
-21
lines changed

5 files changed

+33
-21
lines changed
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
package com.checkmarx.intellij.commands;
22

3-
import com.checkmarx.ast.wrapper.CxConfig;
43
import com.checkmarx.ast.wrapper.CxException;
54
import com.checkmarx.intellij.settings.global.CxWrapperFactory;
6-
import org.jetbrains.annotations.NotNull;
5+
import com.checkmarx.intellij.settings.global.GlobalSettingsState;
6+
import com.checkmarx.intellij.settings.global.GlobalSettingsSensitiveState;
7+
import com.intellij.openapi.diagnostic.Logger;
78

89
import java.io.IOException;
9-
import java.net.URISyntaxException;
1010

1111
/**
1212
* Handle tenant settings related operations with the wrapper
1313
*/
1414
public class TenantSetting {
1515

16+
private static final Logger LOG = Logger.getInstance(TenantSetting.class);
17+
1618
/**
1719
* Check if current tenant has permissions to scan from the IDE
1820
*
1921
* @return true if tenant has permissions to scan. false otherwise
2022
*/
21-
@NotNull
2223
public static boolean isScanAllowed() throws
2324
IOException,
2425
CxException,
@@ -31,12 +32,12 @@ public static boolean isScanAllowed() throws
3132
*
3233
* @return true if AI MCP server is enabled, false otherwise
3334
*/
34-
@NotNull
35-
public static boolean isAiMcpServerEnabled() throws
35+
public static boolean isAiMcpServerEnabled(GlobalSettingsState state, GlobalSettingsSensitiveState sensitiveState) throws
3636
IOException,
3737
CxException,
3838
InterruptedException {
39-
return CxWrapperFactory.build().aiMcpServerEnabled();
39+
LOG.debug("Checking AI MCP server enabled flag using provided credentials");
40+
return CxWrapperFactory.build(state, sensitiveState).aiMcpServerEnabled();
4041
}
4142

4243
}

src/main/java/com/checkmarx/intellij/devassist/configuration/mcp/McpInstallService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* registered in plugin.xml. On startup it auto-installs MCP configuration if:
1919
* <ul>
2020
* <li>User is authenticated</li>
21-
* <li>AI MCP server flag is enabled (TenantSetting.isAiMcpServerEnabled())</li>
21+
* <li>AI MCP server flag is enabled (TenantSetting.isAiMcpServerEnabled(state, sensitiveState))</li>
2222
* <li>A credential token/API key is available</li>
2323
* </ul>
2424
* If any condition fails the auto-install silently skips (debug logged).
@@ -46,7 +46,7 @@ public void runActivity(@NotNull Project project) {
4646

4747
boolean aiMcpEnabled;
4848
try {
49-
aiMcpEnabled = TenantSetting.isAiMcpServerEnabled();
49+
aiMcpEnabled = TenantSetting.isAiMcpServerEnabled(state, sensitive);
5050
} catch (Exception e) {
5151
LOG.warn("Failed to check AI MCP server status; skipping MCP auto-install.", e);
5252
return;

src/main/java/com/checkmarx/intellij/settings/global/CxOneAssistComponent.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ private void checkAndUpdateMcpStatusAsync() {
449449

450450
CompletableFuture.supplyAsync(() -> {
451451
try {
452-
return com.checkmarx.intellij.commands.TenantSetting.isAiMcpServerEnabled();
452+
GlobalSettingsState currentState = GlobalSettingsState.getInstance();
453+
GlobalSettingsSensitiveState currentSensitiveState = GlobalSettingsSensitiveState.getInstance();
454+
return com.checkmarx.intellij.commands.TenantSetting.isAiMcpServerEnabled(currentState, currentSensitiveState);
453455
} catch (Exception ex) {
454456
LOGGER.warn("Failed to check MCP status during upgrade scenario", ex);
455457
return false; // Default to disabled on error

src/main/java/com/checkmarx/intellij/settings/global/GlobalSettingsComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,11 @@ private void onAuthSuccessApiKey() {
318318
* @param credential The credential to use for MCP installation (API key or refresh token)
319319
*/
320320
private void completeAuthenticationSetup(String credential) {
321-
// Check MCP server status once during authentication
321+
// Check MCP server status using current authentication credentials
322322
boolean mcpServerEnabled = false;
323323
try {
324-
mcpServerEnabled = com.checkmarx.intellij.commands.TenantSetting.isAiMcpServerEnabled();
324+
mcpServerEnabled = com.checkmarx.intellij.commands.TenantSetting.isAiMcpServerEnabled(
325+
getStateFromFields(), getSensitiveStateFromFields());
325326
} catch (Exception ex) {
326327
LOGGER.warn("Failed MCP server check", ex);
327328
}

src/test/java/com/checkmarx/intellij/unit/commands/TenantSettingTest.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.checkmarx.intellij.unit.commands;
22

3-
import com.checkmarx.ast.wrapper.CxConfig;
43
import com.checkmarx.ast.wrapper.CxException;
54
import com.checkmarx.ast.wrapper.CxWrapper;
65
import com.checkmarx.intellij.commands.TenantSetting;
76
import com.checkmarx.intellij.settings.global.CxWrapperFactory;
7+
import com.checkmarx.intellij.settings.global.GlobalSettingsState;
8+
import com.checkmarx.intellij.settings.global.GlobalSettingsSensitiveState;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.api.Test;
1011
import org.junit.jupiter.api.extension.ExtendWith;
@@ -13,7 +14,6 @@
1314
import org.mockito.junit.jupiter.MockitoExtension;
1415

1516
import java.io.IOException;
16-
import java.net.URISyntaxException;
1717

1818
import static org.junit.jupiter.api.Assertions.*;
1919
import static org.mockito.Mockito.*;
@@ -72,31 +72,39 @@ void isScanAllowed_ThrowsException() throws IOException, CxException, Interrupte
7272
}
7373
}
7474

75+
7576
@Test
76-
void isAiMcpServerEnabled_ReturnsTrue() throws IOException, CxException, InterruptedException {
77+
void isAiMcpServerEnabled_WithExplicitState_ReturnsTrue() throws IOException, CxException, InterruptedException {
7778
// Arrange
79+
GlobalSettingsState mockState = mock(GlobalSettingsState.class);
80+
GlobalSettingsSensitiveState mockSensitiveState = mock(GlobalSettingsSensitiveState.class);
81+
7882
try (MockedStatic<CxWrapperFactory> mockedFactory = mockStatic(CxWrapperFactory.class)) {
79-
mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper);
83+
mockedFactory.when(() -> CxWrapperFactory.build(mockState, mockSensitiveState)).thenReturn(mockWrapper);
8084
when(mockWrapper.aiMcpServerEnabled()).thenReturn(true);
8185

8286
// Act
83-
boolean result = TenantSetting.isAiMcpServerEnabled();
87+
boolean result = TenantSetting.isAiMcpServerEnabled(mockState, mockSensitiveState);
8488

8589
// Assert
8690
assertTrue(result);
8791
verify(mockWrapper).aiMcpServerEnabled();
92+
mockedFactory.verify(() -> CxWrapperFactory.build(mockState, mockSensitiveState));
8893
}
8994
}
9095

9196
@Test
92-
void isAiMcpServerEnabled_ThrowsException() throws IOException, CxException, InterruptedException {
97+
void isAiMcpServerEnabled_WithExplicitState_ThrowsException() throws IOException, CxException, InterruptedException {
9398
// Arrange
99+
GlobalSettingsState mockState = mock(GlobalSettingsState.class);
100+
GlobalSettingsSensitiveState mockSensitiveState = mock(GlobalSettingsSensitiveState.class);
101+
94102
try (MockedStatic<CxWrapperFactory> mockedFactory = mockStatic(CxWrapperFactory.class)) {
95-
mockedFactory.when(CxWrapperFactory::build).thenReturn(mockWrapper);
103+
mockedFactory.when(() -> CxWrapperFactory.build(mockState, mockSensitiveState)).thenReturn(mockWrapper);
96104
when(mockWrapper.aiMcpServerEnabled()).thenThrow(mock(CxException.class));
97105

98106
// Act & Assert
99-
assertThrows(CxException.class, TenantSetting::isAiMcpServerEnabled);
107+
assertThrows(CxException.class, () -> TenantSetting.isAiMcpServerEnabled(mockState, mockSensitiveState));
100108
}
101109
}
102-
}
110+
}

0 commit comments

Comments
 (0)