@@ -87,72 +87,42 @@ const modernizeInputSchema = z.object({
8787
8888export type ModernizeInput = z . infer < typeof modernizeInputSchema > ;
8989
90- export async function runModernization ( input : ModernizeInput ) {
91- try {
92- if ( ! input . transformations || input . transformations . length === 0 ) {
93- const instructions = [
94- 'See https://angular.dev/best-practices for Angular best practices. ' +
95- 'You can call this tool if you have specific transformation you want to run.' ,
96- ] ;
97-
98- return {
99- content : [
100- {
101- type : 'text' as const ,
102- text : JSON . stringify ( {
103- instructions,
104- } ) ,
105- } ,
106- ] ,
107- structuredContent : {
108- instructions,
109- } ,
110- } ;
111- }
112-
113- const transformationsToRun = TRANSFORMATIONS . filter ( ( t ) =>
114- input . transformations ?. includes ( t . name ) ,
115- ) ;
90+ function generateInstructions ( transformationNames : string [ ] ) : string [ ] {
91+ if ( transformationNames . length === 0 ) {
92+ return [
93+ 'See https://angular.dev/best-practices for Angular best practices. ' +
94+ 'You can call this tool if you have specific transformation you want to run.' ,
95+ ] ;
96+ }
11697
117- const allInstructions : string [ ] = [ ] ;
98+ const instructions : string [ ] = [ ] ;
99+ const transformationsToRun = TRANSFORMATIONS . filter ( ( t ) => transformationNames ?. includes ( t . name ) ) ;
118100
119- for ( const transformation of transformationsToRun ) {
120- let transformationInstructions = '' ;
121- if ( transformation . instructions ) {
122- transformationInstructions = transformation . instructions ;
123- } else {
124- // If no instructions are included, default to running a cli schematic with the transformation name.
125- const command = `ng generate @angular/core:${ transformation . name } ` ;
126- transformationInstructions = `To run the ${ transformation . name } migration, execute the following command: \`${ command } \`.` ;
127- }
128- if ( transformation . documentationUrl ) {
129- transformationInstructions += `\nFor more information, see ${ transformation . documentationUrl } .` ;
130- }
131- allInstructions . push ( transformationInstructions ) ;
101+ for ( const transformation of transformationsToRun ) {
102+ let transformationInstructions = '' ;
103+ if ( transformation . instructions ) {
104+ transformationInstructions = transformation . instructions ;
105+ } else {
106+ // If no instructions are included, default to running a cli schematic with the transformation name.
107+ const command = `ng generate @angular/core:${ transformation . name } ` ;
108+ transformationInstructions = `To run the ${ transformation . name } migration, execute the following command: \`${ command } \`.` ;
132109 }
110+ if ( transformation . documentationUrl ) {
111+ transformationInstructions += `\nFor more information, see ${ transformation . documentationUrl } .` ;
112+ }
113+ instructions . push ( transformationInstructions ) ;
114+ }
133115
134- const structuredContent = {
135- instructions : allInstructions . length ? allInstructions : undefined ,
136- } ;
116+ return instructions ;
117+ }
137118
138- return {
139- content : [ { type : 'text' as const , text : JSON . stringify ( structuredContent ) } ] ,
140- structuredContent,
141- } ;
142- } catch ( e ) {
143- const message = e instanceof Error ? e . message : 'An unknown error occurred.' ;
119+ export async function runModernization ( input : ModernizeInput ) {
120+ const structuredContent = { instructions : generateInstructions ( input . transformations ?? [ ] ) } ;
144121
145- return {
146- content : [
147- {
148- type : 'text' as const ,
149- text : `Failed to run modernization migrations: ${ message } ` ,
150- } ,
151- ] ,
152- structuredContent : { } ,
153- isError : true ,
154- } ;
155- }
122+ return {
123+ content : [ { type : 'text' as const , text : JSON . stringify ( structuredContent ) } ] ,
124+ structuredContent,
125+ } ;
156126}
157127
158128export function registerModernizeTool ( server : McpServer ) : void {
0 commit comments