Skip to content

feat(ts#mcp-server): use CDK buildContexts for Docker image assets#517

Open
nx-plugin-for-aws wants to merge 2 commits intomainfrom
feat/cdk-build-context
Open

feat(ts#mcp-server): use CDK buildContexts for Docker image assets#517
nx-plugin-for-aws wants to merge 2 commits intomainfrom
feat/cdk-build-context

Conversation

@nx-plugin-for-aws
Copy link
Copy Markdown
Collaborator

Reason for this change

CDK's latest release (2.245.0) now supports buildContexts for DockerImageAsset, enabling Docker's --build-context flag during image builds. This allows us to simplify the Docker setup for agents and MCP servers by removing the workaround that required two Dockerfiles per project.

Previously, each agent/MCP server needed:

  1. A colocated Dockerfile next to the project source (the real one using COPY --from=workspace)
  2. A dummy Dockerfile next to the CDK construct (FROM <tag>) that referenced the pre-built image

The dummy Dockerfile existed solely because CDK's DockerImageAsset didn't support named build contexts (--build-context).

Description of changes

  • Removed the dummy Dockerfile template from agent-core-constructs/files/cdk/
  • Updated the CDK construct template to use AgentRuntimeArtifact.fromAsset() with:
    • buildContexts: { workspace: workspaceRoot } — CDK passes --build-context workspace=<root> to docker build
    • hashDirectory() on the bundle output — ensures changes to bundled code trigger redeployment
    • findWorkspaceRoot() — locates the Nx workspace root by searching for nx.json
  • Updated all 4 generators (ts/py strands-agent, ts/py mcp-server) to:
    • Pass dockerfileDir and bundleOutputDir to the infrastructure functions
    • For CDK: remove docker from build dependencies (CDK builds the image itself via fromAsset)
    • For Terraform: keep docker in build dependencies (Terraform still needs the pre-built image)
  • Bumped CDK versions: aws-cdk-lib to 2.245.0, @aws-cdk/aws-bedrock-agentcore-alpha to 2.245.0-alpha.0
  • Updated dungeon adventure tutorial docs to reflect the new CDK construct pattern

Description of how you validated changes

  • All 1501 unit tests pass (including snapshot updates)
  • Full build passes (pnpm nx run-many --target build --all)
  • Lint passes
  • Verified with a test workspace that:
    • Only one Dockerfile is generated (colocated with the project)
    • The dummy Dockerfile is no longer created
    • The CDK construct correctly uses buildContexts and hashDirectory
    • build.dependsOn no longer includes docker for CDK
  • Verified Terraform tests still pass (docker target kept for Terraform path)

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.87%. Comparing base (223bbb6) to head (0d5a54e).
⚠️ Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
packages/nx-plugin/src/py/mcp-server/generator.ts 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #517      +/-   ##
==========================================
- Coverage   91.04%   90.87%   -0.18%     
==========================================
  Files          90       90              
  Lines        3240     3211      -29     
  Branches      711      706       -5     
==========================================
- Hits         2950     2918      -32     
- Misses        118      122       +4     
+ Partials      172      171       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

📚 Documentation translations have been updated and committed (9f6fba2) to this PR.

docs/src/content/docs/es/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/fr/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/jp/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/ko/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/pt/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/vi/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/zh/get_started/tutorials/dungeon-game/1.mdx

@github-actions
Copy link
Copy Markdown
Contributor

📚 Documentation translations have been updated and committed (6201745) to this PR.

docs/src/content/docs/es/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/fr/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/jp/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/ko/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/pt/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/vi/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/zh/get_started/tutorials/dungeon-game/1.mdx

@github-actions
Copy link
Copy Markdown
Contributor

📚 Documentation translations have been updated and committed (087391d) to this PR.

docs/src/content/docs/es/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/fr/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/jp/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/ko/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/pt/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/vi/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/zh/get_started/tutorials/dungeon-game/1.mdx

@github-actions
Copy link
Copy Markdown
Contributor

📚 Documentation translations have been updated and committed (ee61796) to this PR.

docs/src/content/docs/es/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/fr/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/jp/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/ko/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/pt/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/vi/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/zh/get_started/tutorials/dungeon-game/1.mdx

Simplify Docker setup for agents/MCP servers using CDK buildContexts
(aws-cdk-lib 2.245.0) instead of a dummy Dockerfile workaround.

- Remove dummy Dockerfile from CDK construct directory
- Use buildContexts: { workspace: workspaceRoot } in CDK construct
- Use FileSystem.fingerprint on bundle output for extraHash
- Move findWorkspaceRoot to shared core/utils.ts in common/constructs
- For CDK, remove docker from build dependencies
- Keep docker target for Terraform and local testing
- Bump aws-cdk-lib to 2.245.0
@github-actions
Copy link
Copy Markdown
Contributor

📚 Documentation translations have been updated and committed (0d5a54e) to this PR.

docs/src/content/docs/es/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/es/guides/py-mcp-server.mdx
docs/src/content/docs/es/guides/py-strands-agent.mdx
docs/src/content/docs/es/guides/ts-mcp-server.mdx
docs/src/content/docs/es/guides/ts-strands-agent.mdx
docs/src/content/docs/es/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/fr/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/fr/guides/py-mcp-server.mdx
docs/src/content/docs/fr/guides/py-strands-agent.mdx
docs/src/content/docs/fr/guides/ts-mcp-server.mdx
docs/src/content/docs/fr/guides/ts-strands-agent.mdx
docs/src/content/docs/fr/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/it/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/it/guides/py-mcp-server.mdx
docs/src/content/docs/it/guides/py-strands-agent.mdx
docs/src/content/docs/it/guides/ts-mcp-server.mdx
docs/src/content/docs/it/guides/ts-strands-agent.mdx
docs/src/content/docs/it/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/jp/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/jp/guides/py-mcp-server.mdx
docs/src/content/docs/jp/guides/py-strands-agent.mdx
docs/src/content/docs/jp/guides/ts-mcp-server.mdx
docs/src/content/docs/jp/guides/ts-strands-agent.mdx
docs/src/content/docs/jp/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/ko/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/ko/guides/py-mcp-server.mdx
docs/src/content/docs/ko/guides/py-strands-agent.mdx
docs/src/content/docs/ko/guides/ts-mcp-server.mdx
docs/src/content/docs/ko/guides/ts-strands-agent.mdx
docs/src/content/docs/ko/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/pt/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/pt/guides/py-mcp-server.mdx
docs/src/content/docs/pt/guides/py-strands-agent.mdx
docs/src/content/docs/pt/guides/ts-mcp-server.mdx
docs/src/content/docs/pt/guides/ts-strands-agent.mdx
docs/src/content/docs/pt/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/vi/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/vi/guides/py-mcp-server.mdx
docs/src/content/docs/vi/guides/py-strands-agent.mdx
docs/src/content/docs/vi/guides/ts-mcp-server.mdx
docs/src/content/docs/vi/guides/ts-strands-agent.mdx
docs/src/content/docs/vi/snippets/mcp/shared-constructs.mdx
docs/src/content/docs/zh/get_started/tutorials/dungeon-game/1.mdx
docs/src/content/docs/zh/guides/py-mcp-server.mdx
docs/src/content/docs/zh/guides/py-strands-agent.mdx
docs/src/content/docs/zh/guides/ts-mcp-server.mdx
docs/src/content/docs/zh/guides/ts-strands-agent.mdx
docs/src/content/docs/zh/snippets/mcp/shared-constructs.mdx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants