Skip to content

fix(@angular/cli): enforce MCP roots in get_best_practices tool#33653

Open
herdiyana256 wants to merge 2 commits into
angular:mainfrom
herdiyana256:fix-mcp-best-practices-roots-bypass
Open

fix(@angular/cli): enforce MCP roots in get_best_practices tool#33653
herdiyana256 wants to merge 2 commits into
angular:mainfrom
herdiyana256:fix-mcp-best-practices-roots-bypass

Conversation

@herdiyana256

Copy link
Copy Markdown
Contributor

`getVersionSpecificBestPractices()` resolves an npm package (and reads a file path declared in that package's `package.json`) starting from a caller-supplied `workspacePath`, without checking it against the client's declared MCP roots. Every other workspace-path-consuming MCP tool (`run_target`, `devserver_start`/`stop`/`wait_for_build`) validates this through `resolveWorkspaceAndProject()`'s `isAllowedWorkspacePath()` check; this tool never did.

Exports `isAllowedWorkspacePath()` from `workspace-utils.ts` and calls it in `getVersionSpecificBestPractices()` before resolving anything, falling back to the bundled guide when the path is outside the allowed roots, matching this file's existing fallback behavior for every other failure case in the function.

getVersionSpecificBestPractices() resolves an npm package (and reads a
file path declared in that package's package.json) starting from a
caller-supplied workspacePath, without checking it against the client's
declared MCP roots. Every other workspace-path-consuming MCP tool
(run_target, devserver_start/stop/wait_for_build) validates this through
resolveWorkspaceAndProject()'s isAllowedWorkspacePath() check; this tool
never did.

Export isAllowedWorkspacePath() from workspace-utils.ts and call it in
getVersionSpecificBestPractices() before resolving anything, falling back
to the bundled guide when the path is outside the allowed roots, matching
this file's existing fallback behavior for every other failure case.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request integrates workspace path validation into the best practices MCP tool. It exports isAllowedWorkspacePath and uses it within getVersionSpecificBestPractices to ensure the user-provided workspace path is within the allowed MCP roots, falling back to the bundled guide if it is not. Feedback suggests wrapping the isAllowedWorkspacePath check in a try-catch block to gracefully handle potential errors (such as non-existent paths or connection failures) and prevent unhandled exceptions.

Comment thread packages/angular/cli/src/commands/mcp/tools/best-practices.ts Outdated
…practices tool

isAllowedWorkspacePath can throw if the workspace path does not exist
(realpathSync) or if listRoots() fails against the connected client.
Wrap the check in a try-catch and fall back to the bundled guide on
any failure, matching this function's existing fallback behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant