@aws/nx-plugin 1.0.0-rc.44 → 1.0.0-rc.45
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/generators.json +6 -0
- package/package.json +1 -1
- package/src/agentcore-gateway/files/cedar/policies/README.md +9 -0
- package/src/agentcore-gateway/files/cedar/policies/permit-all.cedar +15 -0
- package/src/agentcore-gateway/generator.js +12 -5
- package/src/agentcore-gateway/generator.js.map +1 -1
- package/src/agentcore-gateway/schema.d.js.map +1 -1
- package/src/agentcore-gateway/schema.d.ts +1 -1
- package/src/agentcore-gateway/schema.json +3 -2
- package/src/mcp-server/tools/general-guidance.js +1 -1
- package/src/mcp-server/tools/general-guidance.js.map +1 -1
- package/src/preset/__snapshots__/generator.spec.ts.snap +5 -2
- package/src/py/agent/gateway-connection/generator.js +1 -1
- package/src/py/agent/gateway-connection/generator.js.map +1 -1
- package/src/py/rdb/__snapshots__/generator.spec.ts.snap +16 -0
- package/src/py/rdb/files/Dockerfile.create-db-user.template +4 -0
- package/src/py/rdb/files/Dockerfile.migration.template +4 -0
- package/src/sdk/ts.d.ts +2 -0
- package/src/sdk/ts.js +2 -0
- package/src/sdk/ts.js.map +1 -1
- package/src/ts/agent/__snapshots__/generator.spec.ts.snap +5 -1
- package/src/ts/agent/files/deploy/Dockerfile.template +5 -1
- package/src/ts/agent/gateway-connection/generator.js +1 -1
- package/src/ts/agent/gateway-connection/generator.js.map +1 -1
- package/src/ts/agent/generator.js +6 -0
- package/src/ts/agent/generator.js.map +1 -1
- package/src/ts/dcr-proxy/__snapshots__/generator.spec.ts.snap +982 -0
- package/src/ts/dcr-proxy/generator.d.ts +10 -0
- package/src/ts/dcr-proxy/generator.js +98 -0
- package/src/ts/dcr-proxy/generator.js.map +1 -0
- package/src/ts/dcr-proxy/schema.d.js +6 -0
- package/src/ts/dcr-proxy/schema.d.js.map +1 -0
- package/src/ts/dcr-proxy/schema.d.ts +13 -0
- package/src/ts/dcr-proxy/schema.json +44 -0
- package/src/ts/mcp-server/files/Dockerfile.template +5 -1
- package/src/ts/mcp-server/generator.js +1 -0
- package/src/ts/mcp-server/generator.js.map +1 -1
- package/src/ts/nx-plugin/__snapshots__/generator.spec.ts.snap +2 -2
- package/src/ts/nx-plugin/files/mcp-server/resources/GENERAL_GUIDANCE.md.template +1 -1
- package/src/ts/nx-plugin/files/mcp-server/utils.ts.template +1 -1
- package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +7 -0
- package/src/ts/rdb/files/Dockerfile.template +7 -0
- package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +4 -4
- package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +1 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js +2 -0
- package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
- package/src/utils/agent-core-constructs/files/cdk/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.ts.template +38 -3
- package/src/utils/agent-core-constructs/files/cdk/core/agentcore-gateway/agentcore-gateway.ts.template +13 -3
- package/src/utils/agent-core-constructs/files/terraform/app/agentcore-gateway/__nameKebabCase__/__nameKebabCase__.tf.template +22 -1
- package/src/utils/commands.js +1 -1
- package/src/utils/commands.js.map +1 -1
- package/src/utils/dcr-proxy-constructs/dcr-proxy-constructs.d.ts +38 -0
- package/src/utils/dcr-proxy-constructs/dcr-proxy-constructs.js +93 -0
- package/src/utils/dcr-proxy-constructs/dcr-proxy-constructs.js.map +1 -0
- package/src/utils/dcr-proxy-constructs/files/cdk/app/dcr-proxies/__nameKebabCase__/__nameKebabCase__.ts.template +227 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/authorization-server-metadata.ts.template +39 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/authorize.ts.template +26 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/mcp-proxy.ts.template +89 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/protected-resource-metadata.ts.template +13 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/register.ts.template +70 -0
- package/src/utils/dcr-proxy-constructs/files/project/src/handlers/token.ts.template +75 -0
- package/src/utils/dcr-proxy-constructs/files/terraform/app/dcr-proxies/__nameKebabCase__/__nameKebabCase__.tf.template +410 -0
- package/src/utils/docker.d.ts +4 -3
- package/src/utils/docker.js +11 -7
- package/src/utils/docker.js.map +1 -1
- package/src/utils/format.d.ts +1 -1
- package/src/utils/format.js +3 -2
- package/src/utils/format.js.map +1 -1
- package/src/utils/init.js +4 -0
- package/src/utils/init.js.map +1 -1
- package/src/utils/versions.d.ts +3 -1
- package/src/utils/versions.js +4 -0
- package/src/utils/versions.js.map +1 -1
|
@@ -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 { type GeneratorCallback, type Tree } from '@nx/devkit';
|
|
6
|
+
import { type NxGeneratorInfo } from '../../utils/nx';
|
|
7
|
+
import type { TsDcrProxyGeneratorSchema } from './schema';
|
|
8
|
+
export declare const TS_DCR_PROXY_GENERATOR_INFO: NxGeneratorInfo;
|
|
9
|
+
export declare const tsDcrProxyGenerator: (tree: Tree, options: TsDcrProxyGeneratorSchema) => Promise<GeneratorCallback>;
|
|
10
|
+
export default tsDcrProxyGenerator;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/ import { addDependenciesToPackageJson, generateFiles, joinPathFragments, OverwriteStrategy, updateProjectConfiguration } from "@nx/devkit";
|
|
5
|
+
import tsProjectGenerator from "../lib/generator.js";
|
|
6
|
+
import { addTypeScriptBundleTarget } from "../../utils/bundle/bundle.js";
|
|
7
|
+
import { addDcrProxyInfra, DCR_PROXY_HANDLERS } from "../../utils/dcr-proxy-constructs/dcr-proxy-constructs.js";
|
|
8
|
+
import { formatFilesInSubtree } from "../../utils/format.js";
|
|
9
|
+
import { resolveIac } from "../../utils/iac.js";
|
|
10
|
+
import { installDependencies } from "../../utils/install.js";
|
|
11
|
+
import { addGeneratorMetricsIfApplicable } from "../../utils/metrics.js";
|
|
12
|
+
import { kebabCase, toClassName } from "../../utils/names.js";
|
|
13
|
+
import { getNpmScopePrefix } from "../../utils/npm-scope.js";
|
|
14
|
+
import { getGeneratorInfo, readProjectConfigurationUnqualified } from "../../utils/nx.js";
|
|
15
|
+
import { sortObjectKeys } from "../../utils/object.js";
|
|
16
|
+
import { sharedConstructsGenerator } from "../../utils/shared-constructs.js";
|
|
17
|
+
import { withVersions } from "../../utils/versions.js";
|
|
18
|
+
export const TS_DCR_PROXY_GENERATOR_INFO = getGeneratorInfo(import.meta.filename);
|
|
19
|
+
export const tsDcrProxyGenerator = async (tree, options)=>{
|
|
20
|
+
const name = kebabCase(options.name ? options.name : 'dcr-proxy');
|
|
21
|
+
const nameClassName = toClassName(name);
|
|
22
|
+
const iac = await resolveIac(tree, options.iac);
|
|
23
|
+
// The handlers live in a standalone TypeScript project so they can be bundled
|
|
24
|
+
// (rolldown) into deployable artifacts referenced by both CDK and Terraform.
|
|
25
|
+
const namespace = getNpmScopePrefix(tree);
|
|
26
|
+
const proxyProjectName = `${namespace}${name}`;
|
|
27
|
+
let projectExists;
|
|
28
|
+
try {
|
|
29
|
+
readProjectConfigurationUnqualified(tree, proxyProjectName);
|
|
30
|
+
projectExists = true;
|
|
31
|
+
} catch {
|
|
32
|
+
projectExists = false;
|
|
33
|
+
}
|
|
34
|
+
if (!projectExists) {
|
|
35
|
+
await tsProjectGenerator(tree, {
|
|
36
|
+
name,
|
|
37
|
+
directory: options.directory,
|
|
38
|
+
subDirectory: options.subDirectory,
|
|
39
|
+
preferInstallDependencies: false
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const projectConfig = readProjectConfigurationUnqualified(tree, proxyProjectName);
|
|
43
|
+
const proxyRoot = projectConfig.root;
|
|
44
|
+
// Place the Lambda handlers in the project source
|
|
45
|
+
generateFiles(tree, joinPathFragments(import.meta.dirname, '..', '..', 'utils', 'dcr-proxy-constructs', 'files', 'project'), proxyRoot, {
|
|
46
|
+
nameClassName,
|
|
47
|
+
nameKebabCase: name
|
|
48
|
+
}, {
|
|
49
|
+
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
50
|
+
});
|
|
51
|
+
// The token handler imports @aws-sdk/client-secrets-manager (provided by the
|
|
52
|
+
// Lambda runtime but needed for type-checking and local dev) and the handlers
|
|
53
|
+
// are typed against @types/aws-lambda.
|
|
54
|
+
addDependenciesToPackageJson(tree, withVersions([
|
|
55
|
+
'@aws-sdk/client-secrets-manager'
|
|
56
|
+
]), withVersions([
|
|
57
|
+
'@types/aws-lambda'
|
|
58
|
+
]));
|
|
59
|
+
// Bundle each handler independently to dist/<root>/bundle/<handler>/index.js
|
|
60
|
+
for (const handler of DCR_PROXY_HANDLERS){
|
|
61
|
+
await addTypeScriptBundleTarget(tree, projectConfig, {
|
|
62
|
+
targetFilePath: `src/handlers/${handler}.ts`,
|
|
63
|
+
bundleOutputDir: handler,
|
|
64
|
+
external: [
|
|
65
|
+
/@aws-sdk\/.*/
|
|
66
|
+
],
|
|
67
|
+
platform: 'node'
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
projectConfig.targets = sortObjectKeys(projectConfig.targets);
|
|
71
|
+
updateProjectConfiguration(tree, projectConfig.name, projectConfig);
|
|
72
|
+
const bundlePathsFromRoot = Object.fromEntries(DCR_PROXY_HANDLERS.map((handler)=>[
|
|
73
|
+
handler,
|
|
74
|
+
joinPathFragments('dist', proxyRoot, 'bundle', handler)
|
|
75
|
+
]));
|
|
76
|
+
await sharedConstructsGenerator(tree, {
|
|
77
|
+
iac
|
|
78
|
+
});
|
|
79
|
+
await addDcrProxyInfra(tree, {
|
|
80
|
+
dcrProxyNameClassName: nameClassName,
|
|
81
|
+
dcrProxyNameKebabCase: name,
|
|
82
|
+
proxyProjectName,
|
|
83
|
+
bundlePathsFromRoot,
|
|
84
|
+
iac
|
|
85
|
+
});
|
|
86
|
+
await addGeneratorMetricsIfApplicable(tree, [
|
|
87
|
+
TS_DCR_PROXY_GENERATOR_INFO
|
|
88
|
+
]);
|
|
89
|
+
await formatFilesInSubtree(tree);
|
|
90
|
+
return ()=>installDependencies(tree, options.preferInstallDependencies, {
|
|
91
|
+
languages: [
|
|
92
|
+
'typescript'
|
|
93
|
+
]
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
export default tsDcrProxyGenerator;
|
|
97
|
+
|
|
98
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/dcr-proxy/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type Tree,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport tsProjectGenerator from '../../ts/lib/generator';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport {\n addDcrProxyInfra,\n DCR_PROXY_HANDLERS,\n type DcrProxyHandler,\n} from '../../utils/dcr-proxy-constructs/dcr-proxy-constructs';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScopePrefix } from '../../utils/npm-scope';\nimport {\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { withVersions } from '../../utils/versions';\nimport type { TsDcrProxyGeneratorSchema } from './schema';\n\nexport const TS_DCR_PROXY_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsDcrProxyGenerator = async (\n tree: Tree,\n options: TsDcrProxyGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const name = kebabCase(options.name ? options.name : 'dcr-proxy');\n const nameClassName = toClassName(name);\n\n const iac = await resolveIac(tree, options.iac);\n\n // The handlers live in a standalone TypeScript project so they can be bundled\n // (rolldown) into deployable artifacts referenced by both CDK and Terraform.\n const namespace = getNpmScopePrefix(tree);\n const proxyProjectName = `${namespace}${name}`;\n\n let projectExists: boolean;\n try {\n readProjectConfigurationUnqualified(tree, proxyProjectName);\n projectExists = true;\n } catch {\n projectExists = false;\n }\n\n if (!projectExists) {\n await tsProjectGenerator(tree, {\n name,\n directory: options.directory,\n subDirectory: options.subDirectory,\n preferInstallDependencies: false,\n });\n }\n\n const projectConfig = readProjectConfigurationUnqualified(\n tree,\n proxyProjectName,\n );\n const proxyRoot = projectConfig.root;\n\n // Place the Lambda handlers in the project source\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n '..',\n '..',\n 'utils',\n 'dcr-proxy-constructs',\n 'files',\n 'project',\n ),\n proxyRoot,\n { nameClassName, nameKebabCase: name },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // The token handler imports @aws-sdk/client-secrets-manager (provided by the\n // Lambda runtime but needed for type-checking and local dev) and the handlers\n // are typed against @types/aws-lambda.\n addDependenciesToPackageJson(\n tree,\n withVersions(['@aws-sdk/client-secrets-manager']),\n withVersions(['@types/aws-lambda']),\n );\n\n // Bundle each handler independently to dist/<root>/bundle/<handler>/index.js\n for (const handler of DCR_PROXY_HANDLERS) {\n await addTypeScriptBundleTarget(tree, projectConfig, {\n targetFilePath: `src/handlers/${handler}.ts`,\n bundleOutputDir: handler,\n external: [/@aws-sdk\\/.*/], // lambda runtime provides the aws sdk\n platform: 'node',\n });\n }\n\n projectConfig.targets = sortObjectKeys(projectConfig.targets);\n updateProjectConfiguration(tree, projectConfig.name, projectConfig);\n\n const bundlePathsFromRoot = Object.fromEntries(\n DCR_PROXY_HANDLERS.map((handler) => [\n handler,\n joinPathFragments('dist', proxyRoot, 'bundle', handler),\n ]),\n ) as Record<DcrProxyHandler, string>;\n\n await sharedConstructsGenerator(tree, { iac });\n\n await addDcrProxyInfra(tree, {\n dcrProxyNameClassName: nameClassName,\n dcrProxyNameKebabCase: name,\n proxyProjectName,\n bundlePathsFromRoot,\n iac,\n });\n\n await addGeneratorMetricsIfApplicable(tree, [TS_DCR_PROXY_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsDcrProxyGenerator;\n"],"names":["addDependenciesToPackageJson","generateFiles","joinPathFragments","OverwriteStrategy","updateProjectConfiguration","tsProjectGenerator","addTypeScriptBundleTarget","addDcrProxyInfra","DCR_PROXY_HANDLERS","formatFilesInSubtree","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","kebabCase","toClassName","getNpmScopePrefix","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","sharedConstructsGenerator","withVersions","TS_DCR_PROXY_GENERATOR_INFO","filename","tsDcrProxyGenerator","tree","options","name","nameClassName","iac","namespace","proxyProjectName","projectExists","directory","subDirectory","preferInstallDependencies","projectConfig","proxyRoot","root","dirname","nameKebabCase","overwriteStrategy","KeepExisting","handler","targetFilePath","bundleOutputDir","external","platform","targets","bundlePathsFromRoot","Object","fromEntries","map","dcrProxyNameClassName","dcrProxyNameKebabCase","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAE5BC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAEjBC,0BAA0B,QACrB,aAAa;AACpB,OAAOC,wBAAwB,sBAAyB;AACxD,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BACA,SACA,YAEFF,WACA;QAAET;QAAeY,eAAeb;IAAK,GACrC;QACEc,mBAAmBrC,kBAAkBsC,YAAY;IACnD;IAGF,6EAA6E;IAC7E,8EAA8E;IAC9E,uCAAuC;IACvCzC,6BACEwB,MACAJ,aAAa;QAAC;KAAkC,GAChDA,aAAa;QAAC;KAAoB;IAGpC,6EAA6E;IAC7E,KAAK,MAAMsB,WAAWlC,mBAAoB;QACxC,MAAMF,0BAA0BkB,MAAMW,eAAe;YACnDQ,gBAAgB,CAAC,aAAa,EAAED,QAAQ,GAAG,CAAC;YAC5CE,iBAAiBF;YACjBG,UAAU;gBAAC;aAAe;YAC1BC,UAAU;QACZ;IACF;IAEAX,cAAcY,OAAO,GAAG7B,eAAeiB,cAAcY,OAAO;IAC5D3C,2BAA2BoB,MAAMW,cAAcT,IAAI,EAAES;IAErD,MAAMa,sBAAsBC,OAAOC,WAAW,CAC5C1C,mBAAmB2C,GAAG,CAAC,CAACT,UAAY;YAClCA;YACAxC,kBAAkB,QAAQkC,WAAW,UAAUM;SAChD;IAGH,MAAMvB,0BAA0BK,MAAM;QAAEI;IAAI;IAE5C,MAAMrB,iBAAiBiB,MAAM;QAC3B4B,uBAAuBzB;QACvB0B,uBAAuB3B;QACvBI;QACAkB;QACApB;IACF;IAEA,MAAMhB,gCAAgCY,MAAM;QAACH;KAA4B;IAEzE,MAAMZ,qBAAqBe;IAC3B,OAAO,IACLb,oBAAoBa,MAAMC,QAAQS,yBAAyB,EAAE;YAC3DoB,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe/B,oBAAoB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/dcr-proxy/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport type { IacOption } from '../../utils/iac';\n\nexport interface TsDcrProxyGeneratorSchema {\n name?: string;\n directory?: string;\n subDirectory?: string;\n iac: IacOption;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAGD,WAMC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import type { IacOption } from '../../utils/iac';
|
|
6
|
+
|
|
7
|
+
export interface TsDcrProxyGeneratorSchema {
|
|
8
|
+
name?: string;
|
|
9
|
+
directory?: string;
|
|
10
|
+
subDirectory?: string;
|
|
11
|
+
iac: IacOption;
|
|
12
|
+
preferInstallDependencies?: boolean;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "ts#dcr-proxy",
|
|
4
|
+
"title": "ts#dcr-proxy",
|
|
5
|
+
"description": "Generate an OAuth Dynamic Client Registration (DCR) proxy construct for Cognito-authenticated MCP servers",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"name": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The name of your DCR proxy, used for its TypeScript handler project, the construct/module class name, and its directory under common/constructs or common/terraform",
|
|
11
|
+
"default": "dcr-proxy",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "What would you like to call your DCR proxy?",
|
|
17
|
+
"x-priority": "important"
|
|
18
|
+
},
|
|
19
|
+
"directory": {
|
|
20
|
+
"description": "The directory to store the DCR proxy handler project in.",
|
|
21
|
+
"type": "string",
|
|
22
|
+
"alias": "dir",
|
|
23
|
+
"x-priority": "important",
|
|
24
|
+
"default": "packages"
|
|
25
|
+
},
|
|
26
|
+
"subDirectory": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "The sub directory the handler project is placed in. By default this is the project name."
|
|
29
|
+
},
|
|
30
|
+
"iac": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "The preferred IaC provider (cdk or terraform). By default this is inherited from your initial selection.",
|
|
33
|
+
"enum": ["inherit", "cdk", "terraform"],
|
|
34
|
+
"x-priority": "important",
|
|
35
|
+
"default": "inherit",
|
|
36
|
+
"x-prompt": "Which provider would you like to manage your infrastructure? (default: inherit)"
|
|
37
|
+
},
|
|
38
|
+
"preferInstallDependencies": {
|
|
39
|
+
"type": "boolean",
|
|
40
|
+
"description": "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.",
|
|
41
|
+
"default": true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -7,7 +7,11 @@ WORKDIR /app
|
|
|
7
7
|
|
|
8
8
|
# Add AWS Distro for OpenTelemetry for observability
|
|
9
9
|
# https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/observability-configure.html
|
|
10
|
-
|
|
10
|
+
# The override pins @opentelemetry/propagator-jaeger above the version the
|
|
11
|
+
# autoinstrumentation package resolves transitively, clearing CVE-2026-59892.
|
|
12
|
+
RUN npm init -y \
|
|
13
|
+
&& npm pkg set "overrides.@opentelemetry/propagator-jaeger=<%- jaegerVersion %>" \
|
|
14
|
+
&& npm install @aws/aws-distro-opentelemetry-node-autoinstrumentation@<%- adotVersion %>
|
|
11
15
|
|
|
12
16
|
# Copy bundled streamable http server
|
|
13
17
|
COPY index.js /app
|
|
@@ -51,6 +51,7 @@ export const tsMcpServerGenerator = async (tree, options)=>{
|
|
|
51
51
|
esm,
|
|
52
52
|
distDir,
|
|
53
53
|
adotVersion: TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],
|
|
54
|
+
jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],
|
|
54
55
|
nodeBaseImage: BASE_IMAGES.node,
|
|
55
56
|
npmVersion: TS_VERSIONS.npm
|
|
56
57
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDockerScanTarget } from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { BASE_IMAGES, TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsMcpServerGeneratorSchema } from './schema';\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the module system is esm, otherwise commonjs. Projects\n // don't typically have their own package.json (dependencies are declared in\n // the workspace root), so fall back to the workspace format when absent.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n nodeBaseImage: BASE_IMAGES.node,\n npmVersion: TS_VERSIONS.npm,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add dependencies\n const deps = withVersions([\n '@modelcontextprotocol/sdk',\n 'zod',\n 'express',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]);\n const devDeps = withVersions([\n 'tsx',\n '@types/express',\n '@modelcontextprotocol/inspector',\n ]);\n\n // Add hosting based on infra\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n });\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n addDockerScanTarget(tree, {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n });\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n addDependenciesToPackageJson(tree, deps, devDeps);\n // Add to the project's package.json too if it has one (e.g. nx plugins),\n // otherwise dependencies live in the workspace root only.\n if (tree.exists(projectPackageJsonPath)) {\n addDependenciesToPackageJson(tree, deps, devDeps, projectPackageJsonPath);\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["addDependenciesToPackageJson","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addMcpServerInfra","addTypeScriptBundleTarget","resolveContainers","addDockerScanTarget","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","withVersions","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","nodeBaseImage","node","npmVersion","npm","overwriteStrategy","KeepExisting","deps","devDeps","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","iac","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SAASC,iBAAiB,QAAQ,6DAA0D;AAC5F,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,mBAAmB,QAAQ,wBAAqB;AACzD,SAASC,oBAAoB,QAAQ,wBAAqB;AAC1D,SAASC,UAAU,QAAQ,oBAAiB;AAC5C,SAASC,UAAU,QAAQ,qBAAkB;AAC7C,SAASC,mBAAmB,QAAQ,yBAAsB;AAC1D,SAASC,+BAA+B,QAAQ,yBAAsB;AACtE,SAASC,cAAc,QAAQ,+BAA4B;AAC3D,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAoB;AAC3D,SAASC,WAAW,QAAQ,2BAAwB;AACpD,SACEC,qBAAqB,EACrBC,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAiB;AACxB,SAASC,cAAc,QAA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AQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBuC,SAASlD,eAAesE;IAC1B;IAEA1E,8BACEa,MACAE,QAAQK,IAAI,EACZV,8BACAe,sCACAD,iBACA;QACEwD,MAAMT;QACNU,IAAI1D;QACJQ;IACF;IAGF,MAAMrC,gCAAgCmB,MAAM;QAACH;KAA6B;IAE1E,MAAM1B,wBAAwB6B,MAAM5B;IAEpC,MAAMK,qBAAqBuB;IAC3B,OAAO,IACLpB,oBAAoBoB,MAAMC,QAAQoE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAevE,qBAAqB"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/generator.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n addDependenciesToPackageJson,\n detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { ensureLicenseExceptions } from '../../license/config';\nimport { MCP_INSPECTOR_EXCEPTIONS } from '../../license/known-exceptions';\nimport { addMcpServerInfra } from '../../utils/agent-core-constructs/agent-core-constructs';\nimport { addTypeScriptBundleTarget } from '../../utils/bundle/bundle';\nimport { resolveContainers } from '../../utils/containers';\nimport { addDockerScanTarget } from '../../utils/docker';\nimport { formatFilesInSubtree } from '../../utils/format';\nimport { FsCommands } from '../../utils/fs';\nimport { resolveIac } from '../../utils/iac';\nimport { installDependencies } from '../../utils/install';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics';\nimport { isEsmWorkspace } from '../../utils/module-format';\nimport { kebabCase, toClassName } from '../../utils/names';\nimport { getNpmScope } from '../../utils/npm-scope';\nimport {\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx';\nimport { sortObjectKeys } from '../../utils/object';\nimport { assignPort } from '../../utils/port';\nimport { sharedConstructsGenerator } from '../../utils/shared-constructs';\nimport { BASE_IMAGES, TS_VERSIONS, withVersions } from '../../utils/versions';\nimport type { TsMcpServerGeneratorSchema } from './schema';\n\nexport const TS_MCP_SERVER_GENERATOR_INFO: NxGeneratorInfo = getGeneratorInfo(\n import.meta.filename,\n);\n\nexport const tsMcpServerGenerator = async (\n tree: Tree,\n options: TsMcpServerGeneratorSchema,\n): Promise<GeneratorCallback> => {\n const project = readProjectConfigurationUnqualified(tree, options.project);\n\n if (!tree.exists(joinPathFragments(project.root, 'tsconfig.json'))) {\n throw new Error(\n `Unsupported project ${options.project}. Expected a TypeScript project (with a tsconfig.json)`,\n );\n }\n\n const defaultName = `${kebabCase(project.name.split('/').pop())}-mcp-server`;\n const name = kebabCase(options.name || defaultName);\n const mcpServerNameClassName = toClassName(name);\n const mcpTargetPrefix = options.name ? name : 'mcp-server';\n const targetSourceDirRelativeToProjectRoot = joinPathFragments(\n 'src',\n mcpTargetPrefix,\n );\n const targetSourceDir = joinPathFragments(\n project.root,\n targetSourceDirRelativeToProjectRoot,\n );\n const relativeSourceDir = targetSourceDir.replace(project.root + '/', './');\n const distDir = joinPathFragments('dist', project.root);\n\n const infra = options.infra ?? 'agentcore';\n\n if (infra === 'none' && options.auth && options.auth !== 'iam') {\n console.warn(\n 'Warning: auth is ignored when no infrastructure is configured (no infrastructure is generated)',\n );\n }\n\n const auth = options.auth ?? 'iam';\n\n const projectPackageJsonPath = joinPathFragments(\n project.root,\n 'package.json',\n );\n\n // Generate esm if the module system is esm, otherwise commonjs. Projects\n // don't typically have their own package.json (dependencies are declared in\n // the workspace root), so fall back to the workspace format when absent.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files'),\n targetSourceDir,\n {\n name,\n esm,\n distDir,\n adotVersion:\n TS_VERSIONS['@aws/aws-distro-opentelemetry-node-autoinstrumentation'],\n jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],\n nodeBaseImage: BASE_IMAGES.node,\n npmVersion: TS_VERSIONS.npm,\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add dependencies\n const deps = withVersions([\n '@modelcontextprotocol/sdk',\n 'zod',\n 'express',\n '@aws-lambda-powertools/parameters',\n '@aws-sdk/client-appconfigdata',\n ]);\n const devDeps = withVersions([\n 'tsx',\n '@types/express',\n '@modelcontextprotocol/inspector',\n ]);\n\n // Add hosting based on infra\n if (infra === 'agentcore') {\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(tree, project, {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n });\n\n const dockerOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree);\n project.targets[dockerTargetName] = {\n cache: true,\n outputs: [`{workspaceRoot}/${dockerOutputDir}/Dockerfile`],\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${dockerOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addDependencyToTargetIfNotPresent(project, 'build', 'docker');\n\n addDockerScanTarget(tree, {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n });\n\n // Add shared constructs\n const iac = await resolveIac(tree, options.iac);\n await sharedConstructsGenerator(tree, { iac });\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n dockerImageTag,\n dockerOutputDir,\n iac,\n auth,\n containers,\n });\n } else {\n // No Dockerfile needed for non-hosted MCP\n tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));\n }\n\n addDependenciesToPackageJson(tree, deps, devDeps);\n // Add to the project's package.json too if it has one (e.g. nx plugins),\n // otherwise dependencies live in the workspace root only.\n if (tree.exists(projectPackageJsonPath)) {\n addDependenciesToPackageJson(tree, deps, devDeps, projectPackageJsonPath);\n }\n\n // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range\n // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so\n // without a resolution it installs a separate zod under the SDK's own node_modules.\n // The two zod copies have structurally incompatible types, which breaks type\n // inference for registerTool inputSchema. Scope the resolution to the SDK so\n // other consumers (e.g. @tanstack/router-generator pinning zod@3) are unaffected.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\n };\n return packageJson;\n });\n }\n\n const localDevPort = assignPort(tree, project, 8000, {\n component: { info: TS_MCP_SERVER_GENERATOR_INFO, name: mcpTargetPrefix },\n });\n\n const mcpTargets = {\n ...project.targets,\n // Add targets for running the MCP server\n [`${mcpTargetPrefix}-serve-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/stdio.ts`],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-serve`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n },\n },\n },\n [`${mcpTargetPrefix}-dev`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [`tsx --watch ${relativeSourceDir}/http.ts`],\n cwd: '{projectRoot}',\n env: {\n PORT: `${localDevPort}`,\n LOCAL_DEV: 'true',\n },\n },\n },\n [`${mcpTargetPrefix}-inspect`]: {\n executor: 'nx:run-commands',\n continuous: true,\n // Launch the inspector against the locally served HTTP server. The dev\n // target starts the server and any connected dependencies (e.g. a local\n // database).\n dependsOn: [`${mcpTargetPrefix}-dev`],\n options: {\n commands: [\n `mcp-inspector --transport http --server-url http://localhost:${localDevPort}/mcp`,\n ],\n cwd: '{projectRoot}',\n },\n },\n [`${mcpTargetPrefix}-inspect-stdio`]: {\n executor: 'nx:run-commands',\n continuous: true,\n options: {\n commands: [\n `mcp-inspector -- tsx --watch ${relativeSourceDir}/stdio.ts`,\n ],\n cwd: '{projectRoot}',\n },\n },\n };\n\n // Aggregate `<mcp>-dev` under the project-level `dev` target.\n addComponentDevTarget(mcpTargets, `${mcpTargetPrefix}-dev`);\n\n updateProjectConfiguration(tree, project.name, {\n ...project,\n // Sort targets so their order is stable regardless of insertion order on\n // first run vs re-run.\n targets: sortObjectKeys(mcpTargets),\n });\n\n addComponentGeneratorMetadata(\n tree,\n project.name,\n TS_MCP_SERVER_GENERATOR_INFO,\n targetSourceDirRelativeToProjectRoot,\n mcpTargetPrefix,\n {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n },\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await ensureLicenseExceptions(tree, MCP_INSPECTOR_EXCEPTIONS);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["addDependenciesToPackageJson","detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","ensureLicenseExceptions","MCP_INSPECTOR_EXCEPTIONS","addMcpServerInfra","addTypeScriptBundleTarget","resolveContainers","addDockerScanTarget","formatFilesInSubtree","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","assignPort","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","withVersions","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","root","Error","defaultName","name","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","jaegerVersion","nodeBaseImage","node","npmVersion","npm","overwriteStrategy","KeepExisting","deps","devDeps","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","outputs","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","iac","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","port","rc","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,4BAA4B,EAC5BC,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,uBAAuB,QAAQ,0BAAuB;AAC/D,SAASC,wBAAwB,QAAQ,oCAAiC;AAC1E,SAASC,iBAAiB,QAAQ,6DAA0D;AAC5F,SAASC,yBAAyB,QAAQ,+BAA4B;AACtE,SAASC,iBAAiB,QAAQ,4BAAyB;AAC3D,SAASC,mBAAmB,QAAQ,wBAAqB;AACzD,SAASC,oBA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AW;gBAAC,GAAGtC,gBAAgB,IAAI,CAAC;aAAC;YACrCV,SAAS;gBACP6C,UAAU;oBACR,CAAC,6DAA6D,EAAEa,aAAa,IAAI,CAAC;iBACnF;gBACDK,KAAK;YACP;QACF;QACA,CAAC,GAAGrD,gBAAgB,cAAc,CAAC,CAAC,EAAE;YACpCkC,UAAU;YACVkB,YAAY;YACZ9D,SAAS;gBACP6C,UAAU;oBACR,CAAC,6BAA6B,EAAEhC,kBAAkB,SAAS,CAAC;iBAC7D;gBACDkD,KAAK;YACP;QACF;IACF;IAEA,8DAA8D;IAC9D9E,sBAAsB4E,YAAY,GAAGnD,gBAAgB,IAAI,CAAC;IAE1DzC,2BAA2B8B,MAAME,QAAQK,IAAI,EAAE;QAC7C,GAAGL,OAAO;QACV,yEAAyE;QACzE,uBAAuB;QACvBwC,SAASnD,eAAeuE;IAC1B;IAEA3E,8BACEa,MACAE,QAAQK,IAAI,EACZV,8BACAe,sCACAD,iBACA;QACEyD,MAAMT;QACNU,IAAI3D;QACJQ;IACF;IAGF,MAAMrC,gCAAgCmB,MAAM;QAACH;KAA6B;IAE1E,MAAM1B,wBAAwB6B,MAAM5B;IAEpC,MAAMK,qBAAqBuB;IAC3B,OAAO,IACLpB,oBAAoBoB,MAAMC,QAAQqE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAexE,qBAAqB"}
|
|
@@ -127,7 +127,7 @@ exports[`ts#nx-plugin generator > should generate MCP server files > test-plugin
|
|
|
127
127
|
- pnpm add -w -D <package>
|
|
128
128
|
- yarn add -D <package>
|
|
129
129
|
- npm install --legacy-peer-deps -D <package>
|
|
130
|
-
- bun
|
|
130
|
+
- bun add -D <package>
|
|
131
131
|
- (Omit -D for production dependencies)
|
|
132
132
|
- When specifying project names as arguments to generators, prefer the _fully qualified_ project name, for example \`@workspace-name/project-name\`. Check the \`project.json\` file for the specific package to find its fully qualified name
|
|
133
133
|
- When no generator exists for a specific framework required, look for more generic project generators if availalbe and build on top of these.
|
|
@@ -482,7 +482,7 @@ export const buildInstallCommand = (pm: string, pkg: string) =>
|
|
|
482
482
|
pnpm: \`pnpm add -Dw \${pkg}\`,
|
|
483
483
|
yarn: \`yarn add -D \${pkg}\`,
|
|
484
484
|
npm: \`npm install --legacy-peer-deps -D \${pkg}\`,
|
|
485
|
-
bun: \`bun
|
|
485
|
+
bun: \`bun add -D \${pkg}\`,
|
|
486
486
|
})[pm];
|
|
487
487
|
|
|
488
488
|
const renderSchema = (schema: any) =>
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
- pnpm add -w -D <package>
|
|
31
31
|
- yarn add -D <package>
|
|
32
32
|
- npm install --legacy-peer-deps -D <package>
|
|
33
|
-
- bun
|
|
33
|
+
- bun add -D <package>
|
|
34
34
|
- (Omit -D for production dependencies)
|
|
35
35
|
- When specifying project names as arguments to generators, prefer the _fully qualified_ project name, for example `@workspace-name/project-name`. Check the `project.json` file for the specific package to find its fully qualified name
|
|
36
36
|
- When no generator exists for a specific framework required, look for more generic project generators if availalbe and build on top of these.
|
|
@@ -56,7 +56,7 @@ export const buildInstallCommand = (pm: string, pkg: string) =>
|
|
|
56
56
|
pnpm: `pnpm add -Dw ${pkg}`,
|
|
57
57
|
yarn: `yarn add -D ${pkg}`,
|
|
58
58
|
npm: `npm install --legacy-peer-deps -D ${pkg}`,
|
|
59
|
-
bun: `bun
|
|
59
|
+
bun: `bun add -D ${pkg}`,
|
|
60
60
|
})[pm];
|
|
61
61
|
|
|
62
62
|
const renderSchema = (schema: any) =>
|
|
@@ -4669,6 +4669,13 @@ exports[`ts#rdb generator > should generate the aurora shared construct 4`] = `
|
|
|
4669
4669
|
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
4670
4670
|
RUN npm install -g npm@12.0.1
|
|
4671
4671
|
|
|
4672
|
+
# Patch OS packages beyond the base image's pinned release, and drop the
|
|
4673
|
+
# runtime's convenience copy of the AWS SDK (the handler bundle inlines its
|
|
4674
|
+
# own dependencies), keeping the image free of known HIGH/CRITICAL
|
|
4675
|
+
# vulnerabilities
|
|
4676
|
+
RUN microdnf upgrade -y --releasever latest && microdnf clean all \\
|
|
4677
|
+
&& rm -rf /var/runtime/node_modules/@aws-sdk
|
|
4678
|
+
|
|
4672
4679
|
WORKDIR \${LAMBDA_TASK_ROOT}
|
|
4673
4680
|
|
|
4674
4681
|
# npm blocks dependency install scripts by default; allow prisma's so its
|
|
@@ -3,6 +3,13 @@ FROM public.ecr.aws/lambda/nodejs:24
|
|
|
3
3
|
# Upgrade npm to a version free of known HIGH/CRITICAL vulnerabilities
|
|
4
4
|
RUN npm install -g npm@<%= npmVersion %>
|
|
5
5
|
|
|
6
|
+
# Patch OS packages beyond the base image's pinned release, and drop the
|
|
7
|
+
# runtime's convenience copy of the AWS SDK (the handler bundle inlines its
|
|
8
|
+
# own dependencies), keeping the image free of known HIGH/CRITICAL
|
|
9
|
+
# vulnerabilities
|
|
10
|
+
RUN microdnf upgrade -y --releasever latest && microdnf clean all \
|
|
11
|
+
&& rm -rf /var/runtime/node_modules/@aws-sdk
|
|
12
|
+
|
|
6
13
|
WORKDIR ${LAMBDA_TASK_ROOT}
|
|
7
14
|
|
|
8
15
|
# npm blocks dependency install scripts by default; allow prisma's so its
|
|
@@ -961,7 +961,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
961
961
|
|
|
962
962
|
exports[`react-website generator > Tanstack router integration > should generate website with no router correctly > biome.json 1`] = `
|
|
963
963
|
"{
|
|
964
|
-
"$schema": "https://biomejs.dev/schemas/2.4
|
|
964
|
+
"$schema": "https://biomejs.dev/schemas/2.5.4/schema.json",
|
|
965
965
|
"root": true,
|
|
966
966
|
"formatter": {
|
|
967
967
|
"enabled": true,
|
|
@@ -986,7 +986,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
986
986
|
"linter": {
|
|
987
987
|
"enabled": true,
|
|
988
988
|
"rules": {
|
|
989
|
-
"
|
|
989
|
+
"preset": "none",
|
|
990
990
|
"correctness": {
|
|
991
991
|
"noUndeclaredDependencies": "warn"
|
|
992
992
|
}
|
|
@@ -2674,7 +2674,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
2674
2674
|
|
|
2675
2675
|
exports[`react-website generator > Tanstack router integration > should generate website with router correctly > biome.json 1`] = `
|
|
2676
2676
|
"{
|
|
2677
|
-
"$schema": "https://biomejs.dev/schemas/2.4
|
|
2677
|
+
"$schema": "https://biomejs.dev/schemas/2.5.4/schema.json",
|
|
2678
2678
|
"root": true,
|
|
2679
2679
|
"formatter": {
|
|
2680
2680
|
"enabled": true,
|
|
@@ -2699,7 +2699,7 @@ exports[`react-website generator > Tanstack router integration > should generate
|
|
|
2699
2699
|
"linter": {
|
|
2700
2700
|
"enabled": true,
|
|
2701
2701
|
"rules": {
|
|
2702
|
-
"
|
|
2702
|
+
"preset": "none",
|
|
2703
2703
|
"correctness": {
|
|
2704
2704
|
"noUndeclaredDependencies": "warn"
|
|
2705
2705
|
}
|
|
@@ -53,6 +53,7 @@ export interface AddAgentCoreGatewayInfraProps {
|
|
|
53
53
|
projectName: string;
|
|
54
54
|
projectDirectory: string;
|
|
55
55
|
cedarPolicy: boolean;
|
|
56
|
+
auth: AgentCoreAuth;
|
|
56
57
|
}
|
|
57
58
|
export declare const addAgentCoreGatewayInfra: (tree: Tree, options: AddAgentCoreGatewayInfraProps & IACProvider) => Promise<void>;
|
|
58
59
|
export {};
|
|
@@ -107,6 +107,7 @@ const addAgentCoreGatewayCDKInfra = async (tree, options)=>{
|
|
|
107
107
|
nameKebabCase: options.gatewayNameKebabCase,
|
|
108
108
|
projectDirectory: options.projectDirectory,
|
|
109
109
|
cedarPolicy: options.cedarPolicy,
|
|
110
|
+
auth: options.auth,
|
|
110
111
|
...esmVars(tree)
|
|
111
112
|
}, {
|
|
112
113
|
overwriteStrategy: OverwriteStrategy.KeepExisting
|
|
@@ -126,6 +127,7 @@ const addAgentCoreGatewayTerraformInfra = (tree, options)=>{
|
|
|
126
127
|
nameKebabCase: options.gatewayNameKebabCase,
|
|
127
128
|
projectDirectory: options.projectDirectory,
|
|
128
129
|
cedarPolicy: options.cedarPolicy,
|
|
130
|
+
auth: options.auth,
|
|
129
131
|
boto3Version: PY_VERSIONS.boto3,
|
|
130
132
|
httpxVersion: PY_VERSIONS.httpx,
|
|
131
133
|
mcpVersion: PY_VERSIONS.mcp,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/agent-core-constructs/agent-core-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Containers } from '../containers';\nimport type { Iac } from '../iac';\nimport { esmVars } from '../module-format';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { PY_VERSIONS, terraformProviderVersions } from '../versions';\n\ntype IACProvider = { iac: Iac };\n\nexport type AgentCoreAuth = 'iam' | 'cognito';\n\nexport interface AddAgentCoreInfraProps {\n nameClassName: string;\n nameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n appDirectory: string;\n serverProtocol: 'mcp' | 'http' | 'a2a';\n auth: AgentCoreAuth;\n containers: Containers;\n}\n\nconst addAgentCoreInfra = async (\n tree: Tree,\n options: AddAgentCoreInfraProps & { iac: Iac },\n) => {\n switch (options.iac) {\n case 'cdk':\n await addAgentCoreCDKInfra(tree, options);\n break;\n case 'terraform':\n addAgentCoreTerraformInfra(tree, options);\n break;\n }\n\n // Update shared constructs/terraform project configuration to depend on this project\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nconst addAgentCoreCDKInfra = async (\n tree: Tree,\n options: AddAgentCoreInfraProps,\n) => {\n // Generate app specific CDK construct\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'agent-core'),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n options.appDirectory,\n ),\n { ...options, ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Export app specific CDK construct\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n options.appDirectory,\n 'index.ts',\n ),\n `./${options.nameKebabCase}/${options.nameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n `./${options.appDirectory}/index.js`,\n );\n};\n\nconst addAgentCoreTerraformInfra = (\n tree: Tree,\n options: AddAgentCoreInfraProps,\n) => {\n // Add the AgentCore shared module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'agent-core',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'core',\n 'agent-core',\n ),\n {\n containers: options.containers,\n boto3Version: PY_VERSIONS.boto3,\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Generate app specific agent core configuration\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'agent-core',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n options.appDirectory,\n ),\n options,\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n\nexport interface AddMcpServerInfraProps {\n mcpServerNameClassName: string;\n mcpServerNameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n auth: AgentCoreAuth;\n containers: Containers;\n}\n\n/**\n * Add an MCP server CDK construct\n */\nexport const addMcpServerInfra = async (\n tree: Tree,\n options: AddMcpServerInfraProps & IACProvider,\n) => {\n await addAgentCoreInfra(tree, {\n nameClassName: options.mcpServerNameClassName,\n nameKebabCase: options.mcpServerNameKebabCase,\n dockerImageTag: options.dockerImageTag,\n dockerOutputDir: options.dockerOutputDir,\n projectName: options.projectName,\n appDirectory: 'mcp-servers',\n serverProtocol: 'mcp',\n iac: options.iac,\n auth: options.auth,\n containers: options.containers,\n });\n};\n\nexport interface AddAgentInfraProps {\n agentNameClassName: string;\n agentNameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n auth: AgentCoreAuth;\n serverProtocol?: 'http' | 'a2a';\n containers: Containers;\n}\n\n/**\n * Add an agent CDK construct\n */\nexport const addAgentInfra = async (\n tree: Tree,\n options: AddAgentInfraProps & IACProvider,\n) => {\n await addAgentCoreInfra(tree, {\n nameClassName: options.agentNameClassName,\n nameKebabCase: options.agentNameKebabCase,\n projectName: options.projectName,\n dockerImageTag: options.dockerImageTag,\n dockerOutputDir: options.dockerOutputDir,\n appDirectory: 'agents',\n serverProtocol: options.serverProtocol ?? 'http',\n iac: options.iac,\n auth: options.auth,\n containers: options.containers,\n });\n};\n\nexport interface AddAgentCoreGatewayInfraProps {\n gatewayNameClassName: string;\n gatewayNameKebabCase: string;\n projectName: string;\n projectDirectory: string;\n cedarPolicy: boolean;\n}\n\nexport const addAgentCoreGatewayInfra = async (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps & IACProvider,\n) => {\n switch (options.iac) {\n case 'cdk':\n await addAgentCoreGatewayCDKInfra(tree, options);\n break;\n case 'terraform':\n addAgentCoreGatewayTerraformInfra(tree, options);\n break;\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nconst addAgentCoreGatewayCDKInfra = async (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps,\n) => {\n // Generic gateway construct (readiness probe, policy engine, Cedar policy\n // loading) shared by all gateways\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'core',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'agentcore-gateway',\n ),\n { ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'app',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n ),\n {\n nameClassName: options.gatewayNameClassName,\n nameKebabCase: options.gatewayNameKebabCase,\n projectDirectory: options.projectDirectory,\n cedarPolicy: options.cedarPolicy,\n ...esmVars(tree),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'index.ts',\n ),\n './agentcore-gateway/agentcore-gateway.js',\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n 'index.ts',\n ),\n `./${options.gatewayNameKebabCase}/${options.gatewayNameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './gateways/index.js',\n );\n};\n\nconst addAgentCoreGatewayTerraformInfra = (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps,\n) => {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'core',\n 'agentcore-gateway',\n ),\n { ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'gateways',\n ),\n {\n nameClassName: options.gatewayNameClassName,\n nameKebabCase: options.gatewayNameKebabCase,\n projectDirectory: options.projectDirectory,\n cedarPolicy: options.cedarPolicy,\n boto3Version: PY_VERSIONS.boto3,\n httpxVersion: PY_VERSIONS.httpx,\n mcpVersion: PY_VERSIONS.mcp,\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // The Cedar render script is only needed when policies are enabled\n if (!options.cedarPolicy) {\n const renderScript = joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'gateways',\n options.gatewayNameKebabCase,\n 'render-cedar.cjs',\n );\n if (tree.exists(renderScript)) {\n tree.delete(renderScript);\n }\n }\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","esmVars","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","PY_VERSIONS","terraformProviderVersions","addAgentCoreInfra","tree","options","iac","addAgentCoreCDKInfra","addAgentCoreTerraformInfra","config","projectName","dirname","appDirectory","overwriteStrategy","KeepExisting","nameKebabCase","containers","boto3Version","boto3","addMcpServerInfra","nameClassName","mcpServerNameClassName","mcpServerNameKebabCase","dockerImageTag","dockerOutputDir","serverProtocol","auth","addAgentInfra","agentNameClassName","agentNameKebabCase","addAgentCoreGatewayInfra","addAgentCoreGatewayCDKInfra","addAgentCoreGatewayTerraformInfra","gatewayNameClassName","gatewayNameKebabCase","projectDirectory","cedarPolicy","httpxVersion","httpx","mcpVersion","mcp","renderScript","exists","delete"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;AACpB,SAASC,aAAa,QAAQ,YAAS;AAGvC,SAASC,OAAO,QAAQ,sBAAmB;AAC3C,SAASC,iCAAiC,QAAQ,WAAQ;AAC1D,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,oCAAiC;AACxC,SAASC,WAAW,EAAEC,yBAAyB,QAAQ,iBAAc;AAkBrE,MAAMC,oBAAoB,OACxBC,MACAC;IAEA,OAAQA,QAAQC,GAAG;QACjB,KAAK;YACH,MAAMC,qBAAqBH,MAAMC;YACjC;QACF,KAAK;YACHG,2BAA2BJ,MAAMC;YACjC;IACJ;IAEA,qFAAqF;IACrFX,WACEU,MACAZ,kBACEM,cACAO,QAAQC,GAAG,KAAK,QAAQP,wBAAwBC,sBAChD,iBAEF,CAACS;QACCZ,kCACEY,QACA,SACA,GAAGJ,QAAQK,WAAW,CAAC,MAAM,CAAC;QAEhC,OAAOD;IACT;AAEJ;AAEA,MAAMF,uBAAuB,OAC3BH,MACAC;IAEA,sCAAsC;IACtCd,cACEa,MACAZ,kBAAkB,YAAYmB,OAAO,EAAE,SAAS,OAAO,OAAO,eA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EF,IAAI9B,KAAKsC,MAAM,CAACD,eAAe;YAC7BrC,KAAKuC,MAAM,CAACF;QACd;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../packages/nx-plugin/src/utils/agent-core-constructs/agent-core-constructs.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\nimport {\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n type ProjectConfiguration,\n type Tree,\n updateJson,\n} from '@nx/devkit';\nimport { addStarExport } from '../ast';\nimport type { Containers } from '../containers';\nimport type { Iac } from '../iac';\nimport { esmVars } from '../module-format';\nimport { addDependencyToTargetIfNotPresent } from '../nx';\nimport {\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n SHARED_TERRAFORM_DIR,\n} from '../shared-constructs-constants';\nimport { PY_VERSIONS, terraformProviderVersions } from '../versions';\n\ntype IACProvider = { iac: Iac };\n\nexport type AgentCoreAuth = 'iam' | 'cognito';\n\nexport interface AddAgentCoreInfraProps {\n nameClassName: string;\n nameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n appDirectory: string;\n serverProtocol: 'mcp' | 'http' | 'a2a';\n auth: AgentCoreAuth;\n containers: Containers;\n}\n\nconst addAgentCoreInfra = async (\n tree: Tree,\n options: AddAgentCoreInfraProps & { iac: Iac },\n) => {\n switch (options.iac) {\n case 'cdk':\n await addAgentCoreCDKInfra(tree, options);\n break;\n case 'terraform':\n addAgentCoreTerraformInfra(tree, options);\n break;\n }\n\n // Update shared constructs/terraform project configuration to depend on this project\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nconst addAgentCoreCDKInfra = async (\n tree: Tree,\n options: AddAgentCoreInfraProps,\n) => {\n // Generate app specific CDK construct\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'cdk', 'app', 'agent-core'),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n options.appDirectory,\n ),\n { ...options, ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Export app specific CDK construct\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n options.appDirectory,\n 'index.ts',\n ),\n `./${options.nameKebabCase}/${options.nameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n `./${options.appDirectory}/index.js`,\n );\n};\n\nconst addAgentCoreTerraformInfra = (\n tree: Tree,\n options: AddAgentCoreInfraProps,\n) => {\n // Add the AgentCore shared module\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'agent-core',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'core',\n 'agent-core',\n ),\n {\n containers: options.containers,\n boto3Version: PY_VERSIONS.boto3,\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // Generate app specific agent core configuration\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'agent-core',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n options.appDirectory,\n ),\n options,\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n};\n\nexport interface AddMcpServerInfraProps {\n mcpServerNameClassName: string;\n mcpServerNameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n auth: AgentCoreAuth;\n containers: Containers;\n}\n\n/**\n * Add an MCP server CDK construct\n */\nexport const addMcpServerInfra = async (\n tree: Tree,\n options: AddMcpServerInfraProps & IACProvider,\n) => {\n await addAgentCoreInfra(tree, {\n nameClassName: options.mcpServerNameClassName,\n nameKebabCase: options.mcpServerNameKebabCase,\n dockerImageTag: options.dockerImageTag,\n dockerOutputDir: options.dockerOutputDir,\n projectName: options.projectName,\n appDirectory: 'mcp-servers',\n serverProtocol: 'mcp',\n iac: options.iac,\n auth: options.auth,\n containers: options.containers,\n });\n};\n\nexport interface AddAgentInfraProps {\n agentNameClassName: string;\n agentNameKebabCase: string;\n projectName: string;\n dockerImageTag: string;\n dockerOutputDir: string;\n auth: AgentCoreAuth;\n serverProtocol?: 'http' | 'a2a';\n containers: Containers;\n}\n\n/**\n * Add an agent CDK construct\n */\nexport const addAgentInfra = async (\n tree: Tree,\n options: AddAgentInfraProps & IACProvider,\n) => {\n await addAgentCoreInfra(tree, {\n nameClassName: options.agentNameClassName,\n nameKebabCase: options.agentNameKebabCase,\n projectName: options.projectName,\n dockerImageTag: options.dockerImageTag,\n dockerOutputDir: options.dockerOutputDir,\n appDirectory: 'agents',\n serverProtocol: options.serverProtocol ?? 'http',\n iac: options.iac,\n auth: options.auth,\n containers: options.containers,\n });\n};\n\nexport interface AddAgentCoreGatewayInfraProps {\n gatewayNameClassName: string;\n gatewayNameKebabCase: string;\n projectName: string;\n projectDirectory: string;\n cedarPolicy: boolean;\n auth: AgentCoreAuth;\n}\n\nexport const addAgentCoreGatewayInfra = async (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps & IACProvider,\n) => {\n switch (options.iac) {\n case 'cdk':\n await addAgentCoreGatewayCDKInfra(tree, options);\n break;\n case 'terraform':\n addAgentCoreGatewayTerraformInfra(tree, options);\n break;\n }\n\n updateJson(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n options.iac === 'cdk' ? SHARED_CONSTRUCTS_DIR : SHARED_TERRAFORM_DIR,\n 'project.json',\n ),\n (config: ProjectConfiguration) => {\n addDependencyToTargetIfNotPresent(\n config,\n 'build',\n `${options.projectName}:build`,\n );\n return config;\n },\n );\n};\n\nconst addAgentCoreGatewayCDKInfra = async (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps,\n) => {\n // Generic gateway construct (readiness probe, policy engine, Cedar policy\n // loading) shared by all gateways\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'core',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'agentcore-gateway',\n ),\n { ...esmVars(tree) },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'cdk',\n 'app',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n ),\n {\n nameClassName: options.gatewayNameClassName,\n nameKebabCase: options.gatewayNameKebabCase,\n projectDirectory: options.projectDirectory,\n cedarPolicy: options.cedarPolicy,\n auth: options.auth,\n ...esmVars(tree),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'core',\n 'index.ts',\n ),\n './agentcore-gateway/agentcore-gateway.js',\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'gateways',\n 'index.ts',\n ),\n `./${options.gatewayNameKebabCase}/${options.gatewayNameKebabCase}.js`,\n );\n await addStarExport(\n tree,\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_CONSTRUCTS_DIR,\n 'src',\n 'app',\n 'index.ts',\n ),\n './gateways/index.js',\n );\n};\n\nconst addAgentCoreGatewayTerraformInfra = (\n tree: Tree,\n options: AddAgentCoreGatewayInfraProps,\n) => {\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'core',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'core',\n 'agentcore-gateway',\n ),\n { ...terraformProviderVersions() },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n generateFiles(\n tree,\n joinPathFragments(\n import.meta.dirname,\n 'files',\n 'terraform',\n 'app',\n 'agentcore-gateway',\n ),\n joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'gateways',\n ),\n {\n nameClassName: options.gatewayNameClassName,\n nameKebabCase: options.gatewayNameKebabCase,\n projectDirectory: options.projectDirectory,\n cedarPolicy: options.cedarPolicy,\n auth: options.auth,\n boto3Version: PY_VERSIONS.boto3,\n httpxVersion: PY_VERSIONS.httpx,\n mcpVersion: PY_VERSIONS.mcp,\n ...terraformProviderVersions(),\n },\n {\n overwriteStrategy: OverwriteStrategy.KeepExisting,\n },\n );\n\n // The Cedar render script is only needed when policies are enabled\n if (!options.cedarPolicy) {\n const renderScript = joinPathFragments(\n PACKAGES_DIR,\n SHARED_TERRAFORM_DIR,\n 'src',\n 'app',\n 'gateways',\n options.gatewayNameKebabCase,\n 'render-cedar.cjs',\n );\n if (tree.exists(renderScript)) {\n tree.delete(renderScript);\n }\n }\n};\n"],"names":["generateFiles","joinPathFragments","OverwriteStrategy","updateJson","addStarExport","esmVars","addDependencyToTargetIfNotPresent","PACKAGES_DIR","SHARED_CONSTRUCTS_DIR","SHARED_TERRAFORM_DIR","PY_VERSIONS","terraformProviderVersions","addAgentCoreInfra","tree","options","iac","addAgentCoreCDKInfra","addAgentCoreTerraformInfra","config","projectName","dirname","appDirectory","overwriteStrategy","KeepExisting","nameKebabCase","containers","boto3Version","boto3","addMcpServerInfra","nameClassName","mcpServerNameClassName","mcpServerNameKebabCase","dockerImageTag","dockerOutputDir","serverProtocol","auth","addAgentInfra","agentNameClassName","agentNameKebabCase","addAgentCoreGatewayInfra","addAgentCoreGatewayCDKInfra","addAgentCoreGatewayTerraformInfra","gatewayNameClassName","gatewayNameKebabCase","projectDirectory","cedarPolicy","httpxVersion","httpx","mcpVersion","mcp","renderScript","exists","delete"],"mappings":"AAAA;;;CAGC,GACD,SACEA,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EAGjBC,UAAU,QACL,aAAa;AACpB,SAASC,aAAa,QAAQ,YAAS;AAGvC,SAASC,OAAO,QAAQ,sBAAmB;AAC3C,SAASC,iCAAiC,QAAQ,WAAQ;AAC1D,SACEC,YAAY,EACZC,qBAAqB,EACrBC,oBAAoB,QACf,oCAAiC;AACxC,SAASC,WAAW,EAAEC,yBAAyB,QAAQ,iBAAc;AAkBrE,MAAMC,oBAAoB,OACxBC,MACAC;IAEA,OAAQA,QAAQC,GAAG;QACjB,KAAK;YACH,MAAMC,qBAAqBH,MAAMC;YACjC;QACF,KAAK;YACHG,2BAA2BJ,MAAMC;YACjC;IACJ;IAEA,qFAAqF;IACrFX,WACEU,MACAZ,kBACEM,cACAO,QAAQC,GAAG,KAAK,QAAQP,wBAAwBC,sBAChD,iBAEF,CAACS;QACCZ,kCACEY,QACA,SACA,GAAGJ,QAAQK,WAAW,CAAC,MAAM,CAAC;QAEhC,OAAOD;IACT;AAEJ;AAEA,MAAMF,uBAAuB,OAC3BH,MACAC;IAEA,sCAAsC;IACtCd,cACEa,MACAZ,kBAAkB,YAAYmB,OAAO,EAAE,SAAS,OAAO,OAAO,eAC9DnB,kBACEM,cACAC,uBACA,OACA,OACAM,QAAQO,YAAY,GAEtB;QAAE,GAAGP,OAAO;QAAE,GAAGT,QAAQQ,KAAK;IAAC,GAC/B;QACES,mBAAmBpB,kBAAkBqB,YAA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
@@ -3,6 +3,10 @@ import { Construct } from 'constructs';
|
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
import * as url from 'node:url';
|
|
5
5
|
<%_ } _%>
|
|
6
|
+
<%_ if (auth === 'cognito') { _%>
|
|
7
|
+
import { GatewayAuthorizer } from 'aws-cdk-lib/aws-bedrockagentcore';
|
|
8
|
+
import { IUserPool, IUserPoolClient } from 'aws-cdk-lib/aws-cognito';
|
|
9
|
+
<%_ } _%>
|
|
6
10
|
import {
|
|
7
11
|
AgentCoreGateway,
|
|
8
12
|
AgentCoreGatewayProps,
|
|
@@ -12,14 +16,28 @@ import { RuntimeConfig } from '../../../core/runtime-config<% if (esm) { %>.js<%
|
|
|
12
16
|
import { findWorkspaceRoot } from '../../../core/workspace<% if (esm) { %>.js<% } %>';
|
|
13
17
|
<%_ } _%>
|
|
14
18
|
|
|
15
|
-
<%_ if (
|
|
19
|
+
<%_ if (auth === 'cognito') { _%>
|
|
20
|
+
export type <%- nameClassName %>Props = Omit<
|
|
21
|
+
AgentCoreGatewayProps,
|
|
22
|
+
<%_ if (cedarPolicy) { _%>'cedarPolicyPath' | <%_ } _%>'authorizer'
|
|
23
|
+
> & {
|
|
24
|
+
/**
|
|
25
|
+
* Identity details for Cognito authentication. Callers authenticate with a
|
|
26
|
+
* JWT bearer token issued by this user pool.
|
|
27
|
+
*/
|
|
28
|
+
identity: {
|
|
29
|
+
userPool: IUserPool;
|
|
30
|
+
userPoolClient: IUserPoolClient;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
<%_ } else if (cedarPolicy) { _%>
|
|
16
34
|
export type <%- nameClassName %>Props = Omit<AgentCoreGatewayProps, 'cedarPolicyPath'>;
|
|
17
35
|
<%_ } else { _%>
|
|
18
36
|
export type <%- nameClassName %>Props = AgentCoreGatewayProps;
|
|
19
37
|
<%_ } _%>
|
|
20
38
|
|
|
21
39
|
/**
|
|
22
|
-
* AgentCore Gateway wired for MCP protocol with IAM inbound auth.
|
|
40
|
+
* AgentCore Gateway wired for MCP protocol with <%- auth === 'cognito' ? 'Cognito (JWT)' : 'IAM' %> inbound auth.
|
|
23
41
|
<%_ if (cedarPolicy) { _%>
|
|
24
42
|
*
|
|
25
43
|
* Cedar policies are loaded from the gateway project's policies/ directory
|
|
@@ -30,7 +48,23 @@ export class <%- nameClassName %> extends AgentCoreGateway {
|
|
|
30
48
|
/** Default Gateway target name when added to another Gateway. */
|
|
31
49
|
public readonly gatewayName = '<%- nameKebabCase %>';
|
|
32
50
|
|
|
33
|
-
constructor(scope: Construct, id: string, props
|
|
51
|
+
constructor(scope: Construct, id: string, props<%_ if (auth !== 'cognito') { _%>?<%_ } _%>: <%- nameClassName %>Props) {
|
|
52
|
+
<%_ if (auth === 'cognito') { _%>
|
|
53
|
+
const { identity, ...restProps } = props;
|
|
54
|
+
super(scope, id, {
|
|
55
|
+
<%_ if (cedarPolicy) { _%>
|
|
56
|
+
cedarPolicyPath: path.join(
|
|
57
|
+
findWorkspaceRoot(url.fileURLToPath(new URL(<% if (esm) { %>import.meta.url<% } else { %>require('url').pathToFileURL(__filename).href<% } %>))),
|
|
58
|
+
'<%- projectDirectory %>/policies',
|
|
59
|
+
),
|
|
60
|
+
<%_ } _%>
|
|
61
|
+
authorizer: GatewayAuthorizer.usingCognito({
|
|
62
|
+
userPool: identity.userPool,
|
|
63
|
+
allowedClients: [identity.userPoolClient],
|
|
64
|
+
}),
|
|
65
|
+
...restProps,
|
|
66
|
+
});
|
|
67
|
+
<%_ } else { _%>
|
|
34
68
|
super(scope, id, {
|
|
35
69
|
<%_ if (cedarPolicy) { _%>
|
|
36
70
|
cedarPolicyPath: path.join(
|
|
@@ -40,6 +74,7 @@ export class <%- nameClassName %> extends AgentCoreGateway {
|
|
|
40
74
|
<%_ } _%>
|
|
41
75
|
...props,
|
|
42
76
|
});
|
|
77
|
+
<%_ } _%>
|
|
43
78
|
|
|
44
79
|
const rc = RuntimeConfig.ensure(this);
|
|
45
80
|
rc.set('agentcore', 'gateways', {
|