-
Notifications
You must be signed in to change notification settings - Fork 11.9k
refactor(@angular/cli): add architect target discovery to list_projects MCP tool #33208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
clydin
wants to merge
1
commit into
angular:main
Choose a base branch
from
clydin:feat/mcp-list-projects-targets
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+100
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -88,6 +88,11 @@ const listProjectsOutputSchema = { | |||||
| 'The default style language for the project (e.g., "scss"). ' + | ||||||
| 'This determines the file extension for new component styles.', | ||||||
| ), | ||||||
| targets: z | ||||||
| .array(z.string()) | ||||||
| .describe( | ||||||
| 'Available architect targets (e.g., ["build", "test", "lint", "e2e"]).', | ||||||
| ), | ||||||
| }), | ||||||
| ), | ||||||
| }), | ||||||
|
|
@@ -131,6 +136,7 @@ their types, and their locations. | |||||
| * Getting the \`selectorPrefix\` for a project before generating a new component to ensure it follows conventions. | ||||||
| * Identifying the major version of the Angular framework for each workspace, which is crucial for monorepos. | ||||||
| * Determining a project's primary function by inspecting its builder (e.g., '@angular-devkit/build-angular:browser' for an application). | ||||||
| * Identifying available architect targets (e.g., \`lint\`, \`e2e\`, \`serve\`, \`deploy\`) before attempting execution. | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid placing a comma immediately after abbreviations like 'e.g.' in user-facing messages.
Suggested change
References
|
||||||
| </Use Cases> | ||||||
| <Operational Notes> | ||||||
| * **Working Directory:** Shell commands for a project (like \`ng generate\`) **MUST** | ||||||
|
|
@@ -471,6 +477,7 @@ async function loadAndParseWorkspace( | |||||
| const fullSourceRoot = join(workspaceRoot, sourceRoot); | ||||||
| const unitTestFramework = getUnitTestFramework(project.targets.get('test')); | ||||||
| const styleLanguage = await getProjectStyleLanguage(project, ws, fullSourceRoot); | ||||||
| const targets = Array.from(project.targets.keys()); | ||||||
|
|
||||||
| projects.push({ | ||||||
| name, | ||||||
|
|
@@ -481,6 +488,7 @@ async function loadAndParseWorkspace( | |||||
| selectorPrefix: project.extensions['prefix'] as string, | ||||||
| unitTestFramework, | ||||||
| styleLanguage, | ||||||
| targets, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
92 changes: 92 additions & 0 deletions
92
packages/angular/cli/src/commands/mcp/tools/projects_spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { workspaces } from '@angular-devkit/core'; | ||
| import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { pathToFileURL } from 'node:url'; | ||
| import { AngularWorkspace } from '../../../utilities/config'; | ||
| import { createMockContext } from '../testing/test-utils'; | ||
| import { LIST_PROJECTS_TOOL } from './projects'; | ||
|
|
||
| describe('List Projects Tool', () => { | ||
| let mockWorkspace: AngularWorkspace; | ||
| let mockContext: ReturnType<typeof createMockContext>['context']; | ||
| let tempDir: string; | ||
| let allowedRoot: string; | ||
| let workspaceDir: string; | ||
|
|
||
| beforeEach(() => { | ||
| tempDir = mkdtempSync(join(tmpdir(), 'mcp-projects-tool-')); | ||
| allowedRoot = join(tempDir, 'allowed-root'); | ||
| workspaceDir = join(allowedRoot, 'workspace'); | ||
| mkdirSync(workspaceDir, { recursive: true }); | ||
| writeFileSync(join(workspaceDir, 'angular.json'), '{}'); | ||
| writeFileSync( | ||
| join(workspaceDir, 'package.json'), | ||
| JSON.stringify({ dependencies: { '@angular/core': '18.0.0' } }), | ||
| ); | ||
|
|
||
| const projects = new workspaces.ProjectDefinitionCollection(); | ||
| const targets = new workspaces.TargetDefinitionCollection(); | ||
| targets.set('build', { builder: '@angular-devkit/build-angular:application' }); | ||
| targets.set('test', { builder: '@angular/build:unit-test', options: { runner: 'vitest' } }); | ||
| targets.set('lint', { builder: '@angular-eslint/builder:lint' }); | ||
| targets.set('e2e', { builder: '@cypress/schematic:cypress' }); | ||
|
|
||
| projects.set('my-app', { | ||
| root: 'projects/my-app', | ||
| extensions: { projectType: 'application', prefix: 'app' }, | ||
| targets, | ||
| }); | ||
|
|
||
| mockWorkspace = { | ||
| projects, | ||
| extensions: {}, | ||
| basePath: workspaceDir, | ||
| filePath: join(workspaceDir, 'angular.json'), | ||
| } as unknown as AngularWorkspace; | ||
|
|
||
| spyOn(AngularWorkspace, 'load').and.resolveTo(mockWorkspace); | ||
|
|
||
| const { context } = createMockContext(); | ||
| mockContext = context; | ||
| mockContext.server = { | ||
| server: { | ||
| getClientCapabilities: jasmine.createSpy('getClientCapabilities').and.returnValue({ | ||
| roots: { listChanged: false }, | ||
| }), | ||
| listRoots: jasmine.createSpy('listRoots').and.resolveTo({ | ||
| roots: [{ uri: pathToFileURL(allowedRoot).href, name: 'allowed-root' }], | ||
| }), | ||
| }, | ||
| } as unknown as NonNullable<Parameters<typeof LIST_PROJECTS_TOOL.factory>[0]['server']>; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| it('should list workspaces and extract available architect targets', async () => { | ||
| const handler = await LIST_PROJECTS_TOOL.factory(mockContext); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const result = await (handler as any)({}); | ||
|
|
||
| expect(result.structuredContent).toBeDefined(); | ||
| const workspaces = result.structuredContent.workspaces; | ||
| expect(workspaces.length).toBe(1); | ||
| expect(workspaces[0].frameworkVersion).toBe('18'); | ||
|
|
||
| const projects = workspaces[0].projects; | ||
| expect(projects.length).toBe(1); | ||
| expect(projects[0].name).toBe('my-app'); | ||
| expect(projects[0].targets).toEqual(['build', 'test', 'lint', 'e2e']); | ||
| expect(projects[0].unitTestFramework).toBe('vitest'); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid placing a comma immediately after abbreviations like 'e.g.' in user-facing messages.
References