Skip to content

Python MCP Server to DynamoDB

The connection generator wires a Python MCP Server to a Python DynamoDB project, configuring local development so both start together automatically.

Before using this generator, ensure you have:

  1. A py#mcp-server project
  2. A py#dynamodb project

Run this generator@aws/nx-plugin:connection

pnpm nx g @aws/nx-plugin:connection
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.

Generator Options5 options
sourceProjectRequiredstring

The source project

targetProjectRequiredstring

The target project to connect to

sourceComponentstring

The 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.

targetComponentstring

The 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: true

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.

The generator updates the MCP server’s <mcp-server-name>-dev target in project.json to depend on the DynamoDB project’s dev target, and adds the DynamoDB package as a workspace dependency. No source files are modified.

Import entity classes from the DynamoDB package and use them inside your MCP server tools:

packages/my_project/my_project/my_mcp_server/server.py
from my_scope_my_table.entities.example import ExampleModel
@mcp.tool()
def list_examples() -> str:
"""List all example items."""
items = list(ExampleModel.scan())
return str([item.attribute_values for item in items])

To allow the MCP server’s Lambda function to access the DynamoDB table, grant the necessary permissions in your infrastructure.

packages/infra/src/stacks/application-stack.ts
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.

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 is_local() returns True and your PynamoDB entities connect to the local DynamoDB instance instead of AWS.