@aws/nx-plugin 0.18.2 → 0.19.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 (37) hide show
  1. package/README.md +2 -0
  2. package/generators.json +13 -1
  3. package/package.json +1 -1
  4. package/src/open-api/ts-hooks/__snapshots__/generator.spec.tsx.snap +14 -18
  5. package/src/open-api/ts-hooks/files/options-proxy.gen.ts.template +1 -1
  6. package/src/ts/lib/ts-project-utils.js +0 -1
  7. package/src/ts/lib/ts-project-utils.js.map +1 -1
  8. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +330 -0
  9. package/src/ts/mcp-server/files/README.md.template +108 -0
  10. package/src/ts/mcp-server/files/src/global.d.ts.template +4 -0
  11. package/src/ts/mcp-server/files/src/index.ts.template +6 -0
  12. package/src/ts/mcp-server/files/src/resources/example-context.md +3 -0
  13. package/src/ts/mcp-server/files/src/server.ts.template +28 -0
  14. package/src/ts/mcp-server/generator.d.ts +10 -0
  15. package/src/ts/mcp-server/generator.js +61 -0
  16. package/src/ts/mcp-server/generator.js.map +1 -0
  17. package/src/ts/mcp-server/schema.d.ts +11 -0
  18. package/src/ts/mcp-server/schema.json +27 -0
  19. package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +263 -0
  20. package/src/ts/nx-generator/files/common/schema.d.ts.template +8 -0
  21. package/src/ts/nx-generator/files/common/schema.json.template +16 -0
  22. package/src/ts/nx-generator/files/local/files/hello.ts.template.template +4 -0
  23. package/src/ts/nx-generator/files/local/generator.spec.ts.template +17 -0
  24. package/src/ts/nx-generator/files/local/generator.ts.template +9 -0
  25. package/src/ts/nx-generator/files/nx-plugin-for-aws/docs/__nameKebabCase__.mdx.template +41 -0
  26. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +27 -0
  27. package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +22 -0
  28. package/src/ts/nx-generator/generator.d.ts +9 -0
  29. package/src/ts/nx-generator/generator.js +137 -0
  30. package/src/ts/nx-generator/generator.js.map +1 -0
  31. package/src/ts/nx-generator/schema.d.ts +11 -0
  32. package/src/ts/nx-generator/schema.json +38 -0
  33. package/src/utils/__snapshots__/shared-constructs.spec.ts.snap +1 -1
  34. package/src/utils/files/common/constructs/src/core/app.ts.template +1 -1
  35. package/src/utils/versions.d.ts +4 -2
  36. package/src/utils/versions.js +3 -1
  37. package/src/utils/versions.js.map +1 -1
package/README.md CHANGED
@@ -56,6 +56,8 @@
56
56
  - `ts#cloudscape-website` - Generate a new Cloudscape/React/Vite based web application.
57
57
  - `ts#cloudscape-website#auth` - Add AWS Cognito authentication to your Cloudscape website.
58
58
  - `ts#trpc-api` - Generate a tRPC backend service with Amazon API Gateway/AWS Lambda integration and [AWS Powertools](https://github.com/aws-powertools/powertools-lambda-typescript) pre-configured.
59
+ - `ts#nx-generator` - Add an [Nx Generator](https://nx.dev/features/generate-code) to a TypeScript project.
60
+ - `ts#mcp-server` - Generate a [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) server in TypeScript.
59
61
  - `py#project` - Generate a uv based Python project.
60
62
  - `py#fast-api` - Generate a FastAPI backend service with [AWS Powertools](https://github.com/aws-powertools/powertools-lambda-python) pre-configured.
61
63
  - `py#lambda-function` - Add a lambda function to an existing python project with optional type-safe event sources.
package/generators.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "http://json-schema.org/schema",
3
- "name": "pace",
3
+ "name": "@aws/nx-plugin",
4
4
  "version": "0.0.1",
5
5
  "generators": {
6
6
  "ts#project": {
@@ -104,6 +104,18 @@
104
104
  "schema": "./src/py/lambda-function/schema.json",
105
105
  "description": "Adds a lambda function to a python project",
106
106
  "metric": "g16"
107
+ },
108
+ "ts#nx-generator": {
109
+ "factory": "./src/ts/nx-generator/generator",
110
+ "schema": "./src/ts/nx-generator/schema.json",
111
+ "description": "Generator for adding an Nx Generator to an existing TypeScript project",
112
+ "metric": "g17"
113
+ },
114
+ "ts#mcp-server": {
115
+ "factory": "./src/ts/mcp-server/generator",
116
+ "schema": "./src/ts/mcp-server/schema.json",
117
+ "description": "Generate a TypeScript Model Context Protocol (MCP) server for providing context to Large Language Models",
118
+ "metric": "g18"
107
119
  }
108
120
  }
109
121
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws/nx-plugin",
3
- "version": "0.18.2",
3
+ "version": "0.19.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/awslabs/nx-plugin-for-aws.git",
@@ -98,9 +98,7 @@ export class TestApiOptionsProxy {
98
98
  ...options,
99
99
  };
100
100
  }
101
- private _getTestQueryFilter(
102
- filter?: QueryFilters<GetTest200Response, GetTestError>,
103
- ): QueryFilters<GetTest200Response, GetTestError> {
101
+ private _getTestQueryFilter(filter?: QueryFilters): QueryFilters {
104
102
  return {
105
103
  queryKey: this._getTestQueryKey(),
106
104
  ...filter,
@@ -173,8 +171,8 @@ export class TestApiOptionsProxy {
173
171
  }
174
172
  private _getItemsQueryFilter(
175
173
  input: GetItemsRequest,
176
- filter?: QueryFilters<GetItems200Response, GetItemsError>,
177
- ): QueryFilters<GetItems200Response, GetItemsError> {
174
+ filter?: QueryFilters,
175
+ ): QueryFilters {
178
176
  return {
179
177
  queryKey: this._getItemsQueryKey(input),
180
178
  ...filter,
@@ -338,8 +336,8 @@ export class TestApiOptionsProxy {
338
336
  }
339
337
  private _searchDataQueryFilter(
340
338
  input: SearchDataRequest,
341
- filter?: QueryFilters<SearchData200Response, SearchDataError>,
342
- ): QueryFilters<SearchData200Response, SearchDataError> {
339
+ filter?: QueryFilters,
340
+ ): QueryFilters {
343
341
  return {
344
342
  queryKey: this._searchDataQueryKey(input),
345
343
  ...filter,
@@ -412,8 +410,8 @@ export class TestApiOptionsProxy {
412
410
  }
413
411
  private _getItemsQueryFilter(
414
412
  input: GetItemsRequest,
415
- filter?: QueryFilters<GetItems200Response, GetItemsError>,
416
- ): QueryFilters<GetItems200Response, GetItemsError> {
413
+ filter?: QueryFilters,
414
+ ): QueryFilters {
417
415
  return {
418
416
  queryKey: this._getItemsQueryKey(input),
419
417
  ...filter,
@@ -529,8 +527,8 @@ export class TestApiOptionsProxy {
529
527
  }
530
528
  private _listRecordsQueryFilter(
531
529
  input: ListRecordsRequest,
532
- filter?: QueryFilters<ListRecords200Response, ListRecordsError>,
533
- ): QueryFilters<ListRecords200Response, ListRecordsError> {
530
+ filter?: QueryFilters,
531
+ ): QueryFilters {
534
532
  return {
535
533
  queryKey: this._listRecordsQueryKey(input),
536
534
  ...filter,
@@ -687,9 +685,7 @@ export class TestApiOptionsProxy {
687
685
  ...options,
688
686
  };
689
687
  }
690
- private _getErrorQueryFilter(
691
- filter?: QueryFilters<GetError200Response, GetErrorError>,
692
- ): QueryFilters<GetError200Response, GetErrorError> {
688
+ private _getErrorQueryFilter(filter?: QueryFilters): QueryFilters {
693
689
  return {
694
690
  queryKey: this._getErrorQueryKey(),
695
691
  ...filter,
@@ -809,8 +805,8 @@ export class TestApiOptionsProxy {
809
805
  }
810
806
  private _streamLogsQueryFilter(
811
807
  input: StreamLogsRequest,
812
- filter?: QueryFilters<StreamLogs200Response[], StreamLogsError>,
813
- ): QueryFilters<StreamLogs200Response[], StreamLogsError> {
808
+ filter?: QueryFilters,
809
+ ): QueryFilters {
814
810
  return {
815
811
  queryKey: this._streamLogsQueryKey(input),
816
812
  ...filter,
@@ -1074,8 +1070,8 @@ export class TestApiOptionsProxy {
1074
1070
  }
1075
1071
  private _streamEventsQueryFilter(
1076
1072
  input: StreamEventsRequest,
1077
- filter?: QueryFilters<StreamEvents200Response[], StreamEventsError>,
1078
- ): QueryFilters<StreamEvents200Response[], StreamEventsError> {
1073
+ filter?: QueryFilters,
1074
+ ): QueryFilters {
1079
1075
  return {
1080
1076
  queryKey: this._streamEventsQueryKey(input),
1081
1077
  ...filter,
@@ -133,7 +133,7 @@ export class <%- className %>OptionsProxy {
133
133
  ...options,
134
134
  };
135
135
  }
136
- private _<%- op.uniqueName %>QueryFilter(<%- input %><% if (op.parameters.length > 0) { %>, <% } %>filter?: QueryFilters<<%- queryResultType %>, <%- errorType %>>): QueryFilters<<%- queryResultType %>, <%- errorType %>> {
136
+ private _<%- op.uniqueName %>QueryFilter(<%- input %><% if (op.parameters.length > 0) { %>, <% } %>filter?: QueryFilters): QueryFilters {
137
137
  return {
138
138
  queryKey: this._<%- op.uniqueName %>QueryKey(<% if (op.parameters.length > 0) { %>input<% } %>),
139
139
  ...filter,
@@ -34,7 +34,6 @@ const configureTsProject = (tree, options) => {
34
34
  // Add aliases which begin with colon (eg :foo/bar) to avoid sniping attacks
35
35
  [(0, npm_scope_1.toScopeAlias)(options.fullyQualifiedName)]: [
36
36
  (0, devkit_1.joinPathFragments)(options.dir, 'src', 'index.ts'),
37
- (0, devkit_1.joinPathFragments)('dist', options.dir, 'src', 'index.d.ts'),
38
37
  ] }) }) }));
39
38
  });
40
39
  if (tree.exists('tsconfig.json')) {
@@ -1 +1 @@
1
- {"version":3,"file":"ts-project-utils.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/ts/lib/ts-project-utils.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,uCAAiE;AACjE,+BAAsC;AACtC,qDAAqD;AAErD,qCAA2C;AAC3C,qCAA2C;AAE3C;;GAEG;AACI,MAAM,kBAAkB,GAAG,CAChC,IAAU,EACV,OAAgC,EAChC,EAAE;IACF,mDAAmD;IACnD,IAAA,mBAAU,EAAC,IAAI,EAAE,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,EAAE;;QAAC,OAAA,iCAC9D,QAAQ,KACX,eAAe,kCACV,QAAQ,CAAC,eAAe,KAC3B,MAAM,EACJ,CAAA,MAAA,QAAQ,CAAC,eAAe,0CAAE,MAAM,MAAK,UAAU;oBAC7C,CAAC,CAAC,SAAS;oBACX,CAAC,CAAC,MAAA,QAAQ,CAAC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,EAAE,KAAK,OAAO,CAAC,GAAG,EAAE;qBACzB;iBACF,IACD,CAAA;SAAA,CAAC,CAAC;IACN,CAAC;IACD,+BAA+B;IAC/B,IAAA,mBAAU,EAAC,IAAI,EAAE,cAAc,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,iCAC7C,WAAW,KACd,IAAI,EAAE,QAAQ,IACd,CAAC,CAAC;IACJ,mCAAmC;IACnC,IAAI,IAAI,CAAC,MAAM,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QACnD,IAAI,CAAC,MAAM,CAAC,IAAA,WAAI,EAAC,OAAO,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,IAAA,wBAAe,EAAC,IAAI,CAAC,CAAC;IACtB,IAAA,wBAAe,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACjC,CAAC,CAAC;AAhFW,QAAA,kBAAkB,sBAgF7B"}
@@ -0,0 +1,330 @@
1
+ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
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';
114
+
115
+ export default [
116
+ ...baseConfig,
117
+ {
118
+ files: ['**/*.json'],
119
+ rules: {
120
+ '@nx/dependency-checks': [
121
+ 'error',
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
+ "targets": {
143
+ "build": {
144
+ "dependsOn": ["lint", "compile", "test", "bundle"]
145
+ },
146
+ "compile": {
147
+ "executor": "nx:run-commands",
148
+ "outputs": ["{workspaceRoot}/dist/test-server/tsc"],
149
+ "options": {
150
+ "command": "tsc --build tsconfig.lib.json",
151
+ "cwd": "{projectRoot}"
152
+ }
153
+ },
154
+ "test": {
155
+ "executor": "@nx/vite:test",
156
+ "outputs": ["{options.reportsDirectory}"],
157
+ "options": {
158
+ "reportsDirectory": "../coverage/test-server"
159
+ }
160
+ },
161
+ "bundle": {
162
+ "executor": "nx:run-commands",
163
+ "options": {
164
+ "commands": [
165
+ "esbuild \\"test-server/src/index.ts\\" --bundle --platform=node --format=esm --loader:.md=text --outfile=dist/test-server/bundle/index.js"
166
+ ]
167
+ }
168
+ },
169
+ "dev": {
170
+ "executor": "nx:run-commands",
171
+ "options": {
172
+ "commands": [
173
+ "nx watch --projects=@proj/test-server --includeDependentProjects -- nx run @proj/test-server:bundle"
174
+ ]
175
+ }
176
+ }
177
+ }
178
+ }
179
+ ",
180
+ "test-server/src/global.d.ts": "declare module '*.md' {
181
+ const content: string;
182
+ export default content;
183
+ }
184
+ ",
185
+ "test-server/src/index.ts": "import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
186
+ import { createServer } from './server.js';
187
+
188
+ // Start receiving messages on stdin and sending messages on stdout
189
+ const transport = new StdioServerTransport();
190
+ await createServer().connect(transport);
191
+ ",
192
+ "test-server/src/resources/example-context.md": "## Example Context
193
+
194
+ This is some example context in a markdown file!
195
+ ",
196
+ "test-server/src/server.ts": "import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
197
+ import { z } from 'zod';
198
+ import exampleContext from './resources/example-context.md';
199
+
200
+ /**
201
+ * Create the MCP Server
202
+ */
203
+ export const createServer = () => {
204
+ const server = new McpServer({
205
+ name: 'test-server',
206
+ version: '1.0.0',
207
+ });
208
+
209
+ // Add an addition tool
210
+ server.tool('add', { a: z.number(), b: z.number() }, async ({ a, b }) => ({
211
+ content: [{ type: 'text', text: String(a + b) }],
212
+ }));
213
+
214
+ // Add a resource which provides context from a markdown file
215
+ server.resource('example-context', 'example://context', async (uri) => ({
216
+ contents: [{ uri: uri.href, text: exampleContext }],
217
+ }));
218
+
219
+ return server;
220
+ };
221
+ ",
222
+ "test-server/tsconfig.json": "{
223
+ "extends": "../tsconfig.base.json",
224
+ "files": [],
225
+ "include": [],
226
+ "references": [
227
+ {
228
+ "path": "./tsconfig.lib.json"
229
+ },
230
+ {
231
+ "path": "./tsconfig.spec.json"
232
+ }
233
+ ],
234
+ "nx": {
235
+ "addTypecheckTarget": false
236
+ },
237
+ "compilerOptions": {}
238
+ }
239
+ ",
240
+ "test-server/tsconfig.lib.json": "{
241
+ "extends": "../tsconfig.base.json",
242
+ "compilerOptions": {
243
+ "rootDir": ".",
244
+ "outDir": "../dist/test-server/tsc",
245
+ "tsBuildInfoFile": "../dist/test-server/tsc/tsconfig.lib.tsbuildinfo",
246
+ "emitDeclarationOnly": false,
247
+ "module": "nodenext",
248
+ "moduleResolution": "nodenext",
249
+ "types": ["node"]
250
+ },
251
+ "include": ["src/**/*.ts"],
252
+ "references": [],
253
+ "exclude": [
254
+ "vite.config.ts",
255
+ "vite.config.mts",
256
+ "vitest.config.ts",
257
+ "vitest.config.mts",
258
+ "src/**/*.test.ts",
259
+ "src/**/*.spec.ts",
260
+ "src/**/*.test.tsx",
261
+ "src/**/*.spec.tsx",
262
+ "src/**/*.test.js",
263
+ "src/**/*.spec.js",
264
+ "src/**/*.test.jsx",
265
+ "src/**/*.spec.jsx"
266
+ ]
267
+ }
268
+ ",
269
+ "test-server/tsconfig.spec.json": "{
270
+ "extends": "../tsconfig.base.json",
271
+ "compilerOptions": {
272
+ "outDir": "./out-tsc/vitest",
273
+ "types": [
274
+ "vitest/globals",
275
+ "vitest/importMeta",
276
+ "vite/client",
277
+ "node",
278
+ "vitest"
279
+ ],
280
+ "module": "nodenext",
281
+ "moduleResolution": "nodenext"
282
+ },
283
+ "include": [
284
+ "vite.config.ts",
285
+ "vite.config.mts",
286
+ "vitest.config.ts",
287
+ "vitest.config.mts",
288
+ "src/**/*.test.ts",
289
+ "src/**/*.spec.ts",
290
+ "src/**/*.test.tsx",
291
+ "src/**/*.spec.tsx",
292
+ "src/**/*.test.js",
293
+ "src/**/*.spec.js",
294
+ "src/**/*.test.jsx",
295
+ "src/**/*.spec.jsx",
296
+ "src/**/*.d.ts"
297
+ ],
298
+ "references": [
299
+ {
300
+ "path": "./tsconfig.lib.json"
301
+ }
302
+ ]
303
+ }
304
+ ",
305
+ "test-server/vite.config.ts": "import { defineConfig } from 'vite';
306
+
307
+ export default defineConfig(() => ({
308
+ root: __dirname,
309
+ cacheDir: '../node_modules/.vite/test-server',
310
+ plugins: [],
311
+ // Uncomment this if you are using workers.
312
+ // worker: {
313
+ // plugins: [ nxViteTsPaths() ],
314
+ // },
315
+ test: {
316
+ watch: false,
317
+ globals: true,
318
+ environment: 'jsdom',
319
+ include: ['src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
320
+ reporters: ['default'],
321
+ coverage: {
322
+ reportsDirectory: './test-output/vitest/coverage',
323
+ provider: 'v8' as const,
324
+ },
325
+ passWithNoTests: true,
326
+ },
327
+ }));
328
+ ",
329
+ }
330
+ `;
@@ -0,0 +1,108 @@
1
+ # <%- name %>
2
+
3
+ This package defines a Model Context Protocol (MCP) Server in TypeScript.
4
+
5
+ ## What is MCP?
6
+
7
+ 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.
8
+
9
+ ## Documentation
10
+
11
+ - [Model Context Protocol Documentation](https://modelcontextprotocol.io/)
12
+ - [MCP TypeScript SDK Documentation](https://github.com/modelcontextprotocol/sdk-typescript)
13
+
14
+ ## Developer Guide
15
+
16
+ ### Getting Started
17
+
18
+ This MCP server is built using the MCP TypeScript SDK. Here's how to work with it:
19
+
20
+ 1. **Server Structure**: The main server code is in `src/server.ts`. This file defines the server, its tools, and resources.
21
+
22
+ 2. **Adding Tools**: Tools are functions that the LLM can call to perform actions. Add new tools using the `server.tool()` method:
23
+
24
+ ```typescript
25
+ server.tool("toolName",
26
+ { param1: z.string(), param2: z.number() }, // Input schema using Zod
27
+ async ({ param1, param2 }) => {
28
+ // Tool implementation
29
+ return {
30
+ content: [{ type: "text", text: "Result" }]
31
+ };
32
+ }
33
+ );
34
+ ```
35
+
36
+ 3. **Adding Resources**: Resources provide context to the LLM. You can add static resources from files or dynamic resources:
37
+
38
+ ```typescript
39
+ // Static resource from a file
40
+ import resourceContent from './resources/my-resource.md';
41
+
42
+ server.resource('resource-name', 'example://resource', async (uri) => ({
43
+ contents: [{ uri: uri.href, text: resourceContent }],
44
+ }));
45
+
46
+ // Dynamic resource
47
+ server.resource('dynamic-resource', 'dynamic://resource', async (uri) => {
48
+ const data = await fetchSomeData();
49
+ return {
50
+ contents: [{ uri: uri.href, text: data }],
51
+ };
52
+ });
53
+ ```
54
+
55
+ ### Building the Server
56
+
57
+ To build the server for use with AI assistants:
58
+
59
+ ```bash
60
+ nx run <project-name>:bundle
61
+ ```
62
+
63
+ This creates a bundled version of your server in `dist/<project-path>/bundle/index.js`.
64
+
65
+ ## Using with AI Assistants
66
+
67
+ To use your MCP server with AI assistants, you need to build it first to create the bundle:
68
+
69
+ ```bash
70
+ nx run <project-name>:bundle
71
+ ```
72
+
73
+ ### Configuration
74
+
75
+ 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:
76
+
77
+ ```json
78
+ {
79
+ "mcpServers": {
80
+ "<%- name %>": {
81
+ "command": "node",
82
+ "args": [
83
+ "/path/to/workspace/dist/<%- dir %>/bundle/index.js"
84
+ ],
85
+ "transportType": "stdio"
86
+ }
87
+ }
88
+ }
89
+ ```
90
+
91
+ Replace `/path/to/workspace/dist/<%- dir %>/bundle/index.js` with the actual path to your bundled MCP server.
92
+
93
+ 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`.
94
+
95
+ ### Development Mode
96
+
97
+ During development, you can use the `dev` target to continuously rebuild the bundle whenever you make changes:
98
+
99
+ ```bash
100
+ nx run <project-name>:dev
101
+ ```
102
+
103
+ This will watch for changes in your project files and automatically rebuild the bundle.
104
+
105
+ 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:
106
+
107
+ 1. Find your MCP server in the assistant's settings or configuration
108
+ 2. Look for a "Restart" or "Reload" option
@@ -0,0 +1,4 @@
1
+ declare module '*.md' {
2
+ const content: string;
3
+ export default content;
4
+ }
@@ -0,0 +1,6 @@
1
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
2
+ import { createServer } from './server.js';
3
+
4
+ // Start receiving messages on stdin and sending messages on stdout
5
+ const transport = new StdioServerTransport();
6
+ await createServer().connect(transport);
@@ -0,0 +1,3 @@
1
+ ## Example Context
2
+
3
+ This is some example context in a markdown file!
@@ -0,0 +1,28 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+ import exampleContext from './resources/example-context.md';
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
+ // Add an addition tool
15
+ server.tool("add",
16
+ { a: z.number(), b: z.number() },
17
+ async ({ a, b }) => ({
18
+ content: [{ type: "text", text: String(a + b) }]
19
+ })
20
+ );
21
+
22
+ // Add a resource which provides context from a markdown file
23
+ server.resource('example-context', 'example://context', async (uri) => ({
24
+ contents: [{ uri: uri.href, text: exampleContext }],
25
+ }));
26
+
27
+ return server;
28
+ };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { GeneratorCallback, Tree } from '@nx/devkit';
6
+ import { TsMcpServerGeneratorSchema } from './schema';
7
+ import { NxGeneratorInfo } from '../../utils/nx';
8
+ export declare const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo;
9
+ export declare const tsMcpServerGenerator: (tree: Tree, options: TsMcpServerGeneratorSchema) => Promise<GeneratorCallback>;
10
+ export default tsMcpServerGenerator;