@@ -42,16 +42,39 @@ type FindExampleInput = z.infer<typeof findExampleInputSchema>;
42
42
export const FIND_EXAMPLE_TOOL = declareTool ( {
43
43
name : 'find_examples' ,
44
44
title : 'Find Angular Code Examples' ,
45
- description :
46
- 'Before writing or modifying any Angular code including templates, ' +
47
- '**ALWAYS** use this tool to find current best-practice examples. ' +
48
- 'This is critical for ensuring code quality and adherence to modern Angular standards. ' +
49
- 'This tool searches a curated database of approved Angular code examples and returns the most relevant results for your query. ' +
50
- 'Example Use Cases: ' +
51
- "1) Creating new components, directives, or services (e.g., query: 'standalone component' or 'signal input'). " +
52
- "2) Implementing core features (e.g., query: 'lazy load route', 'httpinterceptor', or 'route guard'). " +
53
- "3) Refactoring existing code to use modern patterns (e.g., query: 'ngfor trackby' or 'form validation')." ,
45
+ description : `
46
+ <Purpose>
47
+ Augments your knowledge base with a curated database of official, best-practice code examples,
48
+ focusing on **modern, new, and recently updated** Angular features. This tool acts as a RAG
49
+ (Retrieval-Augmented Generation) source, providing ground-truth information on the latest Angular
50
+ APIs and patterns. You **MUST** use it to understand and apply current standards when working with
51
+ new or evolving features.
52
+ </Purpose>
53
+ <Use Cases>
54
+ * **Knowledge Augmentation:** Learning about new or updated Angular features (e.g., query: 'signal input' or 'deferrable views').
55
+ * **Modern Implementation:** Finding the correct modern syntax for features
56
+ (e.g., query: 'functional route guard' or 'http client with fetch').
57
+ * **Refactoring to Modern Patterns:** Upgrading older code by finding examples of new syntax
58
+ (e.g., query: 'built-in control flow' to replace "*ngIf').
59
+ </Use Cases>
60
+ <Operational Notes>
61
+ * **Tool Selection:** This database primarily contains examples for new and recently updated Angular
62
+ features. For established, core features, the main documentation (via the
63
+ \`search_documentation\` tool) may be a better source of information.
64
+ * The examples in this database are the single source of truth for modern Angular coding patterns.
65
+ * The search query uses a powerful full-text search syntax (FTS5). Refer to the 'query'
66
+ parameter description for detailed syntax rules and examples.
67
+ </Operational Notes>` ,
54
68
inputSchema : findExampleInputSchema . shape ,
69
+ outputSchema : {
70
+ examples : z . array (
71
+ z . object ( {
72
+ content : z
73
+ . string ( )
74
+ . describe ( 'A complete, self-contained Angular code example in Markdown format.' ) ,
75
+ } ) ,
76
+ ) ,
77
+ } ,
55
78
isReadOnly : true ,
56
79
isLocalOnly : true ,
57
80
shouldRegister : ( { logger } ) => {
@@ -96,14 +119,18 @@ async function createFindExampleHandler({ exampleDatabasePath }: McpToolContext)
96
119
97
120
const sanitizedQuery = escapeSearchQuery ( query ) ;
98
121
99
- // Query database and return results as text content
100
- const content = [ ] ;
122
+ // Query database and return results
123
+ const examples = [ ] ;
124
+ const textContent = [ ] ;
101
125
for ( const exampleRecord of queryStatement . all ( sanitizedQuery ) ) {
102
- content . push ( { type : 'text' as const , text : exampleRecord [ 'content' ] as string } ) ;
126
+ const exampleContent = exampleRecord [ 'content' ] as string ;
127
+ examples . push ( { content : exampleContent } ) ;
128
+ textContent . push ( { type : 'text' as const , text : exampleContent } ) ;
103
129
}
104
130
105
131
return {
106
- content,
132
+ content : textContent ,
133
+ structuredContent : { examples } ,
107
134
} ;
108
135
} ;
109
136
}
0 commit comments