Skip to content

MCP Server: resolve files against content roots for Bazel/IJwB projects#3483

Open
St0rmingBr4in wants to merge 2 commits intoJetBrains:masterfrom
St0rmingBr4in:fix/mcp-server-bazel-content-roots
Open

MCP Server: resolve files against content roots for Bazel/IJwB projects#3483
St0rmingBr4in wants to merge 2 commits intoJetBrains:masterfrom
St0rmingBr4in:fix/mcp-server-bazel-content-roots

Conversation

@St0rmingBr4in
Copy link
Copy Markdown

@St0rmingBr4in St0rmingBr4in commented Apr 13, 2026

In Bazel projects using the IJwB plugin, projectBasePath points to the .ijwb/ subdirectory, while all source files reside in the workspace root (the parent directory). This causes resolveInProject() to reject every source file as "outside of the project directory", breaking get_symbol_info, get_file_problems, and all other MCP tools that operate on files.

Fix resolveInProject() to also try resolving paths against the project's content roots (via ProjectRootManager), and extend findMostRelevantProject() to match against content roots when looking up which project owns a given path.

This unblocks MCP tool usage in large Bazel monorepos (e.g., via Claude Code, Cursor, or VS Code Copilot) where IJwB is the project type.


Note

Medium Risk
Changes project path resolution and ownership matching, which could affect which files are considered in-scope and how outside-project path checks behave. Main risk is inadvertently allowing or misresolving paths if content roots are misconfigured or unavailable at runtime.

Overview
MCP Server now treats IntelliJ content roots as additional in-project roots when resolving relative file paths, so Bazel/IJwB projects (where projectBasePath is .ijwb/) can successfully access workspace source files.

resolveInProject() will fall back to resolving against each content root (and validates throwWhenOutside against all roots), and findMostRelevantProject() can match an absolute path to an open project via either projectBasePath or any content root.

Reviewed by Cursor Bugbot for commit 9ae51b0. Bugbot is set up for automated code reviews on this repo. Configure here.

In Bazel projects using the IJwB plugin, `projectBasePath` points to the
`.ijwb/` subdirectory, while all source files reside in the workspace
root (the parent directory). This causes `resolveInProject()` to reject
every source file as "outside of the project directory", breaking
`get_symbol_info`, `get_file_problems`, and all other MCP tools that
operate on files.

Fix `resolveInProject()` to also try resolving paths against the
project's content roots (via `ProjectRootManager`), and extend
`findMostRelevantProject()` to match against content roots when looking
up which project owns a given path.

This unblocks MCP tool usage in large Bazel monorepos (e.g., via Claude
Code, Cursor, or VS Code Copilot) where IJwB is the project type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@St0rmingBr4in St0rmingBr4in force-pushed the fix/mcp-server-bazel-content-roots branch from 5ea181f to 9ae51b0 Compare April 13, 2026 09:44
@St0rmingBr4in St0rmingBr4in marked this pull request as ready for review April 13, 2026 09:47
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 9ae51b0. Configure here.

Comment thread plugins/mcp-server/src/com/intellij/mcpserver/util/fs.util.kt Outdated
Comment thread plugins/mcp-server/src/com/intellij/mcpserver/util/fs.util.kt Outdated
…ting in findMostRelevantProject

- Normalize projectDirectory in allProjectRoots() so distinct() and
  startsWith() work consistently with the already-normalized content roots
- Use the matched root path (not the input path) in findMostRelevantProject
  pairs so sortedByDescending { nameCount } correctly prefers inner directories

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 16, 2026

You have used all of your free Bugbot PR reviews.

To receive reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

@St0rmingBr4in
Copy link
Copy Markdown
Author

@nerzhulart @BartvHelvert I've addressed the issues Cursor Bugbot reported. I would appreciate a review. Thanks !

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.

2 participants