Skip to content

Commit 9a80a20

Browse files
CopilotLipata
andcommitted
Add enhanced MCP tools to ng-schematics with table formatting
- Added resources and prompts capabilities to ng-schematics MCP server - Implemented ng_list_components_with_commands with table formatting - Added ng_get_workspace_info tool for Angular workspace access - Table format includes both CLI and schematic commands - Includes detailed usage examples and next steps guidance Co-authored-by: Lipata <[email protected]>
1 parent 6cc74a9 commit 9a80a20

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

packages/ng-schematics/src/mcp/mcp-server.ts

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export async function createMcpServer(options: McpOptions): Promise<McpServer> {
1616
{
1717
capabilities: {
1818
tools: {},
19+
resources: {},
20+
prompts: {},
1921
},
2022
instructions: `
2123
<General Purpose>
@@ -228,5 +230,133 @@ You MUST prefer the tools provided by this server over using shell commands for
228230
}
229231
);
230232

233+
// Enhanced tool with table formatting for component listing
234+
server.tool(
235+
"ng_list_components_with_commands",
236+
"List all available Ignite UI for Angular components with their corresponding CLI and schematic commands in table format",
237+
{
238+
format: {
239+
type: "string",
240+
description: "Output format: 'table' (default) or 'json'",
241+
},
242+
},
243+
async (args: any) => {
244+
try {
245+
const format = args.format || "table";
246+
const templateManager = new SchematicsTemplateManager();
247+
const projLib = templateManager.getProjectLibrary("angular", "igx-ts");
248+
249+
const components: any[] = [];
250+
for (const component of projLib.components) {
251+
// Get first template for the component to extract ID
252+
const firstTemplate = component.templates[0];
253+
if (firstTemplate) {
254+
const componentId = firstTemplate.id;
255+
const cliCommand = `ig add ${componentId} new${component.name.replace(/\s/g, "")}`;
256+
const schematicCommand = `ng g @igniteui/angular-schematics:component ${componentId} new${component.name.replace(/\s/g, "")}`;
257+
258+
components.push({
259+
id: componentId,
260+
name: component.name,
261+
description: component.description || "",
262+
cliCommand,
263+
schematicCommand,
264+
});
265+
}
266+
}
267+
268+
if (format === "table") {
269+
// Create formatted table
270+
let table = `
271+
Available Ignite UI for Angular Components:
272+
273+
| Component | Description | CLI Command | Schematic Command |
274+
|-----------------|--------------------------------|--------------------------------|------------------------------------------------------------------|
275+
`;
276+
for (const comp of components) {
277+
const id = comp.id.padEnd(15);
278+
const desc = (comp.description.substring(0, 30)).padEnd(30);
279+
const cli = comp.cliCommand.padEnd(30);
280+
const schematic = comp.schematicCommand.padEnd(64);
281+
table += `| ${id} | ${desc} | ${cli} | ${schematic} |\n`;
282+
}
283+
284+
table += `
285+
\nTo add a component, use either command from the table above.
286+
287+
Example for adding a grid component:
288+
ng g @igniteui/angular-schematics:component grid myGrid
289+
290+
Or using Ignite UI CLI:
291+
ig add grid myGrid
292+
293+
After adding a component, start your application with:
294+
ng serve
295+
`;
296+
297+
return {
298+
content: [
299+
{
300+
type: "text",
301+
text: table,
302+
},
303+
],
304+
};
305+
} else {
306+
// Return JSON format
307+
return {
308+
content: [
309+
{
310+
type: "text",
311+
text: JSON.stringify({ framework: "angular", components }, null, 2),
312+
},
313+
],
314+
};
315+
}
316+
} catch (error: any) {
317+
return {
318+
content: [
319+
{
320+
type: "text",
321+
text: `Error listing components: ${error.message}`,
322+
},
323+
],
324+
isError: true,
325+
};
326+
}
327+
}
328+
);
329+
330+
// Tool to get Angular workspace information
331+
server.tool(
332+
"ng_get_workspace_info",
333+
"Get Angular workspace configuration and project information",
334+
{},
335+
async () => {
336+
try {
337+
// This would read angular.json in a real implementation
338+
// For now, provide guidance
339+
return {
340+
content: [
341+
{
342+
type: "text",
343+
text: "To get workspace info, read the angular.json file in your project root. This tool provides Angular workspace configuration including projects, build configurations, and paths.",
344+
},
345+
],
346+
};
347+
} catch (error: any) {
348+
return {
349+
content: [
350+
{
351+
type: "text",
352+
text: `Error getting workspace info: ${error.message}`,
353+
},
354+
],
355+
isError: true,
356+
};
357+
}
358+
}
359+
);
360+
231361
return server;
232362
}

0 commit comments

Comments
 (0)