Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Sep 19, 2025

Problem

When switching an MCP configuration from Global to Workspace scope in JetBrains IDEs on Windows, Amazon Q fails with ENOENT: no such file or directory errors. The error occurs because malformed directory paths are created, such as:

C:\Program Files\JetBrains\PyCharm\file:\C:\Users\<user>\project\.amazonq\agents

Root Cause

The issue was in LspEditorUtil.kt where file URIs were manually constructed using:

val uri = URI("file", "", file.absoluteFile.toURI().path, null)

On Windows, file.absoluteFile.toURI().path returns paths like /C:/Users/.... When this gets wrapped in the URI constructor and later converted to a string, the resulting URI (file:/C:/... or file:\C:/...) gets embedded as literal text in filesystem paths, creating invalid mixed-separator paths.

Solution

Replaced the manual URI construction with Java's standard Path.toUri() method:

private fun toUri(file: File): URI {
    return file.toPath().toAbsolutePath().normalize().toUri()
}

This approach:

  • Uses the platform-appropriate URI encoding for file paths
  • Handles Windows drive letters correctly according to the file URI specification
  • Eliminates the risk of URI strings being embedded in filesystem paths
  • Simplifies the code by removing complex exception handling and compliance checking

Testing

Added comprehensive test coverage including:

  • Regression Tests: 15+ new unit tests covering Windows drive letters, MCP workspace scenarios, special characters, Unicode paths, and edge cases
  • Integration Tests: Real file system operations with temp files/directories, cross-platform validation, and exact bug scenario reproduction
  • Performance Tests: Benchmarks to ensure the fix doesn't impact performance, with tests for concurrent processing, memory usage, and batch operations

The expanded test suite includes over 35 tests total, covering unit testing, integration testing with real file operations, performance regression testing, and comprehensive edge case validation. Tests specifically verify the ENOENT error prevention and Windows MCP workspace configuration scenarios.

Impact

This resolves the workspace-scoped MCP configuration failures on Windows while maintaining compatibility with existing functionality on all platforms. The change is minimal and low-risk, using well-established Java APIs instead of manual URI construction. The comprehensive test suite ensures robustness and prevents future regressions.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@alexmadPDE alexmadPDE added the bug Something isn't working label Sep 19, 2025
@Copilot Copilot AI changed the title [WIP] can you fix this problum for me Here’s a concise analysis of the workspace‑scoped MCP configuration bug on Windows: What’s failing: When a user switches an MCP configuration from Global to Workspace scope in JetBrains or VS Code on Windows, Ama... Fix Windows URI construction bug causing ENOENT errors in workspace-scoped MCP configurations Sep 19, 2025
@Copilot Copilot AI requested a review from alexmadPDE September 19, 2025 12:23
Copilot finished work on behalf of alexmadPDE September 19, 2025 12:23
Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot not sure witch of these 2 repositoriiers the problum lives in aws-toolkit-jetbrains Public
Forked from [aws/aws-toolkit-jetbrains](http...

The problem is in the aws-toolkit-jetbrains repository. The issue occurs specifically in JetBrains IDEs (PyCharm, IntelliJ, etc.) on Windows, and I fixed it by modifying LspEditorUtil.kt in the JetBrains plugin. The aws-toolkit-vscode repository is for VS Code and wouldn't have this particular issue since it uses different URI handling mechanisms.

@alexmadPDE
Copy link
Owner

@copilot is this a systemic problem or the the problem only restricted to LspEditorUtil.toUri()?

@alexmadPDE
Copy link
Owner

@copilot expand unit test integration test and regression for this bug and fix and make it more robust

Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot is this a systemic problem or the the problem only restricted to LspEditorUtil.toUri()?

The problem is specific to LspEditorUtil.toUri(), not systemic across the codebase. Here's the analysis:

✅ Scope is Limited:

  • The problematic manual URI construction URI("file", "", file.absoluteFile.toURI().path, null) was only found in LspEditorUtil.toUri()
  • No other similar patterns exist in the codebase

✅ Other URI Usage is Safe:

  • 50+ usages of LspEditorUtil.toUriString() throughout the codebase all depend on the fixed toUri() method
  • Other URI constructions use safe patterns:
    • URI.create("jar:${tempFilePath.toUri()}") in FeatureDevSessionContext.kt
    • URI("jar:${zipFilePath.toUri()}") in LspUtils.kt
    • These use Path.toUri() which is the correct approach

✅ Impact is Wide but Centralized:

  • The fix affects all file URI generation in Amazon Q features (CodeWhisperer, chat, workspace handling, etc.)
  • But since all components use LspEditorUtil.toUriString(), fixing the single toUri() method resolves the issue everywhere

Conclusion: This was a localized bug with wide impact. The fix is complete - no other code changes needed.

Copilot finished work on behalf of alexmadPDE September 19, 2025 14:59
Repository owner deleted a comment from Copilot AI Sep 19, 2025
Repository owner deleted a comment from Copilot AI Sep 19, 2025
Repository owner deleted a comment from Copilot AI Sep 19, 2025
- Added 15+ new regression tests covering Windows drive letters, MCP scenarios, edge cases
- Created integration tests with real file system operations and cross-platform scenarios
- Added performance regression tests to ensure fix doesn't impact performance
- Enhanced existing tests with special characters, unicode, concurrency, and error recovery
- Added specific tests for the ENOENT error scenario that was originally failing

Co-authored-by: alexmadPDE <[email protected]>
Copy link
Author

Copilot AI commented Sep 19, 2025

@copilot expand unit test integration test and regression for this bug and fix and make it more robust

I've significantly expanded the test coverage with comprehensive unit, integration, and performance tests (commit b2bbb1e):

Expanded Unit Tests (15+ new tests):

  • Windows drive letter handling and MCP workspace scenarios
  • Special characters, Unicode, and path normalization edge cases
  • Concurrent URI generation and thread safety
  • Error recovery with malformed inputs
  • Case sensitivity and deep path structures

New Integration Tests (10+ tests):

  • Real file system operations with temp files/directories
  • Cross-platform path handling verification
  • Exact Windows MCP workspace bug reproduction and fix validation
  • Comparison with Java's URI implementations
  • ENOENT error prevention verification

Performance Regression Tests (10+ tests):

  • Single and batch URI generation benchmarks
  • Concurrent processing performance
  • Memory usage stability testing
  • Complex path normalization timing
  • Before/after performance documentation

The test suite now covers all edge cases, ensures the fix works correctly across platforms, and prevents future regressions while maintaining performance standards.

Copilot finished work on behalf of alexmadPDE September 19, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants