diff --git a/packages/angular/cli/src/commands/mcp/mcp-server.ts b/packages/angular/cli/src/commands/mcp/mcp-server.ts index 13ba22fbc688..1ca13f8dde3b 100644 --- a/packages/angular/cli/src/commands/mcp/mcp-server.ts +++ b/packages/angular/cli/src/commands/mcp/mcp-server.ts @@ -12,6 +12,7 @@ import path from 'node:path'; import { z } from 'zod'; import type { AngularWorkspace } from '../../utilities/config'; import { VERSION } from '../../utilities/version'; +import { registerBestPracticesTool } from './tools/best-practices'; import { registerDocSearchTool } from './tools/doc-search'; export async function createMcpServer(context: { @@ -48,6 +49,8 @@ export async function createMcpServer(context: { }, ); + registerBestPracticesTool(server); + server.registerTool( 'list_projects', { diff --git a/packages/angular/cli/src/commands/mcp/tools/best-practices.ts b/packages/angular/cli/src/commands/mcp/tools/best-practices.ts new file mode 100644 index 000000000000..c6718a91e3ec --- /dev/null +++ b/packages/angular/cli/src/commands/mcp/tools/best-practices.ts @@ -0,0 +1,45 @@ +/** + * @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 type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; +import { readFile } from 'node:fs/promises'; +import path from 'node:path'; + +export function registerBestPracticesTool(server: McpServer): void { + server.registerTool( + 'get_best_practices', + { + title: 'Get Angular Coding Best Practices Guide', + description: + 'You **MUST** use this tool to retrieve the Angular Best Practices Guide ' + + 'before any interaction with Angular code (creating, analyzing, modifying). ' + + 'It is mandatory to follow this guide to ensure all code adheres to ' + + 'modern standards, including standalone components, typed forms, and ' + + 'modern control flow. This is the first step for any Angular task.', + annotations: { + readOnlyHint: true, + openWorldHint: false, + }, + }, + async () => { + const text = await readFile( + path.join(__dirname, '..', 'instructions', 'best-practices.md'), + 'utf-8', + ); + + return { + content: [ + { + type: 'text', + text, + }, + ], + }; + }, + ); +}