Skip to content

Commit e4baa7b

Browse files
committed
fix(@angular/cli): throw on out-of-roots workspace in best-practices tool
Aligns get_best_practices with resolveWorkspaceAndProject, which throws when a caller-supplied workspacePath falls outside the client's declared MCP roots rather than silently falling back. The try/catch now wraps only the isAllowedWorkspacePath call so genuine verification failures (e.g. a non-existent path) still fall back to the bundled guide, while a path outside the roots surfaces an actionable error pointing at list_projects.
1 parent 5c054c0 commit e4baa7b

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

packages/angular/cli/src/commands/mcp/tools/best-practices.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,9 @@ async function getVersionSpecificBestPractices(
9797
server: McpToolContext['server'],
9898
): Promise<{ content: string; source: string } | undefined> {
9999
if (server) {
100+
let isAllowed: boolean;
100101
try {
101-
if (!(await isAllowedWorkspacePath(server, workspacePath))) {
102-
logger.warn(
103-
`Workspace path is outside the allowed MCP roots: ${workspacePath}. ` +
104-
'Falling back to the bundled guide.',
105-
);
106-
107-
return undefined;
108-
}
102+
isAllowed = await isAllowedWorkspacePath(server, workspacePath);
109103
} catch (e) {
110104
logger.warn(
111105
`Failed to verify workspace path '${workspacePath}': ` +
@@ -114,6 +108,13 @@ async function getVersionSpecificBestPractices(
114108

115109
return undefined;
116110
}
111+
112+
if (!isAllowed) {
113+
throw new Error(
114+
`Workspace path is outside the allowed MCP roots: ${workspacePath}. ` +
115+
"You can use 'list_projects' to find available workspaces.",
116+
);
117+
}
117118
}
118119

119120
// 1. Resolve the path to package.json

0 commit comments

Comments
 (0)