Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>([[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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Loading