From 12f6f907015de6dbab66681d236822f7d174a76f Mon Sep 17 00:00:00 2001 From: 777genius Date: Fri, 17 Apr 2026 20:07:35 +0300 Subject: [PATCH] fix(extensions): hide runtime-injected mcp diagnostics --- .../runtime/mcpDiagnosticsParser.ts | 44 +++++++++++++------ .../McpHealthDiagnosticsService.test.ts | 18 +++++--- 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/main/services/extensions/runtime/mcpDiagnosticsParser.ts b/src/main/services/extensions/runtime/mcpDiagnosticsParser.ts index 911b054f..ebc95bf2 100644 --- a/src/main/services/extensions/runtime/mcpDiagnosticsParser.ts +++ b/src/main/services/extensions/runtime/mcpDiagnosticsParser.ts @@ -1,3 +1,5 @@ +import { isInstalledMcpScope } from '@shared/utils/mcpScopes'; + import type { McpServerDiagnostic, McpServerHealthStatus } from '@shared/types/extensions'; interface McpDiagnoseJsonEntry { @@ -18,6 +20,21 @@ const EMBEDDED_HTTP_URL_PATTERN = /https?:\/\/[^\s"'`]+/gi; const SENSITIVE_FLAG_VALUE_PATTERN = /(--(?:api[-_]?key|access[-_]?token|auth[-_]?token|token|secret|password|client[-_]?secret))(?:=([^\s]+)|\s+([^\s]+))/gi; +function isPluginInjectedDiagnosticName(name: string): boolean { + return name.startsWith('plugin:'); +} + +function isExtensionsManagedDiagnosticEntry(entry: { + name: string; + scope?: 'local' | 'user' | 'project' | 'global' | 'dynamic' | 'managed'; +}): boolean { + if (isPluginInjectedDiagnosticName(entry.name)) { + return false; + } + + return entry.scope === undefined || isInstalledMcpScope(entry.scope); +} + function extractJsonObject(raw: string): T { const trimmed = raw.trim(); try { @@ -127,7 +144,8 @@ export function parseMcpDiagnosticsOutput(output: string): McpServerDiagnostic[] .map((line) => line.trim()) .filter((line) => line.length > 0 && !line.startsWith('Checking MCP server health')) .map((line) => parseDiagnosticLine(line, checkedAt)) - .filter((entry): entry is McpServerDiagnostic => entry !== null); + .filter((entry): entry is McpServerDiagnostic => entry !== null) + .filter((entry) => isExtensionsManagedDiagnosticEntry(entry)); } export function parseMcpDiagnosticsJsonOutput(output: string): McpServerDiagnostic[] { @@ -155,17 +173,17 @@ export function parseMcpDiagnosticsJsonOutput(output: string): McpServerDiagnost : 'unknown'; const rawLine = `${entry.name}: ${redactedTarget} - ${entry.statusLabel}`; - return [ - { - name: entry.name, - target: redactedTarget, - scope: entry.scope, - transport: entry.transport, - status: normalizedStatus, - statusLabel: entry.statusLabel, - rawLine, - checkedAt, - }, - ]; + const diagnostic = { + name: entry.name, + target: redactedTarget, + scope: entry.scope, + transport: entry.transport, + status: normalizedStatus, + statusLabel: entry.statusLabel, + rawLine, + checkedAt, + } satisfies McpServerDiagnostic; + + return isExtensionsManagedDiagnosticEntry(diagnostic) ? [diagnostic] : []; }); } diff --git a/test/main/services/extensions/McpHealthDiagnosticsService.test.ts b/test/main/services/extensions/McpHealthDiagnosticsService.test.ts index c3db915f..706d508f 100644 --- a/test/main/services/extensions/McpHealthDiagnosticsService.test.ts +++ b/test/main/services/extensions/McpHealthDiagnosticsService.test.ts @@ -16,20 +16,20 @@ browsermcp: npx @browsermcp/mcp@latest - ✓ Connected tavily-remote-mcp: npx -y mcp-remote https://mcp.tavily.com/mcp/?tavilyApiKey=test - ✗ Failed to connect alpic: https://mcp.alpic.ai (HTTP) - ! Needs authentication`); - expect(diagnostics).toHaveLength(5); + expect(diagnostics).toHaveLength(3); expect(diagnostics[0]).toMatchObject({ - name: 'plugin:context7:context7', - target: 'npx -y @upstash/context7-mcp', + name: 'browsermcp', + target: 'npx @browsermcp/mcp@latest', status: 'connected', statusLabel: 'Connected', }); - expect(diagnostics[3]).toMatchObject({ + expect(diagnostics[1]).toMatchObject({ name: 'tavily-remote-mcp', target: 'npx -y mcp-remote https://mcp.tavily.com/mcp/?tavilyApiKey=REDACTED', status: 'failed', statusLabel: 'Failed to connect', }); - expect(diagnostics[4]).toMatchObject({ + expect(diagnostics[2]).toMatchObject({ name: 'alpic', target: 'https://mcp.alpic.ai (HTTP)', status: 'needs-authentication', @@ -64,6 +64,14 @@ another log line`); status: 'timeout', statusLabel: 'Timed out', }, + { + name: 'plugin:context7:context7', + target: 'npx -y @upstash/context7-mcp', + scope: 'dynamic', + transport: 'stdio', + status: 'connected', + statusLabel: 'Connected', + }, ], }) );