Skip to content

refactor(@angular/cli): expand MCP tool/resource descriptions #30643

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/angular/cli/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ts_project(
":node_modules/pacote",
":node_modules/resolve",
":node_modules/yargs",
":node_modules/zod",
"//:node_modules/@angular/core",
"//:node_modules/@types/ini",
"//:node_modules/@types/node",
Expand Down
3 changes: 2 additions & 1 deletion packages/angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"pacote": "21.0.0",
"resolve": "1.22.10",
"semver": "7.7.2",
"yargs": "18.0.0"
"yargs": "18.0.0",
"zod": "3.25.75"
},
"ng-update": {
"migrations": "@schematics/angular/migrations/migration-collection.json",
Expand Down
79 changes: 66 additions & 13 deletions packages/angular/cli/src/commands/mcp/mcp-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { readFile } from 'node:fs/promises';
import path from 'node:path';
import { z } from 'zod';
import type { AngularWorkspace } from '../../utilities/config';
import { VERSION } from '../../utilities/version';

Expand All @@ -28,9 +29,12 @@ export async function createMcpServer(context: {
'instructions',
'instructions://best-practices',
{
title: 'Angular System Instructions',
title: 'Angular Best Practices and Code Generation Guide',
description:
'A set of instructions to help LLMs generate correct code that follows Angular best practices.',
"A comprehensive guide detailing Angular's best practices for code generation and development." +
' This guide should be used as a reference by an LLM to ensure any generated code' +
' adheres to modern Angular standards, including the use of standalone components,' +
' typed forms, modern control flow syntax, and other current conventions.',
mimeType: 'text/markdown',
},
async () => {
Expand All @@ -46,32 +50,81 @@ export async function createMcpServer(context: {
server.registerTool(
'list_projects',
{
title: 'List projects',
title: 'List Angular Projects',
description:
'List projects within an Angular workspace.' +
' This information is read from the `angular.json` file at the root path of the Angular workspace',
'Lists the names of all applications and libraries defined within an Angular workspace. ' +
'It reads the `angular.json` configuration file to identify the projects. ',
annotations: {
readOnlyHint: true,
},
outputSchema: {
projects: z.array(
z.object({
name: z
.string()
.describe('The name of the project, as defined in the `angular.json` file.'),
type: z
.enum(['application', 'library'])
.optional()
.describe(`The type of the project, either 'application' or 'library'.`),
root: z
.string()
.describe('The root directory of the project, relative to the workspace root.'),
sourceRoot: z
.string()
.describe(
`The root directory of the project's source files, relative to the workspace root.`,
),
selectorPrefix: z
.string()
.optional()
.describe(
'The prefix to use for component selectors.' +
` For example, a prefix of 'app' would result in selectors like '<app-my-component>'.`,
),
}),
),
},
},
() => {
if (!context.workspace) {
async () => {
const { workspace } = context;

if (!workspace) {
return {
content: [
{
type: 'text',
text: 'Not within an Angular project.',
type: 'text' as const,
text:
'No Angular workspace found.' +
' An `angular.json` file, which marks the root of a workspace,' +
' could not be located in the current directory or any of its parent directories.',
},
],
};
}

const projects = [];
// Convert to output format
for (const [name, project] of workspace.projects.entries()) {
projects.push({
name,
type: project.extensions['projectType'] as 'application' | 'library' | undefined,
root: project.root,
sourceRoot: project.sourceRoot ?? path.posix.join(project.root, 'src'),
selectorPrefix: project.extensions['prefix'] as string,
});
}

// The structuredContent field is newer and may not be supported by all hosts.
// A text representation of the content is also provided for compatibility.
return {
content: [
{
type: 'text',
text:
'Projects in the Angular workspace: ' +
[...context.workspace.projects.keys()].join(','),
type: 'text' as const,
text: `Projects in the Angular workspace:\n${JSON.stringify(projects)}`,
},
],
structuredContent: { projects },
};
},
);
Expand Down
23 changes: 13 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.