MCP Server to DynamoDB
The connection generator wires a TypeScript MCP Server to a TypeScript DynamoDB project, configuring local development so both start together automatically.
Prerequisites
Section titled “Prerequisites”Before using this generator, ensure you have:
- A
ts#mcp-serverproject - A
ts#dynamodbproject
Run the Generator
Section titled “Run the Generator”Run this generator@aws/nx-plugin:connection
pnpm nx g @aws/nx-plugin:connection yarn nx g @aws/nx-plugin:connection npx nx g @aws/nx-plugin:connection bunx nx g @aws/nx-plugin:connection- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- Click
Generate
Build your command5
Required
Required
Select your MCP server project as the source and your DynamoDB project as the target. If the project contains multiple MCP server components, specify sourceComponent to disambiguate.
Options
Section titled “Options”sourceProjectRequiredstringThe source project
targetProjectRequiredstringThe target project to connect to
sourceComponentstringThe source component to connect from (component name, path relative to source project root, or generator id). Use '.' to explicitly select the project as the source.
targetComponentstringThe target component to connect to (component name, path relative to target project root, or generator id). Use '.' to explicitly select the project as the target.
preferInstallDependenciesbooleanDefault:trueWhether 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.
Generator Output
Section titled “Generator Output”The generator updates the MCP server’s <mcp-server-name>-dev target in project.json to depend on the DynamoDB project’s dev target. No source files are modified.
Using DynamoDB in Tools
Section titled “Using DynamoDB in Tools”Import entity factories from the DynamoDB package and use them inside createServer:
import { createExampleEntity } from '@my-scope/my-table';
export const createServer = async () => { const server = new McpServer({ name: 'my-service', version: '1.0.0' });
server.registerTool( 'list_examples', { description: 'List all example items', inputSchema: {} }, async () => { const entity = await createExampleEntity(); const result = await entity.scan.go(); return { content: [{ type: 'text' as const, text: JSON.stringify(result.data) }], }; }, );
return server;};Infrastructure
Section titled “Infrastructure”To allow the MCP server to access the DynamoDB table, grant the necessary permissions in your infrastructure.
import { MyTable } from '@my-scope/common-constructs';
const table = new MyTable(this, 'Table');const myMcpServer = new MyMcpServer(this, 'MyMcpServer');
table.grantReadWriteData(myMcpServer);grantReadWriteData grants both the DynamoDB and KMS permissions to the MCP server’s execution role.
Grant the MCP server’s runtime role access to the table and its KMS encryption key via additional_iam_policy_statements:
module "my_table" { source = "../../common/terraform/src/app/dynamodb/my-table"}
module "my_mcp_server" { source = "../../common/terraform/src/app/mcp-servers/my-mcp-server"
additional_iam_policy_statements = [ { Effect = "Allow" Action = [ "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:UpdateItem", "dynamodb:DeleteItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:BatchGetItem", "dynamodb:BatchWriteItem", ] Resource = [ module.my_table.table_arn, "${module.my_table.table_arn}/index/*", ] }, { Effect = "Allow" Action = [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey", ] Resource = [module.my_table.kms_key_arn] }, ]}Local Development
Section titled “Local Development”The connection generator configures your project’s dev target to depend on the DynamoDB project’s dev target. DynamoDB Local will start automatically alongside your project when running dev.
The LOCAL_DEV=true environment variable is set automatically, so getDynamoDBClient() and resolveTableName() connect to the local DynamoDB Local instance instead of AWS.