fix(@angular/cli): enforce MCP roots in get_best_practices tool#33653
Open
herdiyana256 wants to merge 2 commits into
Open
fix(@angular/cli): enforce MCP roots in get_best_practices tool#33653herdiyana256 wants to merge 2 commits into
herdiyana256 wants to merge 2 commits into
Conversation
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.
There was a problem hiding this comment.
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
`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.