diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.test.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.test.ts index 0667d149cc..93440ac2cb 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.test.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.test.ts @@ -1489,8 +1489,37 @@ describe('McpManager error handling', () => { // Test that getConfigLoadErrors returns the expected error messages const errors = mgr.getConfigLoadErrors() expect(errors).to.not.be.undefined - expect(errors).to.include('File: file1.json, Error: File not found error') - expect(errors).to.include('File: serverA, Error: Missing command error') + expect(errors).to.include('File: `file1.json`, Error: File not found error') + expect(errors).to.include('File: `serverA`, Error: Missing command error') + }) + + it('wraps file paths in code spans so Windows paths render correctly in markdown', async () => { + // A Windows path segment like "\.aws" would have its backslash stripped when + // rendered as markdown unless the path is wrapped in a code span. + const windowsPath = 'C:\\Users\\me\\.aws\\amazonq\\mcp.json' + const mockErrors = new Map([[windowsPath, 'Invalid JSON error']]) + + loadStub = sinon.stub(mcpUtils, 'loadAgentConfig').resolves({ + servers: new Map(), + serverNameMapping: new Map(), + errors: mockErrors, + agentConfig: { + name: 'test-agent', + description: 'Test agent', + mcpServers: {}, + tools: [], + allowedTools: [], + toolsSettings: {}, + includedFiles: [], + resources: [], + }, + }) + + const mgr = await McpManager.init([], features) + await mgr.discoverAllServers() + + const errors = mgr.getConfigLoadErrors() + expect(errors).to.include(`File: \`${windowsPath}\`, Error: Invalid JSON error`) }) it('returns undefined when no errors exist', async () => { diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts index 61e7ea75fe..3ed95ac434 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpManager.ts @@ -1630,7 +1630,10 @@ export class McpManager { if (server === 'registry') { return error } - return `File: ${server}, Error: ${error}` + // Wrap the file path/server name in a code span. This message is rendered + // as markdown in the UI, so an unescaped Windows path (e.g. a segment like + // "\.aws") would have its backslash stripped and be shown incorrectly. + return `File: \`${server}\`, Error: ${error}` }) .join('\n\n') } diff --git a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts index 6945542078..090549f90d 100644 --- a/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts +++ b/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/mcp/mcpUtils.ts @@ -74,7 +74,7 @@ export async function loadMcpServerConfigs( try { rawText = (await workspace.fs.readFile(fsPath)).toString() } catch (e: any) { - const errorMsg = `Failed to read MCP config at ${fsPath}: ${e.message}` + const errorMsg = `Failed to read MCP config at \`${fsPath}\`: ${e.message}` logging.warn(errorMsg) configErrors.set(`${fsPath}`, errorMsg) continue @@ -84,14 +84,14 @@ export async function loadMcpServerConfigs( try { json = JSON.parse(rawText) } catch (e: any) { - const errorMsg = `Invalid JSON in MCP config at ${fsPath}: ${e.message}` + const errorMsg = `Invalid JSON in MCP config at \`${fsPath}\`: ${e.message}` logging.warn(errorMsg) configErrors.set(`${fsPath}`, errorMsg) continue } if (!json.mcpServers || typeof json.mcpServers !== 'object') { - const errorMsg = `MCP config at ${fsPath} missing or invalid 'mcpServers' field` + const errorMsg = `MCP config at \`${fsPath}\` missing or invalid 'mcpServers' field` logging.warn(errorMsg) configErrors.set(`${fsPath}`, errorMsg) continue