Skip to content

fix: MCP roots take priority over CRB_WORKSPACE for multi-window support#164

Merged
ichoosetoaccept merged 1 commit intomainfrom
02-16-fix_mcp_roots_take_priority_over_crb_workspace_for_multi-window_support
Feb 16, 2026
Merged

fix: MCP roots take priority over CRB_WORKSPACE for multi-window support#164
ichoosetoaccept merged 1 commit intomainfrom
02-16-fix_mcp_roots_take_priority_over_crb_workspace_for_multi-window_support

Conversation

@ichoosetoaccept
Copy link
Member

@ichoosetoaccept ichoosetoaccept commented Feb 16, 2026

Summary

Flips workspace detection priority so MCP roots (per-window) take precedence over CRB_WORKSPACE (static env var). This fixes multi-window setups where a single shared MCP client config JSON would hardcode the wrong project path.

Problem

CRB_WORKSPACE was priority #1 in workspace detection. But MCP client config JSON is shared across all IDE windows — setting a static project path breaks when you have multiple windows open on different projects simultaneously.

Changes

  • server.py: Flip _get_workspace_cwd priority: MCP roots → CRB_WORKSPACE → process cwd
  • server.py: Update instructions to explain auto-detection from MCP roots
  • README.md: Remove CRB_WORKSPACE from default config snippet and settings table — it is an internal fallback for CI/scripts, not user-facing config
  • test_server.py: Rewrite TestGetWorkspaceCwd — roots now win over env var; added fallback tests for roots-empty and roots-exception cases (6 → 8 tests)

Detection cascade

1. MCP roots    — per-window, sent by the client (correct for multi-window)
2. CRB_WORKSPACE — static env var fallback (CI, scripts)
3. process cwd  — weakest, almost never useful

Verified: Windsurf sends MCP roots correctly — workspace detection works across multiple windows without any env var config.

MCP roots are per-window (sent by the client), so they correctly identify
the project in each IDE window. CRB_WORKSPACE is now an internal fallback
for CI/scripts where MCP roots are unavailable — removed from all README
config examples and settings table.

- Flip priority: MCP roots → CRB_WORKSPACE → process cwd
- Simplify README: single config snippet, no CRB_WORKSPACE
- Expanded dev setup with all config options commented
- Add fallback tests for roots-empty and roots-exception cases
Copy link
Member Author

ichoosetoaccept commented Feb 16, 2026

@greptile-apps
Copy link

greptile-apps bot commented Feb 16, 2026

Greptile Summary

Flips workspace detection priority so MCP roots take precedence over CRB_WORKSPACE env var, fixing multi-window setups where a single shared MCP client config JSON would hardcode the wrong project path.

  • Priority cascade changed: MCP roots → CRB_WORKSPACE → process cwd (previously CRB_WORKSPACE was chore(ci): bump astral-sh/setup-uv from 7.1.5 to 7.3.0 #1)
  • server.py: Reordered _get_workspace_cwd logic to check MCP roots first, falling back to env var only when roots are unavailable or empty
  • tests: Expanded from 6 to 8 test cases with comprehensive coverage of all fallback scenarios including empty roots and exception handling
  • README: Removed CRB_WORKSPACE from default config examples and settings table — it's now positioned as an internal fallback for CI/scripts, not a user-facing setting

The change is well-motivated: MCP roots are sent per-window by the client and provide the correct workspace for multi-window scenarios, while CRB_WORKSPACE is static and shared across all windows. Test coverage is thorough and validates all code paths.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is a simple priority reordering with clear motivation (multi-window support). All code paths are covered by thorough tests (8 test cases covering roots priority, env var fallback, empty roots, and exception handling). The logic is straightforward and the refactoring preserves backward compatibility by keeping CRB_WORKSPACE as a fallback.
  • No files require special attention

Important Files Changed

Filename Overview
src/codereviewbuddy/server.py Flips workspace detection priority so MCP roots take precedence over CRB_WORKSPACE env var, enabling correct multi-window support
tests/test_server.py Comprehensive test updates with 8 test cases covering all priority cascade scenarios including new fallback tests for empty roots and exceptions
README.md Removes CRB_WORKSPACE from default config examples and settings table, correctly positioning it as an internal fallback rather than user-facing config

Flowchart

flowchart TD
    Start[Tool call needs workspace] --> CheckCtx{Context available?}
    CheckCtx -->|Yes| CheckRoots[Try ctx.list_roots]
    CheckCtx -->|No| CheckEnv[Check CRB_WORKSPACE]
    
    CheckRoots --> RootsException{Exception?}
    RootsException -->|No| RootsEmpty{Roots empty?}
    RootsException -->|Yes| LogWarning[Log warning]
    
    RootsEmpty -->|No| ParseRoot[Parse first root URI]
    RootsEmpty -->|Yes| CheckEnv
    LogWarning --> CheckEnv
    
    ParseRoot --> ValidFile{Valid file:// URI?}
    ValidFile -->|Yes| ReturnRoot[Return root path]
    ValidFile -->|No| CheckEnv
    
    CheckEnv --> EnvSet{CRB_WORKSPACE set?}
    EnvSet -->|Yes| ReturnEnv[Return env var path]
    EnvSet -->|No| ReturnNone[Return None]
    
    ReturnRoot --> Success[Workspace detected]
    ReturnEnv --> Success
    ReturnNone --> UseCwd[Falls back to process cwd]
    
    style ReturnRoot fill:#90EE90
    style ReturnEnv fill:#FFD700
    style ReturnNone fill:#FFB6C1
    style Success fill:#90EE90
Loading

Last reviewed commit: 761dba5

Copy link
Member Author

ichoosetoaccept commented Feb 16, 2026

Merge activity

  • Feb 16, 11:54 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 16, 11:55 AM UTC: Graphite couldn't merge this PR because it had merge conflicts.

@ichoosetoaccept ichoosetoaccept changed the base branch from 02-16-docs_simplify_readme_installation_expand_dev_setup_with_all_config_options to graphite-base/164 February 16, 2026 11:54
@ichoosetoaccept ichoosetoaccept changed the base branch from graphite-base/164 to main February 16, 2026 11:54
@ichoosetoaccept ichoosetoaccept force-pushed the 02-16-fix_mcp_roots_take_priority_over_crb_workspace_for_multi-window_support branch from f6e8eec to 761dba5 Compare February 16, 2026 11:58
@ichoosetoaccept ichoosetoaccept merged commit 8a2eb5c into main Feb 16, 2026
11 checks passed
@ichoosetoaccept ichoosetoaccept deleted the 02-16-fix_mcp_roots_take_priority_over_crb_workspace_for_multi-window_support branch February 16, 2026 12:12
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