From 4c25d6b7be08d0d518fe174756076ce87ea5a17a Mon Sep 17 00:00:00 2001 From: Abdelrahman Shawki Hassan Date: Tue, 14 Oct 2025 12:56:36 +0200 Subject: [PATCH 1/3] fix: send changes for trusted folders --- src/snyk/cli/mcp/mcp.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/snyk/cli/mcp/mcp.ts b/src/snyk/cli/mcp/mcp.ts index 2b42dcc57..5bb418fc7 100644 --- a/src/snyk/cli/mcp/mcp.ts +++ b/src/snyk/cli/mcp/mcp.ts @@ -212,13 +212,13 @@ async function ensureMcpServerInJson( const existing = config.mcpServers[keyToUse]; const desired: McpServer = { command, args, env }; - // Merge env: keep existing keys; override Snyk keys only if already present + // Merge env: keep existing keys; add or override Snyk keys let resultingEnv: Env; if (existing && existing.env) { resultingEnv = { ...existing.env }; - const overrideKeys: (keyof Env)[] = ['SNYK_TOKEN', 'SNYK_CFG_ORG', 'SNYK_API']; + const overrideKeys: (keyof Env)[] = ['SNYK_CFG_ORG', 'SNYK_API', 'IDE_CONFIG_PATH', 'TRUSTED_FOLDERS']; for (const k of overrideKeys) { - if (Object.hasOwn(existing.env, k) && typeof env[k] !== 'undefined') { + if (typeof env[k] !== 'undefined') { resultingEnv[k] = env[k]; } } @@ -347,11 +347,7 @@ async function getSnykMcpEnv(configuration: IConfiguration): Promise { if (trustedFolders.length > 0) { env.TRUSTED_FOLDERS = trustedFolders.join(';'); } - const token = await configuration.getToken(); - const authMethod = configuration.getAuthenticationMethod(); - if ((authMethod === 'pat' || authMethod === 'token') && token) { - env.SNYK_TOKEN = token; - } + env.IDE_CONFIG_PATH = vscode.env.appName; return env; } From 41745e779ae40b74bb5343754c01016a69bc7a96 Mon Sep 17 00:00:00 2001 From: Abdelrahman Shawki Hassan Date: Tue, 14 Oct 2025 12:56:36 +0200 Subject: [PATCH 2/3] fix: send changes for trusted folders --- src/snyk/cli/mcp/mcp.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/snyk/cli/mcp/mcp.ts b/src/snyk/cli/mcp/mcp.ts index bc26739bc..aa63b7bd0 100644 --- a/src/snyk/cli/mcp/mcp.ts +++ b/src/snyk/cli/mcp/mcp.ts @@ -198,13 +198,13 @@ async function ensureMcpServerInJson( const existing = config.mcpServers[keyToUse]; const desired: McpServer = { command, args, env }; - // Merge env: keep existing keys; override Snyk keys only if already present + // Merge env: keep existing keys; add or override Snyk keys let resultingEnv: Env; if (existing && existing.env) { resultingEnv = { ...existing.env }; - const overrideKeys: (keyof Env)[] = ['SNYK_TOKEN', 'SNYK_CFG_ORG', 'SNYK_API']; + const overrideKeys: (keyof Env)[] = ['SNYK_CFG_ORG', 'SNYK_API', 'IDE_CONFIG_PATH', 'TRUSTED_FOLDERS']; for (const k of overrideKeys) { - if (Object.hasOwn(existing.env, k) && typeof env[k] !== 'undefined') { + if (typeof env[k] !== 'undefined') { resultingEnv[k] = env[k]; } } @@ -321,11 +321,7 @@ async function getSnykMcpEnv(configuration: IConfiguration): Promise { if (trustedFolders.length > 0) { env.TRUSTED_FOLDERS = trustedFolders.join(';'); } - const token = await configuration.getToken(); - const authMethod = configuration.getAuthenticationMethod(); - if ((authMethod === 'pat' || authMethod === 'token') && token) { - env.SNYK_TOKEN = token; - } + env.IDE_CONFIG_PATH = vscode.env.appName; return env; } From 1f607349d4ce47f610cabd09164b29f0d2935190 Mon Sep 17 00:00:00 2001 From: Abdelrahman Shawki Hassan Date: Fri, 17 Oct 2025 19:48:46 +0200 Subject: [PATCH 3/3] chore: lint --- src/snyk/cli/mcp/mcp.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/snyk/cli/mcp/mcp.ts b/src/snyk/cli/mcp/mcp.ts index aa63b7bd0..9e725fe8c 100644 --- a/src/snyk/cli/mcp/mcp.ts +++ b/src/snyk/cli/mcp/mcp.ts @@ -57,7 +57,7 @@ export async function configureCopilot(vscodeContext: vscode.ExtensionContext, c const cliPath = await configuration.getCliPath(); /* eslint-disable @typescript-eslint/no-unsafe-return */ const args = ['mcp', '-t', 'stdio']; - const snykEnv = await getSnykMcpEnv(configuration); + const snykEnv = getSnykMcpEnv(configuration); const processEnv: Env = {}; Object.entries(process.env).forEach(([key, value]) => { processEnv[key] = value ?? ''; @@ -105,7 +105,7 @@ export async function configureWindsurf(vscodeContext: vscode.ExtensionContext, Logger.debug(`Windsurf base directory not found at ${baseDir}, skipping MCP configuration.`); } else { const cliPath = await configuration.getCliPath(); - const env = await getSnykMcpEnv(configuration); + const env = getSnykMcpEnv(configuration); await ensureMcpServerInJson(configPath, SERVER_KEY, cliPath, ['mcp', '-t', 'stdio'], env); Logger.debug(`Ensured Windsurf MCP config at ${configPath}`); } @@ -136,7 +136,7 @@ export async function configureCursor(vscodeContext: vscode.ExtensionContext, co if (autoConfigureMcpServer) { const configPath = path.join(os.homedir(), '.cursor', 'mcp.json'); const cliPath = await configuration.getCliPath(); - const env = await getSnykMcpEnv(configuration); + const env = getSnykMcpEnv(configuration); await ensureMcpServerInJson(configPath, SERVER_KEY, cliPath, ['mcp', '-t', 'stdio'], env); Logger.debug(`Ensured Cursor MCP config at ${configPath}`); @@ -309,7 +309,7 @@ async function ensureInGitignore(patterns: string[]): Promise { ); } -async function getSnykMcpEnv(configuration: IConfiguration): Promise { +function getSnykMcpEnv(configuration: IConfiguration): Env { const env: Env = {}; if (configuration.organization) { env.SNYK_CFG_ORG = configuration.organization;