Skip to content
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
21 changes: 15 additions & 6 deletions packages/angular/cli/src/commands/mcp/tools/best-practices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,21 @@ import { declareTool } from './tool-registry';
export const BEST_PRACTICES_TOOL = declareTool({
name: '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.',
description: `
<Purpose>
Retrieves the official Angular Best Practices Guide. This guide contains the essential rules and conventions
that **MUST** be followed for any task involving the creation, analysis, or modification of Angular code.
</Purpose>
<Use Cases>
* As a mandatory first step before writing or modifying any Angular code to ensure adherence to modern standards.
* To learn about key concepts like standalone components, typed forms, and modern control flow syntax (@if, @for, @switch).
* To verify that existing code aligns with current Angular conventions before making changes.
</Use Cases>
<Operational Notes>
* The content of this guide is non-negotiable and reflects the official, up-to-date standards for Angular development.
* You **MUST** internalize and apply the principles from this guide in all subsequent Angular-related tasks.
* Failure to adhere to these best practices will result in suboptimal and outdated code.
</Operational Notes>`,
isReadOnly: true,
isLocalOnly: true,
factory: () => {
Expand Down
53 changes: 40 additions & 13 deletions packages/angular/cli/src/commands/mcp/tools/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,39 @@ type FindExampleInput = z.infer<typeof findExampleInputSchema>;
export const FIND_EXAMPLE_TOOL = declareTool({
name: 'find_examples',
title: 'Find Angular Code Examples',
description:
'Before writing or modifying any Angular code including templates, ' +
'**ALWAYS** use this tool to find current best-practice examples. ' +
'This is critical for ensuring code quality and adherence to modern Angular standards. ' +
'This tool searches a curated database of approved Angular code examples and returns the most relevant results for your query. ' +
'Example Use Cases: ' +
"1) Creating new components, directives, or services (e.g., query: 'standalone component' or 'signal input'). " +
"2) Implementing core features (e.g., query: 'lazy load route', 'httpinterceptor', or 'route guard'). " +
"3) Refactoring existing code to use modern patterns (e.g., query: 'ngfor trackby' or 'form validation').",
description: `
<Purpose>
Augments your knowledge base with a curated database of official, best-practice code examples,
focusing on **modern, new, and recently updated** Angular features. This tool acts as a RAG
(Retrieval-Augmented Generation) source, providing ground-truth information on the latest Angular
APIs and patterns. You **MUST** use it to understand and apply current standards when working with
new or evolving features.
</Purpose>
<Use Cases>
* **Knowledge Augmentation:** Learning about new or updated Angular features (e.g., query: 'signal input' or 'deferrable views').
* **Modern Implementation:** Finding the correct modern syntax for features
(e.g., query: 'functional route guard' or 'http client with fetch').
* **Refactoring to Modern Patterns:** Upgrading older code by finding examples of new syntax
(e.g., query: 'built-in control flow' to replace "*ngIf').
</Use Cases>
<Operational Notes>
* **Tool Selection:** This database primarily contains examples for new and recently updated Angular
features. For established, core features, the main documentation (via the
\`search_documentation\` tool) may be a better source of information.
* The examples in this database are the single source of truth for modern Angular coding patterns.
* The search query uses a powerful full-text search syntax (FTS5). Refer to the 'query'
parameter description for detailed syntax rules and examples.
</Operational Notes>`,
inputSchema: findExampleInputSchema.shape,
outputSchema: {
examples: z.array(
z.object({
content: z
.string()
.describe('A complete, self-contained Angular code example in Markdown format.'),
}),
),
},
isReadOnly: true,
isLocalOnly: true,
shouldRegister: ({ logger }) => {
Expand Down Expand Up @@ -96,14 +119,18 @@ async function createFindExampleHandler({ exampleDatabasePath }: McpToolContext)

const sanitizedQuery = escapeSearchQuery(query);

// Query database and return results as text content
const content = [];
// Query database and return results
const examples = [];
const textContent = [];
for (const exampleRecord of queryStatement.all(sanitizedQuery)) {
content.push({ type: 'text' as const, text: exampleRecord['content'] as string });
const exampleContent = exampleRecord['content'] as string;
examples.push({ content: exampleContent });
textContent.push({ type: 'text' as const, text: exampleContent });
}

return {
content,
content: textContent,
structuredContent: { examples },
};
};
}
Expand Down