@aws/nx-plugin 0.34.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +3 -62
  2. package/generators.json +6 -0
  3. package/package.json +1 -1
  4. package/sdk/ts.d.ts +4 -0
  5. package/sdk/ts.js +15 -9
  6. package/sdk/ts.js.map +1 -1
  7. package/src/mcp-server/tools/create-workspace-command.js +1 -8
  8. package/src/mcp-server/tools/create-workspace-command.js.map +1 -1
  9. package/src/mcp-server/tools/generator-guide.js +1 -1
  10. package/src/mcp-server/tools/generator-guide.js.map +1 -1
  11. package/src/preset/__snapshots__/generator.spec.ts.snap +2 -0
  12. package/src/trpc/backend/__snapshots__/generator.spec.ts.snap +1 -1
  13. package/src/trpc/backend/files/src/schema/echo.ts.template +1 -1
  14. package/src/trpc/backend/generator.js +0 -3
  15. package/src/trpc/backend/generator.js.map +1 -1
  16. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +41 -314
  17. package/src/ts/mcp-server/files/index.ts.template +17 -0
  18. package/src/ts/mcp-server/files/resources/sample-guidance.ts.template +9 -0
  19. package/src/ts/mcp-server/files/server.ts.template +18 -0
  20. package/src/ts/mcp-server/files/tools/add.ts.template +11 -0
  21. package/src/ts/mcp-server/generator.js +42 -31
  22. package/src/ts/mcp-server/generator.js.map +1 -1
  23. package/src/ts/mcp-server/schema.d.ts +4 -2
  24. package/src/ts/mcp-server/schema.json +9 -16
  25. package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +2 -2
  26. package/src/ts/nx-generator/files/common/schema.json.template +1 -1
  27. package/src/ts/nx-generator/files/local/README.md.template +5 -0
  28. package/src/ts/nx-generator/generator.js +5 -41
  29. package/src/ts/nx-generator/generator.js.map +1 -1
  30. package/src/ts/nx-generator/schema.d.ts +1 -1
  31. package/src/ts/nx-generator/schema.json +3 -3
  32. package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +375 -0
  33. package/src/ts/nx-plugin/files/mcp-server/resources/GENERAL_GUIDANCE.md.template +49 -0
  34. package/src/ts/nx-plugin/files/mcp-server/schema.ts.template +4 -0
  35. package/src/ts/nx-plugin/files/mcp-server/server.ts.template +41 -0
  36. package/src/ts/nx-plugin/files/mcp-server/tools/create-workspace-command.ts.template +36 -0
  37. package/src/ts/nx-plugin/files/mcp-server/tools/general-guidance.ts.template +24 -0
  38. package/src/ts/nx-plugin/files/mcp-server/tools/generator-guide.ts.template +45 -0
  39. package/src/ts/nx-plugin/files/mcp-server/tools/list-generators.ts.template +27 -0
  40. package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +97 -0
  41. package/src/ts/nx-plugin/generator.d.ts +10 -0
  42. package/src/ts/nx-plugin/generator.js +88 -0
  43. package/src/ts/nx-plugin/generator.js.map +1 -0
  44. package/src/ts/nx-plugin/schema.d.ts +11 -0
  45. package/src/ts/nx-plugin/schema.json +32 -0
  46. package/src/ts/nx-plugin/utils.d.ts +9 -0
  47. package/src/ts/nx-plugin/utils.js +65 -0
  48. package/src/ts/nx-plugin/utils.js.map +1 -0
  49. package/src/utils/ast.js +3 -1
  50. package/src/utils/ast.js.map +1 -1
  51. package/src/ts/mcp-server/files/README.md.template +0 -108
  52. package/src/ts/mcp-server/files/src/global.d.ts.template +0 -4
  53. package/src/ts/mcp-server/files/src/index.ts.template +0 -6
  54. package/src/ts/mcp-server/files/src/resources/example-context.md +0 -3
  55. package/src/ts/mcp-server/files/src/server.ts.template +0 -28
  56. package/src/utils/zod.d.ts +0 -9
  57. package/src/utils/zod.js +0 -19
  58. package/src/utils/zod.js.map +0 -1
@@ -1,335 +1,62 @@
1
1
  // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
2
 
3
- exports[`ts#mcp-server generator > should match snapshot > mcp-server-files 1`] = `
4
- {
5
- "test-server/README.md": "# test-server
6
-
7
- This package defines a Model Context Protocol (MCP) Server in TypeScript.
8
-
9
- ## What is MCP?
10
-
11
- The Model Context Protocol (MCP) is a standardized protocol for providing context to Large Language Models (LLMs). It allows AI assistants to access external tools and resources through a consistent interface.
12
-
13
- ## Documentation
14
-
15
- - [Model Context Protocol Documentation](https://modelcontextprotocol.io/)
16
- - [MCP TypeScript SDK Documentation](https://github.com/modelcontextprotocol/sdk-typescript)
17
-
18
- ## Developer Guide
19
-
20
- ### Getting Started
21
-
22
- This MCP server is built using the MCP TypeScript SDK. Here's how to work with it:
23
-
24
- 1. **Server Structure**: The main server code is in \`src/server.ts\`. This file defines the server, its tools, and resources.
25
-
26
- 2. **Adding Tools**: Tools are functions that the LLM can call to perform actions. Add new tools using the \`server.tool()\` method:
27
-
28
- \`\`\`typescript
29
- server.tool(
30
- 'toolName',
31
- { param1: z.string(), param2: z.number() }, // Input schema using Zod
32
- async ({ param1, param2 }) => {
33
- // Tool implementation
34
- return {
35
- content: [{ type: 'text', text: 'Result' }],
36
- };
37
- },
38
- );
39
- \`\`\`
40
-
41
- 3. **Adding Resources**: Resources provide context to the LLM. You can add static resources from files or dynamic resources:
42
-
43
- \`\`\`typescript
44
- // Static resource from a file
45
- import resourceContent from './resources/my-resource.md';
46
-
47
- server.resource('resource-name', 'example://resource', async (uri) => ({
48
- contents: [{ uri: uri.href, text: resourceContent }],
49
- }));
50
-
51
- // Dynamic resource
52
- server.resource('dynamic-resource', 'dynamic://resource', async (uri) => {
53
- const data = await fetchSomeData();
54
- return {
55
- contents: [{ uri: uri.href, text: data }],
56
- };
57
- });
58
- \`\`\`
59
-
60
- ### Building the Server
61
-
62
- To build the server for use with AI assistants:
63
-
64
- \`\`\`bash
65
- nx run <project-name>:bundle
66
- \`\`\`
67
-
68
- This creates a bundled version of your server in \`dist/<project-path>/bundle/index.js\`.
69
-
70
- ## Using with AI Assistants
71
-
72
- To use your MCP server with AI assistants, you need to build it first to create the bundle:
73
-
74
- \`\`\`bash
75
- nx run <project-name>:bundle
76
- \`\`\`
77
-
78
- ### Configuration
79
-
80
- Most AI assistants (Amazon Q Developer CLI, Cline, Cursor, Claude Code, etc.) use a similar configuration approach. You'll need to create or update a configuration file with your MCP server details:
81
-
82
- \`\`\`json
83
- {
84
- "mcpServers": {
85
- "test-server": {
86
- "command": "node",
87
- "args": ["/path/to/workspace/dist/test-server/bundle/index.js"],
88
- "transportType": "stdio"
89
- }
90
- }
91
- }
92
- \`\`\`
93
-
94
- Replace \`/path/to/workspace/dist/test-server/bundle/index.js\` with the actual path to your bundled MCP server.
95
-
96
- Note that if you receive an error due to \`node\` missing (eg \`ENOENT node\`), you might need to specify the full path to \`node\` which you can obtain by running \`which node\`.
97
-
98
- ### Development Mode
99
-
100
- During development, you can use the \`dev\` target to continuously rebuild the bundle whenever you make changes:
101
-
102
- \`\`\`bash
103
- nx run <project-name>:dev
104
- \`\`\`
105
-
106
- This will watch for changes in your project files and automatically rebuild the bundle.
107
-
108
- Whenever you've made changes, you'll need to restart the MCP server in your AI assistant to test it out. The exact process depends on the assistant, but generally:
109
-
110
- 1. Find your MCP server in the assistant's settings or configuration
111
- 2. Look for a "Restart" or "Reload" option
112
- ",
113
- "test-server/eslint.config.mjs": "import baseConfig from '../eslint.config.mjs';
3
+ exports[`ts#mcp-server generator > should match snapshot for generated files > mcp-server-index.ts 1`] = `
4
+ "#!/usr/bin/env node
5
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
6
+ import { createServer } from './server';
7
+
8
+ export const startMcpServer = async () => {
9
+ const transport = new StdioServerTransport();
10
+ await createServer().connect(transport);
11
+ console.error('MCP Server listening on STDIO');
12
+ };
114
13
 
115
- export default [
116
- ...baseConfig,
117
- {
118
- files: ['**/*.json'],
119
- rules: {
120
- '@nx/dependency-checks': [
121
- 'warn',
122
- {
123
- ignoredFiles: [
124
- '{projectRoot}/eslint.config.{js,cjs,mjs}',
125
- '{projectRoot}/vite.config.{js,ts,mjs,mts}',
126
- ],
127
- },
128
- ],
129
- },
130
- languageOptions: {
131
- parser: await import('jsonc-eslint-parser'),
132
- },
133
- },
134
- ];
135
- ",
136
- "test-server/project.json": "{
137
- "name": "@proj/test-server",
138
- "$schema": "../node_modules/nx/schemas/project-schema.json",
139
- "sourceRoot": "test-server/src",
140
- "projectType": "library",
141
- "tags": [],
142
- "metadata": {
143
- "generator": "ts#mcp-server"
144
- },
145
- "targets": {
146
- "build": {
147
- "dependsOn": ["lint", "compile", "test", "bundle"]
148
- },
149
- "compile": {
150
- "executor": "nx:run-commands",
151
- "outputs": ["{workspaceRoot}/dist/test-server/tsc"],
152
- "options": {
153
- "command": "tsc --build tsconfig.lib.json",
154
- "cwd": "{projectRoot}"
155
- }
156
- },
157
- "test": {
158
- "executor": "@nx/vite:test",
159
- "outputs": ["{options.reportsDirectory}"],
160
- "options": {
161
- "reportsDirectory": "../coverage/test-server"
162
- }
163
- },
164
- "bundle": {
165
- "executor": "nx:run-commands",
166
- "options": {
167
- "commands": [
168
- "esbuild \\"test-server/src/index.ts\\" --bundle --platform=node --format=esm --loader:.md=text --outfile=dist/test-server/bundle/index.js"
169
- ]
170
- }
171
- },
172
- "dev": {
173
- "executor": "nx:run-commands",
174
- "options": {
175
- "commands": [
176
- "nx watch --projects=@proj/test-server --includeDependentProjects -- nx run @proj/test-server:bundle"
177
- ]
178
- }
179
- }
14
+ void (async () => {
15
+ try {
16
+ await startMcpServer();
17
+ } catch (e) {
18
+ console.error(e);
180
19
  }
181
- }
182
- ",
183
- "test-server/src/global.d.ts": "declare module '*.md' {
184
- const content: string;
185
- export default content;
186
- }
187
- ",
188
- "test-server/src/index.ts": "import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
189
- import { createServer } from './server.js';
190
-
191
- // Start receiving messages on stdin and sending messages on stdout
192
- const transport = new StdioServerTransport();
193
- await createServer().connect(transport);
194
- ",
195
- "test-server/src/resources/example-context.md": "## Example Context
20
+ })();
21
+ "
22
+ `;
196
23
 
197
- This is some example context in a markdown file!
198
- ",
199
- "test-server/src/server.ts": "import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
200
- import { z } from 'zod';
201
- import exampleContext from './resources/example-context.md';
24
+ exports[`ts#mcp-server generator > should match snapshot for generated files > mcp-server-server.ts 1`] = `
25
+ "import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
26
+ import { registerAddTool } from './tools/add';
27
+ import { registerSampleGuidanceResource } from './resources/sample-guidance';
202
28
 
203
29
  /**
204
30
  * Create the MCP Server
205
31
  */
206
32
  export const createServer = () => {
207
33
  const server = new McpServer({
208
- name: 'test-server',
34
+ name: 'snapshot-server',
209
35
  version: '1.0.0',
210
36
  });
211
37
 
212
- // Add an addition tool
213
- server.tool(
214
- 'add',
215
- 'adds two numbers',
216
- { a: z.number(), b: z.number() },
217
- async ({ a, b }) => ({
218
- content: [{ type: 'text', text: String(a + b) }],
219
- }),
220
- );
221
-
222
- // Add a resource which provides context from a markdown file
223
- server.resource('example-context', 'example://context', async (uri) => ({
224
- contents: [{ uri: uri.href, text: exampleContext }],
225
- }));
38
+ registerAddTool(server);
39
+ registerSampleGuidanceResource(server);
226
40
 
227
41
  return server;
228
42
  };
229
- ",
230
- "test-server/tsconfig.json": "{
231
- "extends": "../tsconfig.base.json",
232
- "files": [],
233
- "include": [],
234
- "references": [
235
- {
236
- "path": "./tsconfig.lib.json"
237
- },
238
- {
239
- "path": "./tsconfig.spec.json"
240
- }
241
- ],
242
- "compilerOptions": {}
243
- }
244
- ",
245
- "test-server/tsconfig.lib.json": "{
246
- "extends": "../tsconfig.base.json",
247
- "compilerOptions": {
248
- "rootDir": ".",
249
- "outDir": "../dist/test-server/tsc",
250
- "tsBuildInfoFile": "../dist/test-server/tsc/tsconfig.lib.tsbuildinfo",
251
- "emitDeclarationOnly": false,
252
- "module": "nodenext",
253
- "moduleResolution": "nodenext",
254
- "types": ["node"]
255
- },
256
- "include": ["src/**/*.ts"],
257
- "references": [],
258
- "exclude": [
259
- "vite.config.ts",
260
- "vite.config.mts",
261
- "vitest.config.ts",
262
- "vitest.config.mts",
263
- "src/**/*.test.ts",
264
- "src/**/*.spec.ts",
265
- "src/**/*.test.tsx",
266
- "src/**/*.spec.tsx",
267
- "src/**/*.test.js",
268
- "src/**/*.spec.js",
269
- "src/**/*.test.jsx",
270
- "src/**/*.spec.jsx"
271
- ]
272
- }
273
- ",
274
- "test-server/tsconfig.spec.json": "{
275
- "extends": "../tsconfig.base.json",
276
- "compilerOptions": {
277
- "outDir": "./out-tsc/vitest",
278
- "types": [
279
- "vitest/globals",
280
- "vitest/importMeta",
281
- "vite/client",
282
- "node",
283
- "vitest"
284
- ],
285
- "module": "nodenext",
286
- "moduleResolution": "nodenext"
287
- },
288
- "include": [
289
- "vite.config.ts",
290
- "vite.config.mts",
291
- "vitest.config.ts",
292
- "vitest.config.mts",
293
- "src/**/*.test.ts",
294
- "src/**/*.spec.ts",
295
- "src/**/*.test.tsx",
296
- "src/**/*.spec.tsx",
297
- "src/**/*.test.js",
298
- "src/**/*.spec.js",
299
- "src/**/*.test.jsx",
300
- "src/**/*.spec.jsx",
301
- "src/**/*.d.ts"
302
- ],
303
- "references": [
304
- {
305
- "path": "./tsconfig.lib.json"
306
- }
307
- ]
308
- }
309
- ",
310
- "test-server/vite.config.ts": "import { defineConfig } from 'vite';
43
+ "
44
+ `;
311
45
 
312
- export default defineConfig(() => ({
313
- root: __dirname,
314
- cacheDir: '../node_modules/.vite/test-server',
315
- plugins: [],
316
- // Uncomment this if you are using workers.
317
- // worker: {
318
- // plugins: [ nxViteTsPaths() ],
319
- // },
320
- test: {
321
- watch: false,
322
- globals: true,
323
- environment: 'jsdom',
324
- include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
325
- reporters: ['default'],
326
- coverage: {
327
- reportsDirectory: './test-output/vitest/coverage',
328
- provider: 'v8' as const,
329
- },
330
- passWithNoTests: true,
46
+ exports[`ts#mcp-server generator > should match snapshot for generated files > updated-package.json 1`] = `
47
+ "{
48
+ "name": "test-project",
49
+ "version": "1.0.0",
50
+ "bin": {
51
+ "snapshot-server": "./src/snapshot-server/index.js"
52
+ },
53
+ "dependencies": {
54
+ "@modelcontextprotocol/sdk": "^1.11.3",
55
+ "zod": "^3.25.50"
331
56
  },
332
- }));
333
- ",
57
+ "devDependencies": {
58
+ "tsx": "4.20.1"
59
+ }
334
60
  }
61
+ "
335
62
  `;
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
3
+ import { createServer } from './server<% if (esm) { %>.js<% } %>';
4
+
5
+ export const startMcpServer = async () => {
6
+ const transport = new StdioServerTransport();
7
+ await createServer().connect(transport);
8
+ console.error('MCP Server listening on STDIO');
9
+ };
10
+
11
+ void (async () => {
12
+ try {
13
+ await startMcpServer();
14
+ } catch (e) {
15
+ console.error(e);
16
+ }
17
+ })();
@@ -0,0 +1,9 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+
3
+ export const registerSampleGuidanceResource = (server: McpServer) => {
4
+ server.resource('example-context', 'example://context', async (uri) => ({
5
+ contents: [{ uri: uri.href, text: `## Sample Guidance
6
+
7
+ This is some guidance in markdown format!`}],
8
+ }));
9
+ };
@@ -0,0 +1,18 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { registerAddTool } from './tools/add<% if (esm) { %>.js<% } %>';
3
+ import { registerSampleGuidanceResource } from './resources/sample-guidance<% if (esm) { %>.js<% } %>';
4
+
5
+ /**
6
+ * Create the MCP Server
7
+ */
8
+ export const createServer = () => {
9
+ const server = new McpServer({
10
+ name: "<%- name %>",
11
+ version: "1.0.0"
12
+ });
13
+
14
+ registerAddTool(server);
15
+ registerSampleGuidanceResource(server);
16
+
17
+ return server;
18
+ };
@@ -0,0 +1,11 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+
4
+ export const registerAddTool = (server: McpServer) => {
5
+ server.tool("add", "adds two numbers",
6
+ { a: z.number(), b: z.number() },
7
+ async ({ a, b }) => ({
8
+ content: [{ type: "text", text: String(a + b) }]
9
+ })
10
+ );
11
+ };
@@ -10,47 +10,58 @@ const devkit_1 = require("@nx/devkit");
10
10
  const nx_1 = require("../../utils/nx");
11
11
  const metrics_1 = require("../../utils/metrics");
12
12
  const format_1 = require("../../utils/format");
13
- const generator_1 = tslib_1.__importStar(require("../lib/generator"));
14
13
  const versions_1 = require("../../utils/versions");
14
+ const names_1 = require("../../utils/names");
15
15
  exports.TS_MCP_SERVER_GENERATOR_INFO = (0, nx_1.getGeneratorInfo)(__filename);
16
16
  const tsMcpServerGenerator = (tree, options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
17
- var _a, _b, _c, _d;
18
- // Generate a TypeScript library
19
- yield (0, generator_1.default)(tree, options);
20
- const { fullyQualifiedName } = (0, generator_1.getTsLibDetails)(tree, options);
21
- const project = (0, devkit_1.readProjectConfiguration)(tree, fullyQualifiedName);
17
+ var _a, _b;
18
+ const project = (0, nx_1.readProjectConfigurationUnqualified)(tree, options.project);
19
+ if (!tree.exists((0, devkit_1.joinPathFragments)(project.root, 'tsconfig.json'))) {
20
+ throw new Error(`Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`);
21
+ }
22
+ const defaultName = `${(0, names_1.kebabCase)(project.name.split('/').pop())}-mcp-server`;
23
+ const name = (0, names_1.kebabCase)((_a = options.name) !== null && _a !== void 0 ? _a : defaultName);
24
+ const targetSourceDir = (0, devkit_1.joinPathFragments)((_b = project.sourceRoot) !== null && _b !== void 0 ? _b : `${project.root}/src`, options.name ? name : 'mcp-server');
25
+ const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');
26
+ // Create a package.json if one doesn't exist, since we want to add the server as a bin target
27
+ const projectPackageJsonPath = (0, devkit_1.joinPathFragments)(project.root, 'package.json');
28
+ if (!tree.exists(projectPackageJsonPath)) {
29
+ // Default to esm if no package.json found
30
+ (0, devkit_1.writeJson)(tree, projectPackageJsonPath, {
31
+ name: project.name,
32
+ type: 'module',
33
+ });
34
+ }
35
+ // Generate esm if the package.json is of type module, otherwise we generate commonjs
36
+ // We support commonjs here because nx plugins must be commonjs
37
+ // https://github.com/nrwl/nx/issues/15682
38
+ const esm = (0, devkit_1.readJson)(tree, projectPackageJsonPath).type === 'module';
39
+ // Add a target for running the MCP server
40
+ (0, devkit_1.updateJson)(tree, projectPackageJsonPath, (pkg) => {
41
+ var _a;
42
+ (_a = pkg.bin) !== null && _a !== void 0 ? _a : (pkg.bin = {});
43
+ pkg.bin[name] = `${relativeSourceDir}/index.js`;
44
+ return pkg;
45
+ });
22
46
  // Add dependencies
23
47
  const deps = (0, versions_1.withVersions)(['@modelcontextprotocol/sdk', 'zod']);
24
- const devDeps = (0, versions_1.withVersions)(['tsx', 'esbuild']);
48
+ const devDeps = (0, versions_1.withVersions)(['tsx']);
25
49
  (0, devkit_1.addDependenciesToPackageJson)(tree, deps, devDeps);
50
+ (0, devkit_1.addDependenciesToPackageJson)(tree, deps, devDeps, projectPackageJsonPath);
26
51
  // Generate example server
27
- (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), project.root, {
28
- name: options.name,
29
- dir: project.root,
30
- }, { overwriteStrategy: devkit_1.OverwriteStrategy.Overwrite });
31
- // Add build targets
32
- (0, devkit_1.updateProjectConfiguration)(tree, fullyQualifiedName, Object.assign(Object.assign({}, project), { targets: Object.assign(Object.assign({}, project === null || project === void 0 ? void 0 : project.targets), {
33
- // Bundle with esbuild
34
- bundle: {
52
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files'), targetSourceDir, {
53
+ name,
54
+ esm,
55
+ }, { overwriteStrategy: devkit_1.OverwriteStrategy.KeepExisting });
56
+ (0, devkit_1.updateProjectConfiguration)(tree, project.name, Object.assign(Object.assign({}, project), { targets: Object.assign(Object.assign({}, project.targets), {
57
+ // Add target for running the MCP server
58
+ [`${options.name ? name : 'mcp-server'}-serve`]: {
35
59
  executor: 'nx:run-commands',
36
60
  options: {
37
- commands: [
38
- `esbuild "${(0, devkit_1.joinPathFragments)(project.sourceRoot, 'index.ts')}" --bundle --platform=node --format=esm --loader:.md=text --outfile=${(0, devkit_1.joinPathFragments)('dist', project.root, 'bundle', 'index.js')}`,
39
- ],
61
+ commands: [`tsx --watch ${relativeSourceDir}/index.ts`],
62
+ cwd: '{projectRoot}',
40
63
  },
41
- },
42
- // Dev task for bundling whenever changes are made
43
- dev: {
44
- executor: 'nx:run-commands',
45
- options: {
46
- commands: [
47
- `nx watch --projects=${fullyQualifiedName} --includeDependentProjects -- nx run ${fullyQualifiedName}:bundle`,
48
- ],
49
- },
50
- },
51
- // Ensure bundle runs as part of build
52
- build: Object.assign(Object.assign({}, (_a = project === null || project === void 0 ? void 0 : project.targets) === null || _a === void 0 ? void 0 : _a.build), { dependsOn: [...((_d = (_c = (_b = project === null || project === void 0 ? void 0 : project.targets) === null || _b === void 0 ? void 0 : _b.build) === null || _c === void 0 ? void 0 : _c.dependsOn) !== null && _d !== void 0 ? _d : []), 'bundle'] }) }) }));
53
- (0, nx_1.addGeneratorMetadata)(tree, fullyQualifiedName, exports.TS_MCP_SERVER_GENERATOR_INFO);
64
+ } }) }));
54
65
  yield (0, metrics_1.addGeneratorMetricsIfApplicable)(tree, [exports.TS_MCP_SERVER_GENERATOR_INFO]);
55
66
  yield (0, format_1.formatFilesInSubtree)(tree);
56
67
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"names":[],"mappings":";;;;AAAA;;;GAGG;AACH,uCAUoB;AAEpB,uCAIwB;AACxB,iDAAsE;AACtE,+CAA0D;AAC1D,sEAAuE;AACvE,mDAAoD;AAEvC,QAAA,4BAA4B,GACvC,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAExB,MAAM,oBAAoB,GAAG,CAClC,IAAU,EACV,OAAmC,EACP,EAAE;;IAC9B,gCAAgC;IAChC,MAA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GAAG,EAAE;QACV,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;IAC5B,CAAC,CAAC;AACJ,CAAC,CAAA,CAAC;AApFW,QAAA,oBAAoB,wBAoF/B;AAEF,kBAAe,4BAAoB,CAAC"}
@@ -2,10 +2,12 @@
2
2
  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { TsProjectGeneratorSchema } from '../lib/schema';
6
5
 
7
6
  /**
8
7
  * TypeScript types for options defined in schema.json
9
8
  * Update this to match schema.json if you make changes.
10
9
  */
11
- export type TsMcpServerGeneratorSchema = TsProjectGeneratorSchema;
10
+ export interface TsMcpServerGeneratorSchema {
11
+ project: string;
12
+ name?: string;
13
+ }
@@ -2,31 +2,24 @@
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "$id": "ts#mcp-server",
4
4
  "title": "ts#mcp-server",
5
- "description": "Generate a TypeScript Model Context Protocol (MCP) server for providing context to Large Language Models",
5
+ "description": "Add a Model Context Protocol (MCP) server to an existing TypeScript project",
6
6
  "type": "object",
7
7
  "properties": {
8
- "name": {
8
+ "project": {
9
9
  "type": "string",
10
- "description": "MCP server project name.",
10
+ "description": "The project to add an MCP server to",
11
11
  "$default": {
12
12
  "$source": "argv",
13
13
  "index": 0
14
14
  },
15
- "x-prompt": "What would you like to call your MCP server?",
16
- "x-priority": "important"
17
- },
18
- "directory": {
19
- "type": "string",
20
- "description": "Parent directory where the MCP server is placed.",
21
- "default": "packages",
22
- "x-prompt": "Which directory do you want to create the MCP server in?",
23
- "x-priority": "important"
15
+ "x-prompt": "Select the TypeScript project to add the MCP server to",
16
+ "x-dropdown": "projects"
24
17
  },
25
- "subDirectory": {
18
+ "name": {
26
19
  "type": "string",
27
- "description": "The sub directory the MCP server is placed in. By default this is the MCP server project name.",
28
- "x-prompt": "Which sub directory do you want to create the MCP server in? (By default this is the MCP server project name)"
20
+ "description": "The name of your MCP server (default: mcp-server)",
21
+ "x-prompt": "What would you like to call your MCP server? (default: mcp-server)"
29
22
  }
30
23
  },
31
- "required": ["name"]
24
+ "required": ["project"]
32
25
  }
@@ -120,7 +120,7 @@ exports[`nx-generator generator > within @aws/nx-plugin > should generate an exa
120
120
  "$schema": "https://json-schema.org/schema",
121
121
  "$id": "foo#bar",
122
122
  "title": "foo#bar",
123
- "description": "<Describe your generator here!>",
123
+ "description": "Some description",
124
124
  "type": "object",
125
125
  "properties": {
126
126
  "exampleOption": {
@@ -225,7 +225,7 @@ exports[`nx-generator generator > within another workspace > should generate an
225
225
  "$schema": "https://json-schema.org/schema",
226
226
  "$id": "foo#bar",
227
227
  "title": "foo#bar",
228
- "description": "<Describe your generator here!>",
228
+ "description": "Some description",
229
229
  "type": "object",
230
230
  "properties": {
231
231
  "exampleOption": {
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/schema",
3
3
  "$id": "<%- name %>",
4
4
  "title": "<%- name %>",
5
- "description": "<Describe your generator here!>",
5
+ "description": "<%- description ?? '<Describe your generator here!>'%>",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "exampleOption": {
@@ -0,0 +1,5 @@
1
+ # <%- name %>
2
+
3
+ <%- description %>
4
+
5
+ TODO: document what this generator does, how to use it, and how to build on top of its output