Skip to content

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.

You can generate a TypeScript Nx Plugin in two ways:

Run this generator@aws/nx-plugin:ts#nx-plugin

pnpm nx g @aws/nx-plugin:ts#nx-plugin
Build your command4

Required

Generator Options4 options
nameRequiredstring

TypeScript project name

directorystringDefault: packages

Parent directory where the library is placed.

subDirectorystring

The sub directory the lib is placed in. By default this is the library name.

preferInstallDependenciesbooleanDefault: true

Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end.

The generator will create the following project structure:

  • Directoryyour-plugin/
    • Directorysrc/
      • index.ts 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
        • schema.ts Shared schemas for the MCP server’s tools
        • utils.ts Utility functions for the MCP server
        • Directoryresources/
          • GENERAL_GUIDANCE.md Guidance served by the general-guidance tool
        • 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
    • generators.json Nx generator configuration (initially empty)
    • package.json Plugin package configuration
    • project.json Nx project configuration with build and package targets
    • tsconfig.json TypeScript configuration, referencing the two below
    • tsconfig.lib.json TypeScript configuration for your plugin’s source
    • tsconfig.spec.json TypeScript configuration for your plugin’s tests
    • vitest.config.mts Vitest configuration for your plugin’s tests
    • README.md Documentation for your plugin, served by the generator-guide tool
    • LICENSE Written by the license generator’s sync, when configured

Once you have your plugin project, you can add generators using the ts#nx-generator generator:

Run this generator@aws/nx-plugin:ts#nx-generator

pnpm nx g @aws/nx-plugin:ts#nx-generator
Build your command5

Required

Required

This 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.

The generated plugin includes several important targets:

Compiles your TypeScript code and prepares the plugin for use:

Terminal window
pnpm nx build your-plugin

Creates a distributable package ready for NPM publishing:

Terminal window
pnpm nx package your-plugin

The package target includes all necessary assets:

  • Compiled JavaScript files
  • TypeScript declaration files
  • The generators.json, executors.json and migrations.json manifests Nx reads from a published plugin
  • Documentation and license files

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 plugin
  • create-workspace-command: Learn how to create new workspaces that can use your plugin
  • list-generators: List all available generators in your plugin
  • generator-guide: Get detailed information about specific generators including schemas and usage

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"]
}
}
}

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"]
}
}
}

Please refer to the following documentation for configuring MCP with specific AI Assistants:

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.

  1. Update Package Information: Edit your plugin’s package.json with proper name, version, description, and repository information. Also remove "private": true.

  2. Build the Package:

    Terminal window
    pnpm nx package your-plugin

    The package lands in dist/<your-plugin's project root>/package — for a plugin generated with --name=nx-plugin --directory=tools, that’s dist/tools/nx-plugin/package.

  3. Test Locally: You can test your plugin locally by installing it in another workspace:

    Terminal window
    npm install /path/to/your/workspace/dist/tools/nx-plugin/package

Once your plugin is ready:

Terminal window
cd dist/tools/nx-plugin/package
npm publish

After publishing, others can install and use your plugin:

Terminal window
pnpm add -w your-plugin-name

Then use your generators:

Run this generatoryour-plugin-name:your-generator-name

pnpm nx g your-plugin-name:your-generator-name

Configure 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"]
}
}
}