Skip to main content
Glama

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
NameRequiredDescriptionDefault
appRootYesThe 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'.
nameYesThe name of the artifact to generate
optionsNoAdditional options for the schematic
pathNoThe 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
schematicYesThe schematic to generate (e.g., component, service)

Implementation Reference

  • 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; }
  • 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);
  • Registers the handler for listing tools, which returns the tools array including ng_generate.
    // List tools handler server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: tools, }));
  • 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); }); }); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/talzach/mcp-angular-cli'

If you have feedback or need assistance with the MCP directory API, please join our Discord server