Skip to content

Commit ab2f994

Browse files
committed
refactor(@angular/cli): add a get best practices guide MCP tool
The Angular CLI's stdio-based MCP server now contains a tool to get an Angular best practices guide. This is in addition to a resource with the same content. The tool provides a description that strongly encourages the use of this tool and its content when performing Angular related tasks. This is useful in cases where MCP resource usage is not available or the resource would need to manually be added as context for specific use cases.
1 parent 3faa3b4 commit ab2f994

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

packages/angular/cli/src/commands/mcp/mcp-server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import path from 'node:path';
1212
import { z } from 'zod';
1313
import type { AngularWorkspace } from '../../utilities/config';
1414
import { VERSION } from '../../utilities/version';
15+
import { registerBestPracticesTool } from './tools/best-practices';
1516
import { registerDocSearchTool } from './tools/doc-search';
1617

1718
export async function createMcpServer(context: {
@@ -48,6 +49,8 @@ export async function createMcpServer(context: {
4849
},
4950
);
5051

52+
await registerBestPracticesTool(server);
53+
5154
server.registerTool(
5255
'list_projects',
5356
{
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
10+
import { readFile } from 'node:fs/promises';
11+
import path from 'node:path';
12+
13+
export async function registerBestPracticesTool(server: McpServer): Promise<void> {
14+
server.registerTool(
15+
'get_best_practices',
16+
{
17+
title: 'Get Angular Coding Best Practices Guide',
18+
description:
19+
'You **MUST** use this tool to retrieve the Angular Best Practices Guide ' +
20+
'before any interaction with Angular code (creating, analyzing, modifying). ' +
21+
'It is mandatory to follow this guide to ensure all code adheres to ' +
22+
'modern standards, including standalone components, typed forms, and ' +
23+
'modern control flow. This is the first step for any Angular task.',
24+
annotations: {
25+
readOnlyHint: true,
26+
openWorldHint: false,
27+
},
28+
},
29+
async () => {
30+
const text = await readFile(
31+
path.join(__dirname, '..', 'instructions', 'best-practices.md'),
32+
'utf-8',
33+
);
34+
35+
return {
36+
content: [
37+
{
38+
type: 'resource',
39+
resource: {
40+
uri: 'instructions://best-practices',
41+
mimeType: 'text/markdown',
42+
text,
43+
annotations: {
44+
audience: ['user', 'assistant'],
45+
priority: 1,
46+
},
47+
},
48+
},
49+
],
50+
};
51+
},
52+
);
53+
}

0 commit comments

Comments
 (0)