Skip to content

fix(lib): use absolute workspace path with canonicalization#16

Merged
bug-ops merged 1 commit intomainfrom
fix/workspace-absolute-path
Dec 27, 2025
Merged

fix(lib): use absolute workspace path with canonicalization#16
bug-ops merged 1 commit intomainfrom
fix/workspace-absolute-path

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Dec 27, 2025

Summary

  • Fix LSP server initialization failure when no workspace roots are configured
  • Add resolve_workspace_roots() helper that uses std::env::current_dir() with canonicalization
  • Prevent symlink-based path traversal via canonical path resolution
  • Add graceful fallback with warnings on errors

Problem

When no workspace roots were configured, mcpls used PathBuf::from(".") which resulted in file://. being sent to LSP servers. rust-analyzer and other LSP servers don't handle relative URIs, causing "LSP server process terminated unexpectedly" errors.

Solution

Extract workspace root resolution into a dedicated helper function that:

  1. Uses std::env::current_dir() to get the absolute path
  2. Canonicalizes the path to resolve symlinks (security improvement)
  3. Falls back gracefully with warnings if either operation fails

Test plan

  • All 108 tests pass (3 new unit tests added)
  • cargo clippy --all-targets --all-features -- -D warnings passes
  • cargo +nightly fmt --check passes
  • Manual testing: MCP tools now work correctly with default workspace

Review Notes

  • Addressed performance review: extracted helper to reduce double clone pattern
  • Addressed security review: added canonicalization for symlink protection
  • Addressed testing review: added comprehensive unit tests

- Extract resolve_workspace_roots() helper function
- Use std::env::current_dir() instead of relative "."
- Canonicalize paths to prevent symlink-based traversal
- Add graceful fallback on errors with warnings
- Add 3 unit tests for workspace root resolution

Fixes rust-analyzer "LSP server process terminated unexpectedly"
when no explicit workspace roots are configured.
@bug-ops bug-ops merged commit a9af7e1 into main Dec 27, 2025
14 checks passed
@bug-ops bug-ops deleted the fix/workspace-absolute-path branch December 27, 2025 19:37
@bug-ops bug-ops mentioned this pull request Dec 27, 2025
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant