fix(@angular/cli): enforce MCP roots in get_best_practices tool - #33653
fix(@angular/cli): enforce MCP roots in get_best_practices tool#33653herdiyana256 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.
|
Gentle bump on this one. It has been open two weeks without a reviewer assigned. #33654, from the same MCP batch, was reviewed and merged within a few days, so I suspect this one just slipped past the queue rather than being deliberately parked. Happy to rebase or split it if that helps. @clydin if you are the right person for the MCP tools area, would you mind taking a look or routing it to whoever is? |
`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.