TypeScript Nx Plugin
統合されたModel Context Protocol (MCP)サーバーを備えた完全なTypeScript Nx Pluginを生成します。このジェネレーターは、AIアシスタントによる自動コード生成とプロジェクトスキャフォールディングにシームレスに使用できるカスタムジェネレーターを構築するための基盤を作成します。
Nxプラグインを生成する
Section titled “Nxプラグインを生成する”TypeScript Nxプラグインは2つの方法で生成できます:
このジェネレーターを実行@aws/nx-plugin:ts#nx-plugin
pnpm nx g @aws/nx-plugin:ts#nx-plugin yarn nx g @aws/nx-plugin:ts#nx-plugin npx nx g @aws/nx-plugin:ts#nx-plugin bunx nx g @aws/nx-plugin:ts#nx-plugin- インストール Nx Console VSCode Plugin まだインストールしていない場合
- VSCodeでNxコンソールを開く
- クリック
Generate (UI)"Common Nx Commands"セクションで - 検索
@aws/nx-plugin - ts#nx-plugin - 必須パラメータを入力
- クリック
Generate
コマンドを組み立てる4
必須
name必須stringTypeScriptプロジェクト名
directorystringデフォルト:packagesライブラリが配置される親ディレクトリ
subDirectorystringライブラリが配置されるサブディレクトリ。デフォルトではライブラリ名になります。
preferInstallDependenciesbooleanデフォルト:trueジェネレーター実行後に依存関係のインストールを優先するかどうか。複数のジェネレーターをバッチ処理する際にインストールを延期する場合は false に設定します(後続のジェネレーターが Nx プロジェクトグラフを計算できるよう、必要に応じてインストールは実行されます)。最後に一度だけインストールします。
ジェネレーターの出力
Section titled “ジェネレーターの出力”ジェネレーターは以下のプロジェクト構造を作成します:
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-guidancetool
- GENERAL_GUIDANCE.md Guidance served by the
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-guidetool - LICENSE Written by the
licensegenerator’s sync, when configured
Nxプラグインの操作
Section titled “Nxプラグインの操作”ジェネレーターの追加
Section titled “ジェネレーターの追加”プラグインプロジェクトを作成したら、ts#nx-generatorジェネレーターを使用してジェネレーターを追加できます:
このジェネレーターを実行@aws/nx-plugin:ts#nx-generator
pnpm nx g @aws/nx-plugin:ts#nx-generator yarn nx g @aws/nx-plugin:ts#nx-generator npx nx g @aws/nx-plugin:ts#nx-generator bunx nx g @aws/nx-plugin:ts#nx-generator- インストール Nx Console VSCode Plugin まだインストールしていない場合
- VSCodeでNxコンソールを開く
- クリック
Generate (UI)"Common Nx Commands"セクションで - 検索
@aws/nx-plugin - ts#nx-generator - 必須パラメータを入力
- クリック
Generate
コマンドを組み立てる5
必須
必須
これにより、プラグインに新しいジェネレーターが追加されます。
MCPサーバーのgenerator-guideツールで使用されるため、ジェネレーター用に詳細なREADME.mdを必ず記述してください。
プロジェクトターゲット
Section titled “プロジェクトターゲット”生成されたプラグインには、いくつかの重要なターゲットが含まれています:
ビルドターゲット
Section titled “ビルドターゲット”TypeScriptコードをコンパイルし、プラグインを使用できるように準備します:
pnpm nx build your-pluginyarn nx build your-pluginnpx nx build your-pluginbunx nx build your-pluginパッケージターゲット
Section titled “パッケージターゲット”NPM公開用の配布可能なパッケージを作成します:
pnpm nx package your-pluginyarn nx package your-pluginnpx nx package your-pluginbunx nx package your-pluginパッケージターゲットには、必要なすべてのアセットが含まれます:
- コンパイルされたJavaScriptファイル
- TypeScript宣言ファイル
- 公開されたプラグインからNxが読み取る
generators.json、executors.json、migrations.jsonマニフェスト - ドキュメントとライセンスファイル
MCPサーバーの統合
Section titled “MCPサーバーの統合”プラグインはts#mcp-serverジェネレーターを使用してMCPサーバーを設定します。
プラグインには、AIアシスタントに以下のツールを提供する完全なMCPサーバーが含まれています:
general-guidance: Nxとプラグインでのベストプラクティスを取得create-workspace-command: プラグインを使用できる新しいワークスペースの作成方法を学習list-generators: プラグイン内の利用可能なすべてのジェネレーターをリストgenerator-guide: スキーマと使用方法を含む特定のジェネレーターに関する詳細情報を取得
AIアシスタントでの設定
Section titled “AIアシスタントでの設定”設定ファイル
Section titled “設定ファイル”MCP をサポートするほとんどの AI アシスタントは、同様の設定アプローチを使用します。MCP サーバーの詳細を含む設定ファイルを作成または更新する必要があります:
{ "mcpServers": { "your-mcp-server": { "command": "npx", "args": ["tsx", "/path/to/your-mcp-server/stdio.ts"] } }}ホットリロード
Section titled “ホットリロード”MCP サーバーを開発している間、AI アシスタントが常に最新バージョンのツール/リソースを認識できるように --watch フラグを設定することをお勧めします:
{ "mcpServers": { "your-mcp-server": { "command": "npx", "args": ["tsx", "--watch", "/path/to/your-mcp-server/stdio.ts"] } }}アシスタント固有の設定
Section titled “アシスタント固有の設定”特定の AI アシスタントで MCP を設定するには、以下のドキュメントを参照してください:
MCPサーバーのカスタマイズ
Section titled “MCPサーバーのカスタマイズ”server.tsを変更して、プラグインのドメインに固有の追加のツールやリソースを追加することで、MCPサーバーを拡張できます。
MCPサーバーの記述の詳細については、ts#mcp-serverガイドを参照してください。
プラグインの公開
Section titled “プラグインの公開”-
パッケージ情報の更新: プラグインの
package.jsonを適切な名前、バージョン、説明、リポジトリ情報で編集します。また、"private": trueを削除してください。 -
パッケージのビルド:
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パッケージは
dist/<your-plugin's project root>/packageに配置されます。--name=nx-plugin --directory=toolsで生成されたプラグインの場合、それはdist/tools/nx-plugin/packageです。 -
ローカルでのテスト: 別のワークスペースにインストールすることで、プラグインをローカルでテストできます:
Terminal window npm install /path/to/your/workspace/dist/tools/nx-plugin/package
NPMへの公開
Section titled “NPMへの公開”プラグインの準備ができたら:
cd dist/tools/nx-plugin/packagenpm publish公開されたプラグインの使用
Section titled “公開されたプラグインの使用”公開後、他のユーザーがプラグインをインストールして使用できます:
pnpm add -w your-plugin-nameyarn add your-plugin-namenpm install --legacy-peer-deps your-plugin-namebun add your-plugin-name次に、ジェネレーターを使用します:
このジェネレーターを実行your-plugin-name:your-generator-name
pnpm nx g your-plugin-name:your-generator-name yarn nx g your-plugin-name:your-generator-name npx nx g your-plugin-name:your-generator-name bunx nx g your-plugin-name:your-generator-name- インストール Nx Console VSCode Plugin まだインストールしていない場合
- VSCodeでNxコンソールを開く
- クリック
Generate (UI)"Common Nx Commands"セクションで - 検索
your-plugin-name - your-generator-name - 必須パラメータを入力
- クリック
Generate
公開されたプラグインでAIアシスタントを設定する
Section titled “公開されたプラグインでAIアシスタントを設定する”公開されたプラグインのMCPサーバーは、次のように設定できます:
{ "mcpServers": { "aws-nx-mcp": { "command": "npx", "args": ["-y", "-p", "your-plugin-name", "your-plugin-name-mcp-server"] } }}