Skip to content

Commit af89014

Browse files
committed
refactor(@angular/cli): rewrite modernize MCP tool's description and schemas for clarity
The `modernize` MCP tool's description and schemas are rewritten to clarify its primary function: providing instructions and commands for an AI model to execute. The new description includes detailed operational notes on how to use the tool's output, especially for the multi-step 'standalone' migration. The input and output schema descriptions are also enhanced to provide better context.
1 parent dae7c71 commit af89014

1 file changed

Lines changed: 38 additions & 20 deletions

File tree

packages/angular/cli/src/commands/mcp/tools/modernize.ts

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,11 @@ const modernizeInputSchema = z.object({
7070
// Casting to [string, ...string[]] since the enum definition requires a nonempty array.
7171
transformations: z
7272
.array(z.enum(TRANSFORMATIONS.map((t) => t.name) as [string, ...string[]]))
73-
.optional(),
73+
.optional()
74+
.describe(
75+
'A list of specific transformations to get instructions for. ' +
76+
'If omitted, general guidance is provided.',
77+
),
7478
});
7579

7680
export type ModernizeInput = z.infer<typeof modernizeInputSchema>;
@@ -93,10 +97,14 @@ function generateInstructions(transformationNames: string[]): string[] {
9397
} else {
9498
// If no instructions are included, default to running a cli schematic with the transformation name.
9599
const command = `ng generate @angular/core:${transformation.name}`;
96-
transformationInstructions = `To run the ${transformation.name} migration, execute the following command: \`${command}\`.`;
100+
transformationInstructions = `To run the ${transformation.name} migration, execute the following command:
101+
102+
${command}
103+
.`;
97104
}
98105
if (transformation.documentationUrl) {
99-
transformationInstructions += `\nFor more information, see ${transformation.documentationUrl}.`;
106+
transformationInstructions += `
107+
For more information, see ${transformation.documentationUrl}.`;
100108
}
101109
instructions.push(transformationInstructions);
102110
}
@@ -116,28 +124,38 @@ export async function runModernization(input: ModernizeInput) {
116124
export const MODERNIZE_TOOL = declareTool({
117125
name: 'modernize',
118126
title: 'Modernize Angular Code',
119-
description:
120-
'<Purpose>\n' +
121-
'This tool modernizes Angular code by applying the latest best practices and syntax improvements, ' +
122-
'ensuring it is idiomatic, readable, and maintainable.\n\n' +
123-
'</Purpose>\n' +
124-
'<Use Cases>\n' +
125-
'* After generating new code: Run this tool immediately after creating new Angular components, directives, ' +
126-
'or services to ensure they adhere to modern standards.\n' +
127-
'* On existing code: Apply to existing TypeScript files (.ts) and Angular templates (.html) to update ' +
128-
'them with the latest features, such as the new built-in control flow syntax.\n\n' +
129-
'* When the user asks for a specific transformation: When the transformation list is populated, ' +
130-
'these specific ones will be ran on the inputs.\n' +
131-
'</Use Cases>\n' +
132-
'<Transformations>\n' +
133-
TRANSFORMATIONS.map((t) => `* ${t.name}: ${t.description}`).join('\n') +
134-
'\n</Transformations>\n',
127+
description: `
128+
<Purpose>
129+
Provides instructions and commands for modernizing Angular code to align with the latest best
130+
practices and syntax. This tool helps ensure code is idiomatic, readable, and maintainable by
131+
generating the exact steps needed to perform specific migrations.
132+
</Purpose>
133+
<Use Cases>
134+
* **Applying Specific Migrations:** Get the precise commands to update code to modern patterns
135+
(e.g., selecting 'control-flow-migration' to replace *ngIf with @if).
136+
* **Upgrading Existing Code:** Modernize an entire project by running the 'standalone' migration,
137+
which provides a multi-step command sequence.
138+
* **Discovering Available Migrations:** Call the tool with no transformations to get a link to the
139+
general best practices guide.
140+
</Use Cases>
141+
<Operational Notes>
142+
* **Execution:** This tool **provides instructions**, which you **MUST** then execute as shell commands.
143+
It does not modify code directly.
144+
* **Standalone Migration:** The 'standalone' transformation is a special, multi-step process.
145+
You **MUST** execute the commands in the exact order provided and validate your application
146+
between each step.
147+
* **Transformation List:** The following transformations are available:
148+
${TRANSFORMATIONS.map((t) => ` * ${t.name}: ${t.description}`).join('\n')}
149+
</Operational Notes>`,
135150
inputSchema: modernizeInputSchema.shape,
136151
outputSchema: {
137152
instructions: z
138153
.array(z.string())
139154
.optional()
140-
.describe('A list of instructions on how to run the migrations.'),
155+
.describe(
156+
'A list of instructions and shell commands to run the requested modernizations. ' +
157+
'Each string in the array is a separate step or command.',
158+
),
141159
},
142160
isLocalOnly: true,
143161
isReadOnly: true,

0 commit comments

Comments
 (0)