diff --git a/src/extension.ts b/src/extension.ts index 86ca17e..0d7eeca 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1464,7 +1464,7 @@ class ClaudeChatProvider { try { const mcpConfigPath = this.getMCPConfigPath(); if (!mcpConfigPath) { - this._sendAndSaveMessage({ type: 'mcpServers', data: {} }); + this._postMessage({ type: 'mcpServers', data: {} }); return; } @@ -1474,7 +1474,8 @@ class ClaudeChatProvider { try { const content = await vscode.workspace.fs.readFile(mcpConfigUri); mcpConfig = JSON.parse(new TextDecoder().decode(content)); - } catch { + } catch (error) { + console.log('MCP config file not found or error reading:', error); // File doesn't exist, return empty servers } diff --git a/src/ui.ts b/src/ui.ts index f3d6596..dd4074b 100644 --- a/src/ui.ts +++ b/src/ui.ts @@ -1716,24 +1716,34 @@ const html = ` return; } - for (const [name, config] of Object.entries(servers)) { + for (const [name, config] of Object.entries(servers)) { const serverItem = document.createElement('div'); serverItem.className = 'mcp-server-item'; + // Defensive check for config structure + if (!config || typeof config !== 'object') { + console.error('Invalid config for server:', name, config); + continue; + } + + const serverType = config.type || 'stdio'; let configDisplay = ''; - if (config.type === 'stdio') { - configDisplay = \`Command: \${config.command}\`; - if (config.args) { + + if (serverType === 'stdio') { + configDisplay = \`Command: \${config.command || 'Not specified'}\`; + if (config.args && Array.isArray(config.args)) { configDisplay += \`
Args: \${config.args.join(' ')}\`; } + } else if (serverType === 'http' || serverType === 'sse') { + configDisplay = \`URL: \${config.url || 'Not specified'}\`; } else { - configDisplay = \`URL: \${config.url}\`; + configDisplay = \`Type: \${serverType}\`; } serverItem.innerHTML = \`
\${name}
-
\${config.type.toUpperCase()}
+
\${serverType.toUpperCase()}
\${configDisplay}