@aws/nx-plugin 1.0.0-rc.90 → 1.0.0-rc.92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/LICENSE-THIRD-PARTY +2 -2
  2. package/migrations.json +32 -27
  3. package/package.json +4 -4
  4. package/src/infra/app/__snapshots__/generator.spec.ts.snap +3 -3
  5. package/src/internal/test-matrix/generator.js +28 -0
  6. package/src/internal/test-matrix/generator.js.map +1 -1
  7. package/src/migrations/latest/react-website-unique-dev-ports/metadata.json +3 -0
  8. package/src/migrations/latest/react-website-unique-dev-ports/migration.js +79 -0
  9. package/src/migrations/latest/react-website-unique-dev-ports/migration.js.map +1 -0
  10. package/src/migrations/v1.0.0-rc.87/0001-add-destroy-sandbox-target/migration.js.map +1 -0
  11. package/src/migrations/v1.0.0-rc.87/0002-terraform-rdb-proxy-iam-connect-grant/migration.js.map +1 -0
  12. package/src/migrations/v1.0.0-rc.88/0001-python-version-drop-exact-patch/migration.d.ts +6 -0
  13. package/src/migrations/v1.0.0-rc.88/0001-python-version-drop-exact-patch/migration.js.map +1 -0
  14. package/src/migrations/v1.0.0-rc.88/0002-react-website-nx-react-express-override/migration.js.map +1 -0
  15. package/src/migrations/v1.0.0-rc.89/0001-nx-parallel-default/migration.js.map +1 -0
  16. package/src/preset/__snapshots__/generator.spec.ts.snap +2 -2
  17. package/src/py/agent/__snapshots__/generator.constructs.spec.ts.snap +2 -2
  18. package/src/py/agent/__snapshots__/generator.frameworks.spec.ts.snap +1 -1
  19. package/src/py/agent/__snapshots__/generator.protocols.spec.ts.snap +91 -116
  20. package/src/py/agent/files/package/main.py.template +13 -0
  21. package/src/py/agent/generator.d.ts +6 -1
  22. package/src/py/agent/generator.js +82 -45
  23. package/src/py/agent/generator.js.map +1 -1
  24. package/src/py/agent/schema.d.js.map +1 -1
  25. package/src/py/agent/schema.d.ts +2 -1
  26. package/src/py/agent/schema.json +2 -2
  27. package/src/py/mcp-server/__snapshots__/generator.spec.ts.snap +66 -115
  28. package/src/py/mcp-server/files/package/main.py.template +13 -0
  29. package/src/py/mcp-server/generator.d.ts +6 -1
  30. package/src/py/mcp-server/generator.js +79 -43
  31. package/src/py/mcp-server/generator.js.map +1 -1
  32. package/src/py/mcp-server/schema.d.js.map +1 -1
  33. package/src/py/mcp-server/schema.d.ts +2 -1
  34. package/src/py/mcp-server/schema.json +2 -2
  35. package/src/py/rdb/__snapshots__/generator.spec.ts.snap +14 -61
  36. package/src/ts/agent/__snapshots__/generator.spec.ts.snap +78 -115
  37. package/src/ts/agent/generator.d.ts +26 -1
  38. package/src/ts/agent/generator.js +71 -45
  39. package/src/ts/agent/generator.js.map +1 -1
  40. package/src/ts/agent/schema.d.js.map +1 -1
  41. package/src/ts/agent/schema.d.ts +2 -1
  42. package/src/ts/agent/schema.json +2 -2
  43. package/src/ts/mcp-server/__snapshots__/generator.spec.ts.snap +65 -114
  44. package/src/ts/mcp-server/generator.d.ts +26 -1
  45. package/src/ts/mcp-server/generator.js +66 -38
  46. package/src/ts/mcp-server/generator.js.map +1 -1
  47. package/src/ts/mcp-server/schema.d.js.map +1 -1
  48. package/src/ts/mcp-server/schema.d.ts +2 -1
  49. package/src/ts/mcp-server/schema.json +2 -2
  50. package/src/ts/rdb/__snapshots__/generator.spec.ts.snap +16 -110
  51. package/src/ts/react-website/app/__snapshots__/generator.spec.ts.snap +12 -10
  52. package/src/ts/react-website/app/generator.js +16 -0
  53. package/src/ts/react-website/app/generator.js.map +1 -1
  54. package/src/ts/react-website/cognito-auth/__snapshots__/generator.terraform.spec.ts.snap +1 -1
  55. package/src/ts/react-website/cognito-auth/generator.js +14 -2
  56. package/src/ts/react-website/cognito-auth/generator.js.map +1 -1
  57. package/src/utils/agent-core-constructs/agent-core-constructs.d.ts +25 -6
  58. package/src/utils/agent-core-constructs/agent-core-constructs.js +36 -7
  59. package/src/utils/agent-core-constructs/agent-core-constructs.js.map +1 -1
  60. package/src/utils/agent-core-constructs/files/cdk/app/agent-core/__nameKebabCase__/__nameKebabCase__.ts.template +20 -4
  61. package/src/utils/agent-core-constructs/files/terraform/app/agent-core/__nameKebabCase__/__nameKebabCase__.tf.template +34 -1
  62. package/src/utils/agent-core-constructs/files/terraform/core/agent-core/runtime.tf.template +51 -112
  63. package/src/utils/agent-core-constructs/files/terraform/core/agent-core-code/runtime.tf.template +204 -0
  64. package/src/utils/agent-core-constructs/files/terraform/core/agent-core-container/runtime.tf.template +235 -0
  65. package/src/utils/agent-core-packaging.d.ts +119 -0
  66. package/src/utils/agent-core-packaging.js +131 -0
  67. package/src/utils/agent-core-packaging.js.map +1 -0
  68. package/src/utils/agent-core-runtime-resolution.d.ts +35 -0
  69. package/src/utils/agent-core-runtime-resolution.js +68 -0
  70. package/src/utils/agent-core-runtime-resolution.js.map +1 -0
  71. package/src/utils/files/terraform/src/core/asset-ecr/asset-ecr.tf.template +137 -0
  72. package/src/utils/identity-constructs/files/cdk/core/user-identity.ts.template +1 -1
  73. package/src/utils/identity-constructs/files/terraform/core/user-identity/identity/identity.tf.template +1 -4
  74. package/src/utils/identity-constructs/identity-constructs.d.ts +22 -2
  75. package/src/utils/identity-constructs/identity-constructs.js +75 -5
  76. package/src/utils/identity-constructs/identity-constructs.js.map +1 -1
  77. package/src/utils/port.d.ts +5 -0
  78. package/src/utils/port.js +1 -1
  79. package/src/utils/port.js.map +1 -1
  80. package/src/utils/rdb-constructs/files/terraform/app/dbs/__nameKebabCase__/__nameKebabCase__.tf.template +12 -59
  81. package/src/utils/versions.d.ts +51 -31
  82. package/src/utils/versions.js +48 -31
  83. package/src/utils/versions.js.map +1 -1
  84. package/src/migrations/latest/add-destroy-sandbox-target/migration.js.map +0 -1
  85. package/src/migrations/latest/nx-parallel-default/migration.js.map +0 -1
  86. package/src/migrations/latest/python-version-drop-exact-patch/migration.js.map +0 -1
  87. package/src/migrations/latest/react-website-nx-react-express-override/migration.js.map +0 -1
  88. package/src/migrations/latest/terraform-rdb-proxy-iam-connect-grant/migration.js.map +0 -1
  89. /package/src/migrations/latest/{add-destroy-sandbox-target → react-website-unique-dev-ports}/migration.d.ts +0 -0
  90. /package/src/migrations/{latest/add-destroy-sandbox-target → v1.0.0-rc.87/0001-add-destroy-sandbox-target}/metadata.json +0 -0
  91. /package/src/migrations/{latest/python-version-drop-exact-patch → v1.0.0-rc.87/0001-add-destroy-sandbox-target}/migration.d.ts +0 -0
  92. /package/src/migrations/{latest/add-destroy-sandbox-target → v1.0.0-rc.87/0001-add-destroy-sandbox-target}/migration.js +0 -0
  93. /package/src/migrations/{latest/terraform-rdb-proxy-iam-connect-grant → v1.0.0-rc.87/0002-terraform-rdb-proxy-iam-connect-grant}/__snapshots__/migration.spec.ts.snap +0 -0
  94. /package/src/migrations/{latest/terraform-rdb-proxy-iam-connect-grant → v1.0.0-rc.87/0002-terraform-rdb-proxy-iam-connect-grant}/metadata.json +0 -0
  95. /package/src/migrations/{latest/terraform-rdb-proxy-iam-connect-grant → v1.0.0-rc.87/0002-terraform-rdb-proxy-iam-connect-grant}/migration.d.ts +0 -0
  96. /package/src/migrations/{latest/terraform-rdb-proxy-iam-connect-grant → v1.0.0-rc.87/0002-terraform-rdb-proxy-iam-connect-grant}/migration.js +0 -0
  97. /package/src/migrations/{latest/python-version-drop-exact-patch → v1.0.0-rc.88/0001-python-version-drop-exact-patch}/metadata.json +0 -0
  98. /package/src/migrations/{latest/python-version-drop-exact-patch → v1.0.0-rc.88/0001-python-version-drop-exact-patch}/migration.js +0 -0
  99. /package/src/migrations/{latest/react-website-nx-react-express-override → v1.0.0-rc.88/0002-react-website-nx-react-express-override}/metadata.json +0 -0
  100. /package/src/migrations/{latest/react-website-nx-react-express-override → v1.0.0-rc.88/0002-react-website-nx-react-express-override}/migration.d.ts +0 -0
  101. /package/src/migrations/{latest/react-website-nx-react-express-override → v1.0.0-rc.88/0002-react-website-nx-react-express-override}/migration.js +0 -0
  102. /package/src/migrations/{latest/nx-parallel-default → v1.0.0-rc.89/0001-nx-parallel-default}/metadata.json +0 -0
  103. /package/src/migrations/{latest/nx-parallel-default → v1.0.0-rc.89/0001-nx-parallel-default}/migration.d.ts +0 -0
  104. /package/src/migrations/{latest/nx-parallel-default → v1.0.0-rc.89/0001-nx-parallel-default}/migration.js +0 -0
  105. /package/src/ts/mcp-server/files/{http.ts.template → app/http.ts.template} +0 -0
  106. /package/src/ts/mcp-server/files/{index.ts.template → app/index.ts.template} +0 -0
  107. /package/src/ts/mcp-server/files/{resources → app/resources}/sample-guidance.ts.template +0 -0
  108. /package/src/ts/mcp-server/files/{server.ts.template → app/server.ts.template} +0 -0
  109. /package/src/ts/mcp-server/files/{stdio.ts.template → app/stdio.ts.template} +0 -0
  110. /package/src/ts/mcp-server/files/{tools → app/tools}/divide.ts.template +0 -0
  111. /package/src/ts/mcp-server/files/{Dockerfile.template → deploy/Dockerfile.template} +0 -0
@@ -55,9 +55,9 @@
55
55
  },
56
56
  "infra": {
57
57
  "type": "string",
58
- "description": "The type of infrastructure to host your Agent.",
58
+ "description": "The type of infrastructure to host your Agent. agentcore deploys your code as a zip to an AgentCore managed runtime for the fastest build and deploy cycle. agentcore-ecr builds and hosts a container image instead, for OS-level control or an established container pipeline.",
59
59
  "x-prompt": "How would you like to host your Agent server?",
60
- "enum": ["agentcore", "none"],
60
+ "enum": ["agentcore", "agentcore-ecr", "none"],
61
61
  "default": "agentcore",
62
62
  "x-priority": "important"
63
63
  },
@@ -157,10 +157,6 @@ exports[`ts#mcp-server generator > should match snapshot for Terraform generated
157
157
  source = "hashicorp/aws"
158
158
  version = "6.62.0"
159
159
  }
160
- external = {
161
- source = "hashicorp/external"
162
- version = "2.4.1"
163
- }
164
160
  null = {
165
161
  source = "hashicorp/null"
166
162
  version = "3.3.1"
@@ -204,9 +200,36 @@ variable "authorizer_configuration" {
204
200
  default = null
205
201
  }
206
202
 
207
- variable "docker_image_tag" {
208
- description = "Name of the docker image tag to use as the agent core runtime"
209
- type = string
203
+ variable "container_configuration" {
204
+ description = "Container artifact for this runtime. Set exactly one of this or \`code_configuration\`; the \`agent-core-container\` module renders it."
205
+ type = object({
206
+ container_uri = string
207
+ })
208
+ default = null
209
+ }
210
+
211
+ variable "code_configuration" {
212
+ description = "Code artifact for this runtime. Set exactly one of this or \`container_configuration\`; the \`agent-core-code\` module renders it."
213
+ type = object({
214
+ entry_point = list(string)
215
+ runtime = string
216
+ s3_bucket = string
217
+ s3_key = string
218
+ })
219
+ default = null
220
+
221
+ validation {
222
+ # Evaluated at plan time, since Terraform defers validation that reads
223
+ # another variable.
224
+ condition = (var.code_configuration == null) != (var.container_configuration == null)
225
+ error_message = "Set exactly one of code_configuration or container_configuration."
226
+ }
227
+ }
228
+
229
+ variable "artifact_dependencies" {
230
+ description = "Resources the artifact is produced by (an image push or a code upload), so the runtime is created only once they exist."
231
+ type = list(any)
232
+ default = []
210
233
  }
211
234
 
212
235
  variable "env" {
@@ -269,47 +292,6 @@ resource "random_id" "unique_suffix" {
269
292
  byte_length = 4
270
293
  }
271
294
 
272
- # ECR Repository
273
- resource "aws_ecr_repository" "agent_core_repository" {
274
- #checkov:skip=CKV_AWS_136:AES256 encryption is sufficient for ECR repositories
275
- name = "\${lower(var.agent_runtime_name)}_repository_\${random_id.unique_suffix.hex}"
276
-
277
- image_tag_mutability = "IMMUTABLE"
278
- force_delete = true
279
-
280
- image_scanning_configuration {
281
- scan_on_push = true
282
- }
283
-
284
- tags = var.tags
285
- }
286
-
287
- # ECR Repository Policy
288
- resource "aws_ecr_repository_policy" "agent_core_ecr_policy" {
289
- repository = aws_ecr_repository.agent_core_repository.name
290
-
291
- policy = jsonencode({
292
- Version = "2012-10-17"
293
- Statement = [
294
- {
295
- Sid = "AllowPushPull"
296
- Effect = "Allow"
297
- Principal = {
298
- AWS = "arn:aws:iam::\${local.aws_account_id}:root"
299
- }
300
- Action = [
301
- "ecr:GetDownloadUrlForLayer",
302
- "ecr:BatchGetImage",
303
- "ecr:BatchCheckLayerAvailability",
304
- "ecr:PutImage",
305
- "ecr:InitiateLayerUpload",
306
- "ecr:UploadLayerPart",
307
- "ecr:CompleteLayerUpload"
308
- ]
309
- }
310
- ]
311
- })
312
- }
313
295
 
314
296
  # IAM Role for Agent Core Runtime
315
297
  resource "aws_iam_role" "agent_core_runtime_role" {
@@ -348,27 +330,6 @@ resource "aws_iam_policy" "agent_core_runtime_policy" {
348
330
  policy = jsonencode({
349
331
  Version = "2012-10-17"
350
332
  Statement = concat([
351
- {
352
- Sid = "ECRImageAccess"
353
- Effect = "Allow"
354
- Action = [
355
- "ecr:BatchGetImage",
356
- "ecr:GetDownloadUrlForLayer"
357
- ]
358
- Resource = [
359
- aws_ecr_repository.agent_core_repository.arn
360
- ]
361
- },
362
- {
363
- Sid = "ECRTokenAccess"
364
- Effect = "Allow"
365
- Action = [
366
- "ecr:GetAuthorizationToken"
367
- ]
368
- Resource = [
369
- "*"
370
- ]
371
- },
372
333
  {
373
334
  "Effect" : "Allow",
374
335
  "Action" : [
@@ -443,46 +404,6 @@ resource "aws_iam_role_policy_attachment" "agent_core_policy" {
443
404
  policy_arn = aws_iam_policy.agent_core_runtime_policy.arn
444
405
  }
445
406
 
446
- # Data source to get container image digest
447
- data "external" "docker_digest" {
448
- program = ["sh", "-c", "echo '{\\"digest\\":\\"'$(docker inspect \${var.docker_image_tag} --format '{{.Id}}')'\\"}' "]
449
- }
450
-
451
- locals {
452
- # Content-based, immutable image tag derived from the local image digest
453
- image_tag = replace(data.external.docker_digest.result.digest, "sha256:", "")
454
- }
455
-
456
- # Null resource for container image publish
457
- resource "null_resource" "docker_publish" {
458
- triggers = {
459
- docker_digest = data.external.docker_digest.result.digest
460
- repository_url = aws_ecr_repository.agent_core_repository.repository_url
461
- docker_image_tag = var.docker_image_tag
462
- image_tag = local.image_tag
463
- }
464
-
465
- provisioner "local-exec" {
466
- command = <<-EOT
467
- # Get ECR login token
468
- aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$REPOSITORY_URL"
469
-
470
- # Tag the image with the immutable content-based tag
471
- docker tag "$DOCKER_IMAGE_TAG" "$REPOSITORY_URL:$IMAGE_TAG"
472
-
473
- # Push the image
474
- docker push "$REPOSITORY_URL:$IMAGE_TAG"
475
- EOT
476
- environment = {
477
- AWS_REGION = local.aws_region
478
- REPOSITORY_URL = self.triggers.repository_url
479
- DOCKER_IMAGE_TAG = self.triggers.docker_image_tag
480
- IMAGE_TAG = self.triggers.image_tag
481
- }
482
- }
483
-
484
- depends_on = [aws_ecr_repository_policy.agent_core_ecr_policy]
485
- }
486
407
 
487
408
  # Security group for the agent core runtime, used when running inside a VPC
488
409
  resource "aws_security_group" "agent_core_runtime" {
@@ -513,8 +434,26 @@ resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
513
434
  role_arn = aws_iam_role.agent_core_runtime_role.arn
514
435
 
515
436
  agent_runtime_artifact {
516
- container_configuration {
517
- container_uri = "\${aws_ecr_repository.agent_core_repository.repository_url}:\${local.image_tag}"
437
+ dynamic "container_configuration" {
438
+ for_each = var.container_configuration != null ? [var.container_configuration] : []
439
+ content {
440
+ container_uri = container_configuration.value.container_uri
441
+ }
442
+ }
443
+
444
+ dynamic "code_configuration" {
445
+ for_each = var.code_configuration != null ? [var.code_configuration] : []
446
+ content {
447
+ entry_point = code_configuration.value.entry_point
448
+ runtime = code_configuration.value.runtime
449
+
450
+ code {
451
+ s3 {
452
+ bucket = code_configuration.value.s3_bucket
453
+ prefix = code_configuration.value.s3_key
454
+ }
455
+ }
456
+ }
518
457
  }
519
458
  }
520
459
 
@@ -558,7 +497,7 @@ resource "aws_bedrockagentcore_agent_runtime" "agent_runtime" {
558
497
  tags = var.tags
559
498
 
560
499
  depends_on = [
561
- null_resource.docker_publish,
500
+ var.artifact_dependencies,
562
501
  aws_iam_role_policy_attachment.agent_core_policy
563
502
  ]
564
503
  }
@@ -575,7 +514,7 @@ resource "null_resource" "runtime_ready" {
575
514
 
576
515
  provisioner "local-exec" {
577
516
  command = <<-EOT
578
- uv run --with boto3==1.43.82 python -c "
517
+ uv run --with boto3==1.43.83 python -c "
579
518
  import boto3
580
519
  import json
581
520
  import os
@@ -716,15 +655,27 @@ variable "appconfig_application_id" {
716
655
  type = string
717
656
  }
718
657
 
658
+ variable "asset_ecr_repository_url" {
659
+ description = "URL of the shared asset ECR repository the agent's image is published to. Instantiate the \`core/asset-ecr\` module once per deployment and pass its \`repository_url\` output here."
660
+ type = string
661
+ }
662
+
663
+ variable "asset_ecr_repository_arn" {
664
+ description = "ARN of the shared asset ECR repository (from \`core/asset-ecr.repository_arn\`), used to scope the runtime's image pull grant to it."
665
+ type = string
666
+ }
667
+
719
668
  variable "appconfig_application_arn" {
720
669
  description = "ARN of the shared runtime-config AppConfig application (from \`core/runtime-config/appconfig.application_arn\`). Used to scope the IAM read permission granted to the agent runtime."
721
670
  type = string
722
671
  }
723
672
 
724
673
  module "agent_core_runtime" {
725
- source = "../../../core/agent-core"
674
+ source = "../../../core/agent-core-container"
726
675
  agent_runtime_name = "TerraformSnapshotServer"
727
676
  docker_image_tag = "proj-terraform-snapshot-server:latest"
677
+ asset_ecr_repository_url = var.asset_ecr_repository_url
678
+ asset_ecr_repository_arn = var.asset_ecr_repository_arn
728
679
  server_protocol = "MCP"
729
680
  enable_vpc = var.enable_vpc
730
681
  vpc_id = var.vpc_id
@@ -5,12 +5,17 @@
5
5
  import { type GeneratorCallback, type Tree } from '@nx/devkit';
6
6
  import { type NxGeneratorInfo } from '../../utils/nx.js';
7
7
  import type { IacMetadata } from '../../utils/shared-constructs-constants.js';
8
- import type { TsMcpServerGeneratorSchema } from './schema';
8
+ import type { TsMcpServerGeneratorSchema, TsMcpServerInfra } from './schema';
9
9
  /** The metadata this generator records, which its predicates read. */
10
10
  export interface TsMcpServerMetadata extends IacMetadata {
11
11
  readonly port: number;
12
12
  readonly rc: string;
13
13
  readonly auth: string;
14
+ /**
15
+ * How this component is packaged and hosted, so a consumer can tell a
16
+ * code-packaged runtime from a container-packaged one without re-deriving it.
17
+ */
18
+ readonly infra: TsMcpServerInfra;
14
19
  }
15
20
  export declare const DEPENDENCIES: import("../../utils/declared-dependencies.js").DependencyDeclaration<readonly [{
16
21
  readonly name: "@modelcontextprotocol/sdk";
@@ -99,6 +104,26 @@ export declare const DEPENDENCIES: import("../../utils/declared-dependencies.js"
99
104
  readonly name: "@opentelemetry/propagator-jaeger";
100
105
  } & {
101
106
  versionOnly: true;
107
+ }, {
108
+ readonly name: "ncp";
109
+ } & {
110
+ versionOnly: true;
111
+ }, {
112
+ readonly name: "rimraf";
113
+ } & {
114
+ versionOnly: true;
115
+ }, {
116
+ readonly name: "make-dir-cli";
117
+ } & {
118
+ versionOnly: true;
119
+ }, {
120
+ readonly name: "cpy-cli";
121
+ } & {
122
+ versionOnly: true;
123
+ }, {
124
+ readonly name: "@aws/aws-distro-opentelemetry-node-autoinstrumentation";
125
+ } & {
126
+ versionOnly: true;
102
127
  }], readonly [{
103
128
  readonly name: "boto3";
104
129
  readonly when: (m: IacMetadata) => boolean;
@@ -4,6 +4,7 @@
4
4
  */ import { detectPackageManager, generateFiles, joinPathFragments, OverwriteStrategy, readJson, updateJson, updateProjectConfiguration } from "@nx/devkit";
5
5
  import { addTsDependencies } from "../../utils/add-dependencies.js";
6
6
  import { AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES, addMcpServerInfra } from "../../utils/agent-core-constructs/agent-core-constructs.js";
7
+ import { addTypeScriptCodePackageTarget, agentCoreNodeRuntime, CODE_PACKAGE_DEPENDENCIES, isAgentCoreHosted, isContainerHosted } from "../../utils/agent-core-packaging.js";
7
8
  import { addTypeScriptBundleTarget, BUNDLE_DEPENDENCIES } from "../../utils/bundle/bundle.js";
8
9
  import { resolveContainers } from "../../utils/containers.js";
9
10
  import { declareDependencies, ownedElsewhere } from "../../utils/declared-dependencies.js";
@@ -59,7 +60,8 @@ export const DEPENDENCIES = declareDependencies()({
59
60
  ...ownedElsewhere(DOCKER_DEPENDENCIES),
60
61
  ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),
61
62
  ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),
62
- ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES)
63
+ ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),
64
+ ...ownedElsewhere(CODE_PACKAGE_DEPENDENCIES)
63
65
  ],
64
66
  py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES)
65
67
  });
@@ -90,8 +92,7 @@ export const tsMcpServerGenerator = async (tree, options)=>{
90
92
  // Generate esm if the project's package.json is `type: module`, falling
91
93
  // back to the workspace format when the project has no manifest.
92
94
  const esm = tree.exists(projectPackageJsonPath) ? readJson(tree, projectPackageJsonPath).type === 'module' : isEsmWorkspace(tree);
93
- // Generate example server
94
- generateFiles(tree, joinPathFragments(import.meta.dirname, 'files'), targetSourceDir, {
95
+ const templateContext = {
95
96
  name,
96
97
  esm,
97
98
  distDir,
@@ -99,11 +100,14 @@ export const tsMcpServerGenerator = async (tree, options)=>{
99
100
  jaegerVersion: TS_VERSIONS['@opentelemetry/propagator-jaeger'],
100
101
  nodeBaseImage: BASE_IMAGES.node,
101
102
  ...nodeImageVersions()
102
- }, {
103
+ };
104
+ // Generate example server
105
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'app'), targetSourceDir, templateContext, {
103
106
  overwriteStrategy: OverwriteStrategy.KeepExisting
104
107
  });
105
108
  // Add hosting based on infra
106
- if (infra === 'agentcore') {
109
+ if (isAgentCoreHosted(infra)) {
110
+ const container = isContainerHosted(infra);
107
111
  const containers = await resolveContainers(tree, 'inherit');
108
112
  const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;
109
113
  // Add bundle target
@@ -111,34 +115,61 @@ export const tsMcpServerGenerator = async (tree, options)=>{
111
115
  targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,
112
116
  bundleOutputDir: joinPathFragments('mcp', name)
113
117
  }, DEPENDENCIES);
114
- const dockerOutputDir = joinPathFragments('dist', project.root, 'bundle', 'mcp', name);
115
- const dockerTargetName = `${mcpTargetPrefix}-docker`;
116
- const fs = new FsCommands(tree, DEPENDENCIES);
117
- project.targets[dockerTargetName] = {
118
- cache: IMAGE_BUILD_CACHE,
119
- executor: 'nx:run-commands',
120
- options: {
121
- commands: [
122
- fs.cp(`${targetSourceDir}/Dockerfile`, `${dockerOutputDir}/Dockerfile`),
123
- `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${dockerOutputDir}`
124
- ],
125
- parallel: false
126
- },
127
- dependsOn: [
128
- 'bundle'
129
- ]
130
- };
131
- addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);
132
- addArtifactDependencyToTargets(project, 'docker');
133
- addDockerScanTarget(tree, {
134
- project,
135
- containerEngine: containers,
136
- trivyTargetName: `${mcpTargetPrefix}-trivy`,
137
- dockerTargetName,
138
- imageTags: [
139
- dockerImageTag
140
- ]
141
- }, DEPENDENCIES);
118
+ const bundleOutputDir = joinPathFragments('dist', project.root, 'bundle', 'mcp', name);
119
+ let artifact;
120
+ if (container) {
121
+ // Add the Dockerfile
122
+ generateFiles(tree, joinPathFragments(import.meta.dirname, 'files', 'deploy'), targetSourceDir, templateContext, {
123
+ overwriteStrategy: OverwriteStrategy.KeepExisting
124
+ });
125
+ const dockerTargetName = `${mcpTargetPrefix}-docker`;
126
+ const fs = new FsCommands(tree, DEPENDENCIES);
127
+ project.targets[dockerTargetName] = {
128
+ cache: IMAGE_BUILD_CACHE,
129
+ executor: 'nx:run-commands',
130
+ options: {
131
+ commands: [
132
+ fs.cp(`${targetSourceDir}/Dockerfile`, `${bundleOutputDir}/Dockerfile`),
133
+ `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${bundleOutputDir}`
134
+ ],
135
+ parallel: false
136
+ },
137
+ dependsOn: [
138
+ 'bundle'
139
+ ]
140
+ };
141
+ addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);
142
+ addArtifactDependencyToTargets(project, 'docker');
143
+ addDockerScanTarget(tree, {
144
+ project,
145
+ containerEngine: containers,
146
+ trivyTargetName: `${mcpTargetPrefix}-trivy`,
147
+ dockerTargetName,
148
+ imageTags: [
149
+ dockerImageTag
150
+ ]
151
+ }, DEPENDENCIES);
152
+ artifact = {
153
+ type: 'container',
154
+ dockerImageTag,
155
+ outputDir: bundleOutputDir
156
+ };
157
+ } else {
158
+ const packageOutputDir = joinPathFragments('dist', project.root, 'package', 'mcp', name);
159
+ addTypeScriptCodePackageTarget(tree, {
160
+ project,
161
+ targetName: `${mcpTargetPrefix}-package`,
162
+ bundleTargetName: 'bundle',
163
+ bundleOutputDir,
164
+ packageOutputDir
165
+ }, DEPENDENCIES);
166
+ artifact = {
167
+ type: 'code',
168
+ outputDir: packageOutputDir,
169
+ runtime: agentCoreNodeRuntime(),
170
+ entryPoint: 'index.js'
171
+ };
172
+ }
142
173
  // Add shared constructs
143
174
  await sharedConstructsGenerator(tree, {
144
175
  iac
@@ -148,15 +179,11 @@ export const tsMcpServerGenerator = async (tree, options)=>{
148
179
  mcpServerNameKebabCase: name,
149
180
  mcpServerNameClassName,
150
181
  projectName: project.name,
151
- dockerImageTag,
152
- dockerOutputDir,
182
+ artifact,
153
183
  iac,
154
184
  auth,
155
185
  containers
156
186
  });
157
- } else {
158
- // No Dockerfile needed for non-hosted MCP
159
- tree.delete(joinPathFragments(targetSourceDir, 'Dockerfile'));
160
187
  }
161
188
  // @modelcontextprotocol/sdk declares zod as a peer dependency with a wide range
162
189
  // (^3.25 || ^4.0). Yarn does not dedupe the peer to the workspace's pinned zod, so
@@ -186,6 +213,7 @@ export const tsMcpServerGenerator = async (tree, options)=>{
186
213
  // Recorded below and read by the declaration's predicates, so the packages
187
214
  // added here are exactly the ones the version sync will own.
188
215
  const metadata = {
216
+ infra,
189
217
  port: localDevPort,
190
218
  rc: mcpServerNameClassName,
191
219
  auth,
@@ -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 detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n addMcpServerInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n IMAGE_BUILD_CACHE,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions.js';\nimport type { TsMcpServerGeneratorSchema } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsMcpServerMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n}\n\nexport const DEPENDENCIES = declareDependencies<TsMcpServerMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk' },\n { name: 'zod' },\n { name: 'express' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/express', dev: true },\n // tsx (local dev) and the MCP inspector are shared tooling.\n { name: 'tsx', dev: true, root: true },\n { name: '@modelcontextprotocol/inspector', dev: true, root: true },\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\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 // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\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 project's package.json is `type: module`, falling\n // back to the workspace format when the project has no manifest.\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 ...nodeImageVersions(),\n },\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\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(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n },\n DEPENDENCIES,\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, DEPENDENCIES);\n project.targets[dockerTargetName] = {\n cache: IMAGE_BUILD_CACHE,\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 addArtifactDependencyToTargets(project, 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\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 // @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 // Classic yarn only honours the `**/`-prefixed descriptor in a workspace, and\n // berry only the bare one — it deletes a glob descriptor on install — so\n // declare both.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\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 // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsMcpServerMetadata = {\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n ...(iac ? { iac } : {}),\n };\n\n // The MCP inspector has a postinstall script that cascades installs into its\n // client packages, which no-ops when the package is installed as a dependency.\n // Register it as an explicitly-rejected build so pnpm 11's default\n // `strictDepBuilds=true` skips it instead of failing the install.\n registerPnpmBuiltDependencies(tree, {\n '@modelcontextprotocol/inspector': false,\n });\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\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 metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","addTsDependencies","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addMcpServerInfra","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addArtifactDependencyToTargets","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","registerPnpmBuiltDependencies","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","dev","root","py","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","Error","defaultName","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","auth","console","warn","projectPackageJsonPath","esm","type","dirname","adotVersion","jaegerVersion","nodeBaseImage","node","overwriteStrategy","KeepExisting","containers","dockerImageTag","targetFilePath","bundleOutputDir","dockerOutputDir","dockerTargetName","fs","targets","cache","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","mcpServerNameKebabCase","projectName","delete","packageJson","resolutions","localDevPort","component","info","metadata","port","rc","projectRoot","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,qCAAqC,EACrCC,iBAAiB,QACZ,6DAA6D;AACpE,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA+B;AACtC,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,uBAAuB,EACvBC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,SAAS,EAAEC,WAAW,QAAQ,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/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 detectPackageManager,\n type GeneratorCallback,\n generateFiles,\n joinPathFragments,\n OverwriteStrategy,\n readJson,\n type Tree,\n updateJson,\n updateProjectConfiguration,\n} from '@nx/devkit';\nimport { addTsDependencies } from '../../utils/add-dependencies.js';\nimport {\n AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES,\n type AgentCoreArtifact,\n addMcpServerInfra,\n} from '../../utils/agent-core-constructs/agent-core-constructs.js';\nimport {\n addTypeScriptCodePackageTarget,\n agentCoreNodeRuntime,\n CODE_PACKAGE_DEPENDENCIES,\n isAgentCoreHosted,\n isContainerHosted,\n} from '../../utils/agent-core-packaging.js';\nimport {\n addTypeScriptBundleTarget,\n BUNDLE_DEPENDENCIES,\n} from '../../utils/bundle/bundle.js';\nimport { resolveContainers } from '../../utils/containers.js';\nimport {\n declareDependencies,\n ownedElsewhere,\n} from '../../utils/declared-dependencies.js';\nimport {\n ADOT_IMAGE_DEPENDENCIES,\n addDockerScanTarget,\n DOCKER_DEPENDENCIES,\n IMAGE_BUILD_CACHE,\n NODE_IMAGE_DEPENDENCIES,\n nodeImageVersions,\n} from '../../utils/docker.js';\nimport { formatFilesInSubtree } from '../../utils/format.js';\nimport { FS_DEPENDENCIES, FsCommands } from '../../utils/fs.js';\nimport { resolveIac } from '../../utils/iac.js';\nimport { installDependencies } from '../../utils/install.js';\nimport { addGeneratorMetricsIfApplicable } from '../../utils/metrics.js';\nimport { isEsmWorkspace } from '../../utils/module-format.js';\nimport { kebabCase, toClassName } from '../../utils/names.js';\nimport { getNpmScope } from '../../utils/npm-scope.js';\nimport {\n addArtifactDependencyToTargets,\n addComponentDevTarget,\n addComponentGeneratorMetadata,\n addDependencyToTargetIfNotPresent,\n getGeneratorInfo,\n type NxGeneratorInfo,\n readProjectConfigurationUnqualified,\n} from '../../utils/nx.js';\nimport { sortObjectKeys } from '../../utils/object.js';\nimport { registerPnpmBuiltDependencies } from '../../utils/pnpm-workspace.js';\nimport { assignPort } from '../../utils/port.js';\nimport {\n SHARED_CONSTRUCTS_DEPENDENCIES,\n sharedConstructsGenerator,\n} from '../../utils/shared-constructs.js';\nimport type { IacMetadata } from '../../utils/shared-constructs-constants.js';\nimport { BASE_IMAGES, TS_VERSIONS } from '../../utils/versions.js';\nimport type { TsMcpServerGeneratorSchema, TsMcpServerInfra } from './schema';\n\n/** The metadata this generator records, which its predicates read. */\nexport interface TsMcpServerMetadata extends IacMetadata {\n readonly port: number;\n readonly rc: string;\n readonly auth: string;\n /**\n * How this component is packaged and hosted, so a consumer can tell a\n * code-packaged runtime from a container-packaged one without re-deriving it.\n */\n readonly infra: TsMcpServerInfra;\n}\n\nexport const DEPENDENCIES = declareDependencies<TsMcpServerMetadata>()({\n ts: [\n { name: '@modelcontextprotocol/sdk' },\n { name: 'zod' },\n { name: 'express' },\n { name: '@aws-lambda-powertools/parameters' },\n { name: '@aws-sdk/client-appconfigdata' },\n { name: '@types/express', dev: true },\n // tsx (local dev) and the MCP inspector are shared tooling.\n { name: 'tsx', dev: true, root: true },\n { name: '@modelcontextprotocol/inspector', dev: true, root: true },\n ...ownedElsewhere(FS_DEPENDENCIES),\n ...ownedElsewhere(BUNDLE_DEPENDENCIES),\n ...ownedElsewhere(DOCKER_DEPENDENCIES),\n ...ownedElsewhere(SHARED_CONSTRUCTS_DEPENDENCIES),\n ...ownedElsewhere(NODE_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(ADOT_IMAGE_DEPENDENCIES),\n ...ownedElsewhere(CODE_PACKAGE_DEPENDENCIES),\n ],\n py: ownedElsewhere(AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES),\n});\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 // Recorded in the metadata below so the version sync can tell a CDK\n // project from a Terraform one; undefined when no infrastructure was\n // generated, in which case neither provider's packages were added.\n const iac =\n infra !== 'none' ? await resolveIac(tree, options.iac) : undefined;\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 project's package.json is `type: module`, falling\n // back to the workspace format when the project has no manifest.\n const esm = tree.exists(projectPackageJsonPath)\n ? readJson(tree, projectPackageJsonPath).type === 'module'\n : isEsmWorkspace(tree);\n\n const templateContext = {\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 ...nodeImageVersions(),\n };\n\n // Generate example server\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'app'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n // Add hosting based on infra\n if (isAgentCoreHosted(infra)) {\n const container = isContainerHosted(infra);\n const containers = await resolveContainers(tree, 'inherit');\n const dockerImageTag = `${getNpmScope(tree)}-${name}:latest`;\n\n // Add bundle target\n await addTypeScriptBundleTarget(\n tree,\n project,\n {\n targetFilePath: `${targetSourceDirRelativeToProjectRoot}/http.ts`,\n bundleOutputDir: joinPathFragments('mcp', name),\n },\n DEPENDENCIES,\n );\n\n const bundleOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'bundle',\n 'mcp',\n name,\n );\n\n let artifact: AgentCoreArtifact;\n\n if (container) {\n // Add the Dockerfile\n generateFiles(\n tree,\n joinPathFragments(import.meta.dirname, 'files', 'deploy'),\n targetSourceDir,\n templateContext,\n { overwriteStrategy: OverwriteStrategy.KeepExisting },\n );\n\n const dockerTargetName = `${mcpTargetPrefix}-docker`;\n\n const fs = new FsCommands(tree, DEPENDENCIES);\n project.targets[dockerTargetName] = {\n cache: IMAGE_BUILD_CACHE,\n executor: 'nx:run-commands',\n options: {\n commands: [\n fs.cp(\n `${targetSourceDir}/Dockerfile`,\n `${bundleOutputDir}/Dockerfile`,\n ),\n `${containers} build --platform linux/arm64 -t ${dockerImageTag} ${bundleOutputDir}`,\n ],\n parallel: false,\n },\n dependsOn: ['bundle'],\n };\n\n addDependencyToTargetIfNotPresent(project, 'docker', dockerTargetName);\n addArtifactDependencyToTargets(project, 'docker');\n\n addDockerScanTarget(\n tree,\n {\n project,\n containerEngine: containers,\n trivyTargetName: `${mcpTargetPrefix}-trivy`,\n dockerTargetName,\n imageTags: [dockerImageTag],\n },\n DEPENDENCIES,\n );\n\n artifact = {\n type: 'container',\n dockerImageTag,\n outputDir: bundleOutputDir,\n };\n } else {\n const packageOutputDir = joinPathFragments(\n 'dist',\n project.root,\n 'package',\n 'mcp',\n name,\n );\n addTypeScriptCodePackageTarget(\n tree,\n {\n project,\n targetName: `${mcpTargetPrefix}-package`,\n bundleTargetName: 'bundle',\n bundleOutputDir,\n packageOutputDir,\n },\n DEPENDENCIES,\n );\n\n artifact = {\n type: 'code',\n outputDir: packageOutputDir,\n runtime: agentCoreNodeRuntime(),\n entryPoint: 'index.js',\n };\n }\n\n // Add shared constructs\n await sharedConstructsGenerator(tree, { iac }, DEPENDENCIES);\n\n // Add the construct to deploy the mcp server\n await addMcpServerInfra(tree, {\n mcpServerNameKebabCase: name,\n mcpServerNameClassName,\n projectName: project.name,\n artifact,\n iac,\n auth,\n containers,\n });\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 // Classic yarn only honours the `**/`-prefixed descriptor in a workspace, and\n // berry only the bare one — it deletes a glob descriptor on install — so\n // declare both.\n if (detectPackageManager() === 'yarn') {\n updateJson(tree, 'package.json', (packageJson) => {\n packageJson.resolutions = {\n ...packageJson.resolutions,\n '**/@modelcontextprotocol/sdk/zod': TS_VERSIONS['zod'],\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 // Recorded below and read by the declaration's predicates, so the packages\n // added here are exactly the ones the version sync will own.\n const metadata: TsMcpServerMetadata = {\n infra,\n port: localDevPort,\n rc: mcpServerNameClassName,\n auth,\n ...(iac ? { iac } : {}),\n };\n\n // The MCP inspector has a postinstall script that cascades installs into its\n // client packages, which no-ops when the package is installed as a dependency.\n // Register it as an explicitly-rejected build so pnpm 11's default\n // `strictDepBuilds=true` skips it instead of failing the install.\n registerPnpmBuiltDependencies(tree, {\n '@modelcontextprotocol/inspector': false,\n });\n\n addTsDependencies(tree, DEPENDENCIES, {\n metadata,\n projectRoot: project.root,\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 metadata,\n );\n\n await addGeneratorMetricsIfApplicable(tree, [TS_MCP_SERVER_GENERATOR_INFO]);\n\n await formatFilesInSubtree(tree);\n return () =>\n installDependencies(tree, options.preferInstallDependencies, {\n languages: ['typescript'],\n });\n};\n\nexport default tsMcpServerGenerator;\n"],"names":["detectPackageManager","generateFiles","joinPathFragments","OverwriteStrategy","readJson","updateJson","updateProjectConfiguration","addTsDependencies","AGENT_CORE_CONSTRUCTS_PY_DEPENDENCIES","addMcpServerInfra","addTypeScriptCodePackageTarget","agentCoreNodeRuntime","CODE_PACKAGE_DEPENDENCIES","isAgentCoreHosted","isContainerHosted","addTypeScriptBundleTarget","BUNDLE_DEPENDENCIES","resolveContainers","declareDependencies","ownedElsewhere","ADOT_IMAGE_DEPENDENCIES","addDockerScanTarget","DOCKER_DEPENDENCIES","IMAGE_BUILD_CACHE","NODE_IMAGE_DEPENDENCIES","nodeImageVersions","formatFilesInSubtree","FS_DEPENDENCIES","FsCommands","resolveIac","installDependencies","addGeneratorMetricsIfApplicable","isEsmWorkspace","kebabCase","toClassName","getNpmScope","addArtifactDependencyToTargets","addComponentDevTarget","addComponentGeneratorMetadata","addDependencyToTargetIfNotPresent","getGeneratorInfo","readProjectConfigurationUnqualified","sortObjectKeys","registerPnpmBuiltDependencies","assignPort","SHARED_CONSTRUCTS_DEPENDENCIES","sharedConstructsGenerator","BASE_IMAGES","TS_VERSIONS","DEPENDENCIES","ts","name","dev","root","py","TS_MCP_SERVER_GENERATOR_INFO","filename","tsMcpServerGenerator","tree","options","project","exists","Error","defaultName","split","pop","mcpServerNameClassName","mcpTargetPrefix","targetSourceDirRelativeToProjectRoot","targetSourceDir","relativeSourceDir","replace","distDir","infra","iac","undefined","auth","console","warn","projectPackageJsonPath","esm","type","templateContext","adotVersion","jaegerVersion","nodeBaseImage","node","dirname","overwriteStrategy","KeepExisting","container","containers","dockerImageTag","targetFilePath","bundleOutputDir","artifact","dockerTargetName","fs","targets","cache","executor","commands","cp","parallel","dependsOn","containerEngine","trivyTargetName","imageTags","outputDir","packageOutputDir","targetName","bundleTargetName","runtime","entryPoint","mcpServerNameKebabCase","projectName","packageJson","resolutions","localDevPort","component","info","metadata","port","rc","projectRoot","mcpTargets","continuous","cwd","env","PORT","LOCAL_DEV","preferInstallDependencies","languages"],"mappings":"AAAA;;;CAGC,GACD,SACEA,oBAAoB,EAEpBC,aAAa,EACbC,iBAAiB,EACjBC,iBAAiB,EACjBC,QAAQ,EAERC,UAAU,EACVC,0BAA0B,QACrB,aAAa;AACpB,SAASC,iBAAiB,QAAQ,kCAAkC;AACpE,SACEC,qCAAqC,EAErCC,iBAAiB,QACZ,6DAA6D;AACpE,SACEC,8BAA8B,EAC9BC,oBAAoB,EACpBC,yBAAyB,EACzBC,iBAAiB,EACjBC,iBAAiB,QACZ,sCAAsC;AAC7C,SACEC,yBAAyB,EACzBC,mBAAmB,QACd,+BAA+B;AACtC,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SACEC,mBAAmB,EACnBC,cAAc,QACT,uCAAuC;AAC9C,SACEC,uBAAuB,EACvBC,mBAAmB,EACnBC,mBAAmB,EACnBC,iBAAiB,EACjBC,uBAAuB,EACvBC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,oBAAoB,QAAQ,wBAAwB;AAC7D,SAASC,eAAe,EAAEC,UAAU,QAAQ,oBAAoB;AAChE,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,mBAAmB,QAAQ,yBAAyB;AAC7D,SAASC,+BAA+B,QAAQ,yBAAyB;AACzE,SAASC,cAAc,QAAQ,+BAA+B;AAC9D,SAASC,SAAS,EAAEC,WAAW,QAAQ,uBAAuB;AAC9D,SAASC,WAAW,QAAQ,2BAA2B;AACvD,SACEC,8BAA8B,EAC9BC,qBAAqB,EACrBC,6BAA6B,EAC7BC,iCAAiC,EACjCC,gBAAgB,EAEhBC,mCAAmC,QAC9B,oBAAoB;AAC3B,SAASC,cAAc,QAAQ,wBAA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E,uBAAuB;QACvBsC,SAASxD,eAAemF;IAC1B;IAEAvF,8BACEoB,MACAE,QAAQT,IAAI,EACZI,8BACAa,sCACAD,iBACAsD;IAGF,MAAM1F,gCAAgC2B,MAAM;QAACH;KAA6B;IAE1E,MAAM7B,qBAAqBgC;IAC3B,OAAO,IACL5B,oBAAoB4B,MAAMC,QAAQwE,yBAAyB,EAAE;YAC3DC,WAAW;gBAAC;aAAa;QAC3B;AACJ,EAAE;AAEF,eAAe3E,qBAAqB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { IacOption } from '../../utils/iac.js';\n\nexport type TsMcpServerInfra = 'none' | 'agentcore';\n\nexport type TsMcpServerAuth = 'iam' | 'cognito';\n\nexport interface TsMcpServerGeneratorSchema {\n project: string;\n name?: string;\n infra?: TsMcpServerInfra;\n auth?: TsMcpServerAuth;\n iac: IacOption;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GAQD,WAOC"}
1
+ {"version":3,"sources":["../../../../../../packages/nx-plugin/src/ts/mcp-server/schema.d.ts"],"sourcesContent":["/**\n * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { AgentCoreInfra } from '../../utils/agent-core-packaging.js';\nimport { IacOption } from '../../utils/iac.js';\n\nexport type TsMcpServerInfra = AgentCoreInfra;\n\nexport type TsMcpServerAuth = 'iam' | 'cognito';\n\nexport interface TsMcpServerGeneratorSchema {\n project: string;\n name?: string;\n infra?: TsMcpServerInfra;\n auth?: TsMcpServerAuth;\n iac: IacOption;\n preferInstallDependencies?: boolean;\n}\n"],"names":[],"mappings":"AAAA;;;CAGC,GASD,WAOC"}
@@ -3,9 +3,10 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
 
6
+ import { AgentCoreInfra } from '../../utils/agent-core-packaging.js';
6
7
  import { IacOption } from '../../utils/iac.js';
7
8
 
8
- export type TsMcpServerInfra = 'none' | 'agentcore';
9
+ export type TsMcpServerInfra = AgentCoreInfra;
9
10
 
10
11
  export type TsMcpServerAuth = 'iam' | 'cognito';
11
12
 
@@ -39,9 +39,9 @@
39
39
  },
40
40
  "infra": {
41
41
  "type": "string",
42
- "description": "The type of infrastructure to host your MCP server. Select none for no hosting.",
42
+ "description": "The type of infrastructure to host your MCP server. agentcore deploys your code as a zip to an AgentCore managed runtime for the fastest build and deploy cycle. agentcore-ecr builds and hosts a container image instead, for OS-level control or an established container pipeline. Select none for no hosting.",
43
43
  "x-prompt": "How would you like to host your MCP server?",
44
- "enum": ["agentcore", "none"],
44
+ "enum": ["agentcore", "agentcore-ecr", "none"],
45
45
  "default": "agentcore",
46
46
  "x-priority": "important"
47
47
  },