TypeScript Nx Plugin
Generate a complete TypeScript Nx Plugin with an integrated Model Context Protocol (MCP) server. This generator creates a foundation for building custom generators that can be seamlessly used by AI assistants for automated code generation and project scaffolding.
Generate an Nx Plugin
Section titled “Generate an Nx Plugin”You can generate a TypeScript Nx Plugin in two ways:
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#nx-plugin - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:ts#nx-pluginyarn nx g @aws/nx-plugin:ts#nx-pluginnpx nx g @aws/nx-plugin:ts#nx-pluginbunx nx g @aws/nx-plugin:ts#nx-pluginYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#nx-plugin --dry-runyarn nx g @aws/nx-plugin:ts#nx-plugin --dry-runnpx nx g @aws/nx-plugin:ts#nx-plugin --dry-runbunx nx g @aws/nx-plugin:ts#nx-plugin --dry-runOptions
Section titled “Options”| Parameter | Type | Default | Description |
|---|---|---|---|
| name Required | string | - | TypeScript project name |
| directory | string | packages | Parent directory where the library is placed. |
| subDirectory | string | - | The sub directory the lib is placed in. By default this is the library name. |
Generator Output
Section titled “Generator Output”The generator will create the following project structure:
Directoryyour-plugin/
Directorysrc/
- index.ts Empty entry point for your plugin
Directorymcp-server/
- index.ts Exports your server
- server.ts Main MCP server configuration
- stdio.ts Entry point for your MCP server with STDIO transport
- http.ts Entry point for your MCP server with Streamable HTTP transport
Directorytools/
- create-workspace-command.ts Tool for workspace creation guidance
- general-guidance.ts Tool for general Nx and plugin guidance
- list-generators.ts Tool to list available generators
- generator-guide.ts Tool for detailed generator information
- utils.ts Utility functions for the MCP server
- generators.json Nx generator configuration (initially empty)
- package.json Plugin package configuration with MCP server binary
- tsconfig.json TypeScript configuration (CommonJS for Nx compatibility)
- project.json Nx project configuration with build and package targets
Working with Your Nx Plugin
Section titled “Working with Your Nx Plugin”Adding Generators
Section titled “Adding Generators”Once you have your plugin project, you can add generators using the ts#nx-generator generator:
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - ts#nx-generator - Fill in the required parameters
- pluginProject: your-plugin
- Click
Generate
pnpm nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-pluginyarn nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-pluginnpx nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-pluginbunx nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-pluginYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-plugin --dry-runyarn nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-plugin --dry-runnpx nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-plugin --dry-runbunx nx g @aws/nx-plugin:ts#nx-generator --pluginProject=your-plugin --dry-runThis will add a new generator to your plugin.
Make sure to write a detailed README.md for your generator, since this is used by the MCP Server’s generator-guide tool.
Project Targets
Section titled “Project Targets”The generated plugin includes several important targets:
Build Target
Section titled “Build Target”Compiles your TypeScript code and prepares the plugin for use:
pnpm nx build your-pluginyarn nx build your-pluginnpx nx build your-pluginbunx nx build your-pluginPackage Target
Section titled “Package Target”Creates a distributable package ready for NPM publishing:
pnpm nx package your-pluginyarn nx package your-pluginnpx nx package your-pluginbunx nx package your-pluginThe package target includes all necessary assets:
- Compiled JavaScript files
- TypeScript declaration files
- Generator and executor configuration files
- Documentation and license files
MCP Server Integration
Section titled “MCP Server Integration”The plugin configures an MCP server using the ts#mcp-server generator.
The plugin includes a complete MCP server that provides AI assistants the following tools:
general-guidance: Get best practices for working with Nx and your plugincreate-workspace-command: Learn how to create new workspaces that can use your pluginlist-generators: List all available generators in your plugingenerator-guide: Get detailed information about specific generators including schemas and usage
Configuring with AI Assistants
Section titled “Configuring with AI Assistants”Configuration Files
Section titled “Configuration Files”Most AI assistants that support MCP use a similar configuration approach. You’ll need to create or update a configuration file with your MCP server details:
{ "mcpServers": { "your-mcp-server": { "command": "npx", "args": ["tsx", "/path/to/your-mcp-server/stdio.ts"] } }}Hot Reload
Section titled “Hot Reload”While developing your MCP server, you may wish to configure the --watch flag so that the AI assistant always sees the latest versions of tools/resources:
{ "mcpServers": { "your-mcp-server": { "command": "npx", "args": ["tsx", "--watch", "/path/to/your-mcp-server/stdio.ts"] } }}Assistant-Specific Configuration
Section titled “Assistant-Specific Configuration”Please refer to the following documentation for configuring MCP with specific AI Assistants:
Customizing the MCP Server
Section titled “Customizing the MCP Server”You can extend the MCP server by modifying server.ts to add additional tools or resources specific to your plugin’s domain.
For more details about writing MCP Servers, refer to the ts#mcp-server guide.
Publishing Your Plugin
Section titled “Publishing Your Plugin”Preparing for Publication
Section titled “Preparing for Publication”-
Update Package Information: Edit your plugin’s
package.jsonwith proper name, version, description, and repository information. -
Build the Package:
Terminal window pnpm nx package your-pluginTerminal window yarn nx package your-pluginTerminal window npx nx package your-pluginTerminal window bunx nx package your-plugin -
Test Locally: You can test your plugin locally by installing it in another workspace:
Terminal window npm install /path/to/your/workspace/dist/your-plugin/package
Publishing to NPM
Section titled “Publishing to NPM”Once your plugin is ready:
cd dist/your-plugin/packagenpm publishUsing Published Plugins
Section titled “Using Published Plugins”After publishing, others can install and use your plugin:
pnpm add -w your-plugin-nameyarn add your-plugin-namenpm install --legacy-peer-deps your-plugin-namebun install your-plugin-nameThen use your generators:
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
your-plugin-name - your-generator-name - Fill in the required parameters
- Click
Generate
pnpm nx g your-plugin-name:your-generator-nameyarn nx g your-plugin-name:your-generator-namenpx nx g your-plugin-name:your-generator-namebunx nx g your-plugin-name:your-generator-nameYou can also perform a dry-run to see what files would be changed
pnpm nx g your-plugin-name:your-generator-name --dry-runyarn nx g your-plugin-name:your-generator-name --dry-runnpx nx g your-plugin-name:your-generator-name --dry-runbunx nx g your-plugin-name:your-generator-name --dry-runConfigure AI Assistants with your Published Plugin
Section titled “Configure AI Assistants with your Published Plugin”Your published plugin’s MCP server can be configured as follows:
{ "mcpServers": { "aws-nx-mcp": { "command": "npx", "args": ["-y", "-p", "your-plugin-name", "your-plugin-name-mcp-server"] } }}