@aws/nx-plugin 0.18.3 → 0.20.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.
- package/README.md +2 -0
- package/generators.json +13 -1
- package/package.json +1 -1
- package/src/cloudscape-website/app/__snapshots__/generator.spec.ts.snap +3 -0
- package/src/cloudscape-website/app/files/common/constructs/src/core/static-website.ts.template +3 -0
- package/src/cloudscape-website/app/generator.js +3 -3
- package/src/cloudscape-website/app/generator.js.map +1 -1
- package/src/ts/lib/ts-project-utils.js +0 -1
- package/src/ts/lib/ts-project-utils.js.map +1 -1
- package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +330 -0
- package/src/ts/mcp-server/files/README.md.template +108 -0
- package/src/ts/mcp-server/files/src/global.d.ts.template +4 -0
- package/src/ts/mcp-server/files/src/index.ts.template +6 -0
- package/src/ts/mcp-server/files/src/resources/example-context.md +3 -0
- package/src/ts/mcp-server/files/src/server.ts.template +28 -0
- package/src/ts/mcp-server/generator.d.ts +10 -0
- package/src/ts/mcp-server/generator.js +61 -0
- package/src/ts/mcp-server/generator.js.map +1 -0
- package/src/ts/mcp-server/schema.d.ts +11 -0
- package/src/ts/mcp-server/schema.json +27 -0
- package/src/ts/nx-generator/__snapshots__/generator.spec.ts.snap +263 -0
- package/src/ts/nx-generator/files/common/schema.d.ts.template +8 -0
- package/src/ts/nx-generator/files/common/schema.json.template +16 -0
- package/src/ts/nx-generator/files/local/files/hello.ts.template.template +4 -0
- package/src/ts/nx-generator/files/local/generator.spec.ts.template +17 -0
- package/src/ts/nx-generator/files/local/generator.ts.template +9 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/docs/__nameKebabCase__.mdx.template +41 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.spec.ts.template +27 -0
- package/src/ts/nx-generator/files/nx-plugin-for-aws/generator/generator.ts.template +22 -0
- package/src/ts/nx-generator/generator.d.ts +9 -0
- package/src/ts/nx-generator/generator.js +137 -0
- package/src/ts/nx-generator/generator.js.map +1 -0
- package/src/ts/nx-generator/schema.d.ts +11 -0
- package/src/ts/nx-generator/schema.json +38 -0
- package/src/utils/versions.d.ts +3 -1
- package/src/utils/versions.js +2 -0
- 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": "
|
|
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
|
@@ -429,6 +429,9 @@ export class StaticWebsite extends Construct {
|
|
|
429
429
|
new CfnOutput(this, 'DistributionDomainName', {
|
|
430
430
|
value: this.cloudFrontDistribution.domainName,
|
|
431
431
|
});
|
|
432
|
+
new CfnOutput(this, 'WebsiteBucketName', {
|
|
433
|
+
value: this.websiteBucket.bucketName,
|
|
434
|
+
});
|
|
432
435
|
}
|
|
433
436
|
private resolveTokens = (payload: any) => {
|
|
434
437
|
const _payload: Record<string, any> = {};
|
package/src/cloudscape-website/app/files/common/constructs/src/core/static-website.ts.template
CHANGED
|
@@ -132,6 +132,9 @@ export class StaticWebsite extends Construct {
|
|
|
132
132
|
new CfnOutput(this, 'DistributionDomainName', {
|
|
133
133
|
value: this.cloudFrontDistribution.domainName,
|
|
134
134
|
});
|
|
135
|
+
new CfnOutput(this, 'WebsiteBucketName', {
|
|
136
|
+
value: this.websiteBucket.bucketName,
|
|
137
|
+
});
|
|
135
138
|
}
|
|
136
139
|
private resolveTokens = (payload: any) => {
|
|
137
140
|
const _payload: Record<string, any> = {};
|
|
@@ -43,10 +43,10 @@ function appGenerator(tree, schema) {
|
|
|
43
43
|
targets['load:runtime-config'] = {
|
|
44
44
|
executor: 'nx:run-commands',
|
|
45
45
|
metadata: {
|
|
46
|
-
description: `Load runtime config from your deployed stack for dev purposes. You must set
|
|
46
|
+
description: `Load runtime config from your deployed stack for dev purposes. You must set your AWS CLI credentials whilst calling 'pnpm exec nx run ${fullyQualifiedName}:load:runtime-config'`,
|
|
47
47
|
},
|
|
48
48
|
options: {
|
|
49
|
-
command: `
|
|
49
|
+
command: `aws s3 cp s3://\`aws cloudformation describe-stacks --query "Stacks[?StackName=='${(0, lodash_kebabcase_1.default)(npmScopePrefix)}-infra-sandbox'][].Outputs[?contains(OutputKey, 'WebsiteBucketName')].OutputValue" --output text\`/runtime-config.json './${websiteContentPath}/public/runtime-config.json'`,
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
const buildTarget = targets['build'];
|
|
@@ -68,7 +68,7 @@ function appGenerator(tree, schema) {
|
|
|
68
68
|
...((_b = buildTarget.dependsOn) !== null && _b !== void 0 ? _b : []),
|
|
69
69
|
],
|
|
70
70
|
options: {
|
|
71
|
-
outputPath: (0, devkit_1.joinPathFragments)('dist', websiteContentPath),
|
|
71
|
+
outputPath: (0, devkit_1.joinPathFragments)('dist', websiteContentPath, 'bundle'),
|
|
72
72
|
},
|
|
73
73
|
};
|
|
74
74
|
projectConfiguration.targets = (0, object_1.sortObjectKeys)(targets);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/app/generator.ts"],"names":[],"mappings":";;;AAoDA,oCA4YC;;AAhcD;;;GAGG;AACH,uCAaoB;AACpB,2CAKoB;AAEpB,qCAAiD;AACjD,qEAA0E;AAC1E,yFAGiD;AACjD,qDAAwE;AACxE,oEAAmE;AACnE,mDAAoD;AACpD,6CAA0D;AAC1D,6CAA6D;AAC7D,yCAKyB;AACzB,+CAA0D;AAC1D,+BAAgC;AAChC,gFAAyC;AACzC,+CAAoD;AACpD,uCAAmE;AACnE,iDAAsE;AAEzD,QAAA,qCAAqC,GAChD,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;AAE/B,SAAsB,YAAY,CAAC,IAAU,EAAE,MAA0B;;;QACvE,MAAM,cAAc,GAAG,IAAA,6BAAiB,EAAC,IAAI,CAAC,CAAC;QAC/C,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,oBAAoB,GAAG,IAAA,mBAAW,EAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACtD,MAAM,kBAAkB,GAAG,GAAG,cAAc,GAAG,oBAAoB,EAAE,CAAC;QACtE,MAAM,kBAAkB,GAAG,IAAA,0BAAiB,EAC1C,MAAA,MAAM,CAAC,SAAS,mCAAI,GAAG,EACvB,oBAAoB,CACrB,CAAC;QACF,mDAAmD;QACnD,MAAM,aAAa,GAAG,MAAM,CAAC;QAC7B,MAAM,IAAA,4BAAoB,EAAC,IAAI,kCAC1B,MAAM,KACT,IAAI,EAAE,kBAAkB,EACxB,SAAS,EAAE,kBAAkB,EAC7B,OAAO,EAAE,KAAK,EACd,aAAa,EACb,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,MAAM,EACf,cAAc,EAAE,QAAQ,EACxB,cAAc,EAAE,IAAI,EACpB,KAAK,EAAE,KAAK,IACZ,CAAC;QAEH,0CAA0C;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAA,0BAAiB,EAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;QAE1D,MAAM,oBAAoB,GAAG,IAAA,iCAAwB,EACnD,IAAI,EACJ,kBAAkB,CACnB,CAAC;QACF,MAAM,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC;QAC7C,OAAO,CAAC,qBAAqB,CAAC,GAAG;YAC/B,QAAQ,EAAE,iBAAiB;YAC3B,QAAQ,EAAE;gBACR,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../../../../../../packages/nx-plugin/src/cloudscape-website/app/generator.ts"],"names":[],"mappings":";;;AAoDA,oCA4YC;;AAhcD;;;GAGG;AACH,uCAaoB;AACpB,2CAKoB;AAEpB,qCAAiD;AACjD,qEAA0E;AAC1E,yFAGiD;AACjD,qDAAwE;AACxE,oEAAmE;AACnE,mDAAoD;AAC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mBAAU,EACR,IAAI,EACJ,IAAA,0BAAiB,EAAC,kBAAkB,EAAE,mBAAmB,CAAC,EAC1D,CAAC,QAAQ,EAAE,EAAE,CAAC,iCACT,QAAQ,KACX,eAAe,kCACV,QAAQ,CAAC,eAAe,KAC3B,MAAM,EAAE,OAAO,EACf,eAAe,EAAE,IAAA,0BAAiB,EAAC,OAAO,EAAE,0BAA0B,CAAC,EACvE,GAAG,EAAE,CAAC,KAAK,CAAC,OAEd,CACH,CAAC;QACF,IAAA,qCAA4B,EAC1B,IAAI,EACJ,IAAA,uBAAY,EAAC;YACX,+BAA+B;YAC/B,qCAAqC;YACrC,kCAAkC;YAClC,wBAAwB;SACzB,CAAC,EACF,IAAA,uBAAY,EAAC,CAAC,yBAAyB,EAAE,qBAAqB,CAAC,CAAC,CACjE,CAAC;QAEF,MAAM,IAAA,yCAA+B,EAAC,IAAI,EAAE;YAC1C,6CAAqC;SACtC,CAAC,CAAC;QAEH,MAAM,IAAA,6BAAoB,EAAC,IAAI,CAAC,CAAC;QACjC,OAAO,GAAG,EAAE;YACV,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;gBACxB,IAAA,4BAAmB,EAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;CAAA;AACD,kBAAe,YAAY,CAAC"}
|
|
@@ -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","source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,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,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,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;
|