ng_generate
Create Angular artifacts like components or services using a specified schematic. Define the artifact name, path, and app root for precise file generation, with optional settings for interactive prompts and dry runs.
Instructions
Run 'ng generate' to create a new Angular artifact (component, service, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| appRoot | Yes | The absolute path to the first folder in the 'path' property. For example, if 'path' is 'webui/src/app/modules/alerts', then 'appRoot' should be the absolute path to 'webui'. | |
| name | Yes | The name of the artifact to generate | |
| options | No | Additional options for the schematic | |
| path | No | The path where the artifact should be created, relative to the appRoot (do not include the app folder itself). For example, if the full path is 'webui/src/app/modules/alerts' and appRoot is 'webui', then path should be 'src/app/modules/alerts'. | src/app |
| schematic | Yes | The schematic to generate (e.g., component, service) |
Implementation Reference
- src/toolHandler.ts:15-27 (handler)The handler function for the 'ng_generate' tool. It constructs the command 'npx ng generate [schematic] [name]' and adds optional --path and other options from args.options, then breaks to execute via runCommand.case "ng_generate": { command = "npx"; commandArgs = ["ng", "generate", args.schematic, args.name]; if (args.path) { commandArgs.push("--path", args.path); } if (args.options) { for (const [key, value] of Object.entries(args.options)) { commandArgs.push(`--${key}`, String(value)); } } break; }
- src/tools.ts:9-68 (schema)Input schema defining parameters for ng_generate: schematic (required), name (required), appRoot (required), optional path and options with specific properties.inputSchema: { type: "object", properties: { schematic: { type: "string", description: "The schematic to generate (e.g., component, service)", }, name: { type: "string", description: "The name of the artifact to generate", }, path: { type: "string", description: "The path where the artifact should be created, relative to the appRoot (do not include the app folder itself). For example, if the full path is 'webui/src/app/modules/alerts' and appRoot is 'webui', then path should be 'src/app/modules/alerts'.", default: "src/app", }, appRoot: { type: "string", description: "The absolute path to the first folder in the 'path' property. For example, if 'path' is 'webui/src/app/modules/alerts', then 'appRoot' should be the absolute path to 'webui'.", }, options: { type: "object", description: "Additional options for the schematic", properties: { defaults: { type: "boolean", description: "Disable interactive input prompts for options with a default.", default: false, }, dryRun: { type: "boolean", description: "Run through and report activity without writing out results.", default: false, }, force: { type: "boolean", description: "Force overwriting of existing files.", default: false, }, help: { type: "boolean", description: "Shows a help message for this command in the console.", default: false, }, interactive: { type: "boolean", description: "Enable interactive input prompts.", default: true, }, }, additionalProperties: { type: "string" }, }, }, required: ["schematic", "name", "appRoot"], },
- src/index.ts:22-26 (registration)Registers the tools by calling createToolDefinitions() to get the tool list including ng_generate, and passes it to setupRequestHandlers which sets up list and call handlers on the MCP server.// Create tool definitions const TOOLS = createToolDefinitions(); // Setup request handlers setupRequestHandlers(server, TOOLS);
- src/requestHandler.ts:10-13 (registration)Registers the handler for listing tools, which returns the tools array including ng_generate.// List tools handler server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, }));
- src/toolHandler.ts:86-112 (helper)Helper function to execute the spawned child process for ng commands and capture output.function runCommand( command: string, args: string[], cwd: string ): Promise<string> { return new Promise((resolve, reject) => { const proc = spawn(command, args, { cwd, shell: true }); let stdout = ""; let stderr = ""; proc.stdout.on("data", (data) => { stdout += data.toString(); }); proc.stderr.on("data", (data) => { stderr += data.toString(); }); proc.on("close", (code) => { if (code === 0) { resolve(stdout); } else { reject(stderr || `Process exited with code ${code}`); } }); proc.on("error", (err) => { reject(err); }); }); }