awslabs.dynamodb-mcp-server 2.0.10__py3-none-any.whl

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 (27) hide show
  1. awslabs/__init__.py +17 -0
  2. awslabs/dynamodb_mcp_server/__init__.py +17 -0
  3. awslabs/dynamodb_mcp_server/cdk_generator/__init__.py +19 -0
  4. awslabs/dynamodb_mcp_server/cdk_generator/generator.py +276 -0
  5. awslabs/dynamodb_mcp_server/cdk_generator/models.py +521 -0
  6. awslabs/dynamodb_mcp_server/cdk_generator/templates/README.md +57 -0
  7. awslabs/dynamodb_mcp_server/cdk_generator/templates/stack.ts.j2 +70 -0
  8. awslabs/dynamodb_mcp_server/common.py +94 -0
  9. awslabs/dynamodb_mcp_server/db_analyzer/__init__.py +30 -0
  10. awslabs/dynamodb_mcp_server/db_analyzer/analyzer_utils.py +394 -0
  11. awslabs/dynamodb_mcp_server/db_analyzer/base_plugin.py +355 -0
  12. awslabs/dynamodb_mcp_server/db_analyzer/mysql.py +450 -0
  13. awslabs/dynamodb_mcp_server/db_analyzer/plugin_registry.py +73 -0
  14. awslabs/dynamodb_mcp_server/db_analyzer/postgresql.py +215 -0
  15. awslabs/dynamodb_mcp_server/db_analyzer/sqlserver.py +255 -0
  16. awslabs/dynamodb_mcp_server/markdown_formatter.py +513 -0
  17. awslabs/dynamodb_mcp_server/model_validation_utils.py +845 -0
  18. awslabs/dynamodb_mcp_server/prompts/dynamodb_architect.md +851 -0
  19. awslabs/dynamodb_mcp_server/prompts/json_generation_guide.md +185 -0
  20. awslabs/dynamodb_mcp_server/prompts/transform_model_validation_result.md +168 -0
  21. awslabs/dynamodb_mcp_server/server.py +524 -0
  22. awslabs_dynamodb_mcp_server-2.0.10.dist-info/METADATA +306 -0
  23. awslabs_dynamodb_mcp_server-2.0.10.dist-info/RECORD +27 -0
  24. awslabs_dynamodb_mcp_server-2.0.10.dist-info/WHEEL +4 -0
  25. awslabs_dynamodb_mcp_server-2.0.10.dist-info/entry_points.txt +2 -0
  26. awslabs_dynamodb_mcp_server-2.0.10.dist-info/licenses/LICENSE +175 -0
  27. awslabs_dynamodb_mcp_server-2.0.10.dist-info/licenses/NOTICE +2 -0
@@ -0,0 +1,185 @@
1
+ # DynamoDB Data Model JSON Generation Guide
2
+
3
+ ## Overview
4
+
5
+ This guide explains how to generate the `dynamodb_data_model.json` file required for data model validation. This file contains your table definitions, test data, and access pattern implementations in a format that can be automatically validated.
6
+
7
+ ## When to Generate JSON
8
+
9
+ After completing your DynamoDB data model design (documented in `dynamodb_data_model.md`), you should generate the JSON implementation file. The AI will ask:
10
+
11
+ **"Would you like me to generate the JSON model and validate your DynamoDB data model? (yes/no)"**
12
+
13
+ - **If you respond yes:** The AI will generate the JSON file and proceed to validation
14
+ - **If you respond no:** The design process stops, and you can review the markdown documentation first
15
+
16
+ ## JSON File Structure
17
+
18
+ The `dynamodb_data_model.json` file must contain three main sections:
19
+
20
+ ### 1. Tables Section
21
+ Defines your DynamoDB tables in boto3 `create_table` format.
22
+
23
+ ### 2. Items Section
24
+ Contains test data for validation in boto3 `batch_write_item` format.
25
+
26
+ ### 3. Access Patterns Section
27
+ Lists all access patterns with their AWS CLI implementations for testing.
28
+
29
+ ## Complete JSON Schema
30
+
31
+ ```json
32
+ {
33
+ "tables": [
34
+ {
35
+ "AttributeDefinitions": [
36
+ {"AttributeName": "partition_key_name", "AttributeType": "S|N|B"},
37
+ {"AttributeName": "sort_key_name", "AttributeType": "S|N|B"},
38
+ {"AttributeName": "gsi_key_name", "AttributeType": "S|N|B"}
39
+ ],
40
+ "TableName": "TableName",
41
+ "KeySchema": [
42
+ {"AttributeName": "partition_key_name", "KeyType": "HASH"},
43
+ {"AttributeName": "sort_key_name", "KeyType": "RANGE"}
44
+ ],
45
+ "GlobalSecondaryIndexes": [
46
+ {
47
+ "IndexName": "GSIName",
48
+ "KeySchema": [
49
+ {"AttributeName": "gsi_partition_key", "KeyType": "HASH"},
50
+ {"AttributeName": "gsi_sort_key", "KeyType": "RANGE"}
51
+ ],
52
+ "Projection": {
53
+ "ProjectionType": "ALL|KEYS_ONLY|INCLUDE",
54
+ "NonKeyAttributes": ["attr1", "attr2"]
55
+ }
56
+ }
57
+ ],
58
+ "BillingMode": "PAY_PER_REQUEST"
59
+ }
60
+ ],
61
+ "items": {
62
+ "TableName": [
63
+ {
64
+ "PutRequest": {
65
+ "Item": {
66
+ "partition_key": {"S": "value"},
67
+ "sort_key": {"S": "value"},
68
+ "attribute": {"S|N|B|SS|NS|BS|M|L|BOOL|NULL": "value"}
69
+ }
70
+ }
71
+ }
72
+ ]
73
+ },
74
+ "access_patterns": [
75
+ {
76
+ "pattern": "1",
77
+ "description": "Pattern description",
78
+ "table": "TableName",
79
+ "index": "GSIName|null",
80
+ "dynamodb_operation": "Query|GetItem|PutItem|UpdateItem|DeleteItem|BatchGetItem|TransactWrite",
81
+ "implementation": "aws dynamodb [operation] --table-name TableName --key-condition-expression 'pk = :pk' --expression-attribute-values '{\":pk\":{\"S\":\"value\"}}'",
82
+ "reason": "Optional: Why pattern cannot be implemented in DynamoDB"
83
+ }
84
+ ]
85
+ }
86
+ ```
87
+
88
+ ## JSON Generation Rules
89
+
90
+ ### Tables Section Rules
91
+
92
+ Generate boto3 `create_table` format with AttributeDefinitions, TableName, KeySchema, GlobalSecondaryIndexes, BillingMode:
93
+
94
+ - **Map attribute types**: string→S, number→N, binary→B
95
+ - **Include ONLY key attributes** used in KeySchemas in AttributeDefinitions (table keys AND GSI keys)
96
+ - **CRITICAL**: Never include attributes in AttributeDefinitions that aren't used in any KeySchema - this violates DynamoDB validation
97
+ - **Extract partition_key and sort_key** from table description
98
+ - **Include GlobalSecondaryIndexes array** with GSI definitions from `### GSIName GSI` sections
99
+ - **If no GSIs exist** for a table, omit the GlobalSecondaryIndexes field entirely
100
+ - **If multiple GSIs exist** for a table, include all of them in the GlobalSecondaryIndexes array
101
+ - **For each GSI**: Include IndexName, KeySchema, Projection with correct ProjectionType
102
+ - **Use INCLUDE projection** with NonKeyAttributes from "Per‑Pattern Projected Attributes" section
103
+
104
+ ### Items Section Rules
105
+
106
+ Generate boto3 `batch_write_item` format grouped by TableName:
107
+
108
+ - **Each table contains array** of 5-10 PutRequest objects with Item data
109
+ - **Convert values to DynamoDB format**: strings→S, numbers→N, booleans→BOOL with True/False (Python-style capitalization: True not true), etc.
110
+ - **Create one PutRequest per data row**
111
+ - **Include ALL item definitions** found in markdown - do not skip any items
112
+ - **Generate realistic test data** that demonstrates the table's entity types and access patterns
113
+
114
+ ### Access Patterns Section Rules
115
+
116
+ Convert to new format with keys: pattern, description, table/index (optional), dynamodb_operation (optional), implementation (optional), reason (optional):
117
+
118
+ - **Use "table" key** for table operations (queries/scans on main table)
119
+ - **Use both "table" and "index" keys** for GSI operations (queries/scans on indexes)
120
+ - **For external services** or patterns that don't involve DynamoDB operations, omit table/index, dynamodb_operation, and implementation keys and include "reason" key explaining why it was skipped
121
+ - **Convert DynamoDB Operations** to dynamodb_operation values: Query, Scan, GetItem, PutItem, UpdateItem, DeleteItem, BatchGetItem, BatchWriteItem, TransactGetItems, TransactWriteItems
122
+ - **Convert Implementation Notes** to valid AWS CLI commands in implementation field with complete syntax:
123
+ - Include `--table-name <TableName>` for all operations
124
+ - Include both partition and sort keys in `--key` parameters
125
+ - **ALWAYS use `--expression-attribute-names`** for all attributes (not just reserved keywords)
126
+ - **Use single quotes** around all JSON parameters (--expression-attribute-values, --item, --key, --transact-items, etc.)
127
+ - **Use correct AWS CLI boolean syntax**: `--flag` for true, `--no-flag` for false (e.g., `--no-scan-index-forward` NOT `--scan-index-forward false`)
128
+ - **Commands must be executable** and syntactically correct with valid JSON syntax
129
+ - **Preserve pattern ranges** (e.g. "1-2") when multiple patterns share the same description, operation, and implementation
130
+ - **Split pattern ranges** when multiple operations exist (e.g. "16-19" with GetItem/UpdateItem becomes two entries: "16-19" with GetItem operation and "16-19" with UpdateItem operation)
131
+
132
+ ### Output Requirements
133
+
134
+ - Write JSON to `dynamodb_data_model.json` with 2-space indentation
135
+ - Always include all three sections: tables, items, access_patterns
136
+ - **ALWAYS include all three keys in the JSON output: "tables", "items", "access_patterns" - even if empty arrays**
137
+
138
+ ## After JSON Generation
139
+
140
+ Once the JSON file is generated, the AI will ask:
141
+
142
+ **"I've generated your `dynamodb_data_model.json` file! Now I can validate your DynamoDB data model. This comprehensive validation will:**
143
+
144
+ **Environment Setup:**
145
+ - Set up DynamoDB Local environment (tries containers first: Docker/Podman/Finch/nerdctl, falls back to Java)
146
+
147
+ **⚠️ IMPORTANT - Isolated Environment:**
148
+ - **Creates a separate DynamoDB Local instance** specifically for validation (container: `dynamodb-local-setup-for-data-model-validation` or Java process: `dynamodb.local.setup.for.data.model.validation`)
149
+ - **Does NOT affect your existing DynamoDB Local setup** - uses an isolated environment
150
+ - **Cleans up only validation tables** to ensure accurate testing
151
+
152
+ **Validation Process:**
153
+ - Create tables from your data model specification
154
+ - Insert test data items into the created tables
155
+ - Test all defined access patterns
156
+ - Save detailed validation results to `dynamodb_model_validation.json`
157
+ - Transform results to markdown format for comprehensive review
158
+
159
+ **This validation helps ensure your design works as expected and identifies any issues. Would you like me to proceed with the validation?**"
160
+
161
+ If you respond positively (yes, sure, validate, test, etc.), the AI will immediately call the `dynamodb_data_model_validation` tool.
162
+
163
+ ## How to Use This Guide
164
+
165
+ 1. **If you haven't started modeling yet**: Call the `dynamodb_data_modeling` tool to begin the design process
166
+ 2. **If you have a design but no JSON**: Provide your `dynamodb_data_model.md` content to the AI and ask it to generate the JSON following this guide
167
+ 3. **If you have the JSON**: Proceed directly to calling `dynamodb_data_model_validation` tool
168
+
169
+ ## Example Workflow
170
+
171
+ ```
172
+ User: "I want to design a DynamoDB model for my e-commerce application"
173
+ AI: [Calls dynamodb_data_modeling tool, guides through requirements]
174
+ AI: [Creates dynamodb_requirement.md and dynamodb_data_model.md]
175
+ AI: "Would you like me to generate the JSON model and validate?"
176
+ User: "Yes"
177
+ AI: [Generates dynamodb_data_model.json following this guide]
178
+ AI: "Would you like me to proceed with validation?"
179
+ User: "Yes"
180
+ AI: [Calls dynamodb_data_model_validation tool]
181
+ ```
182
+
183
+ ## Need Help?
184
+
185
+ If you're unsure about any step, call the `dynamodb_data_modeling` tool and the AI will guide you through the entire process from requirements gathering to validation.
@@ -0,0 +1,168 @@
1
+ # Transform DynamoDB Access Pattern Validation Results
2
+
3
+ You are tasked with transforming DynamoDB access pattern validation results from JSON format to a comprehensive markdown report.
4
+
5
+ ## Input
6
+ - Read the `dynamodb_model_validation.json` file from the current working directory.
7
+ - This file is generated after testing access patterns.
8
+ - The file contains detailed results of each access pattern test execution against DynamoDB Local.
9
+
10
+ ## Output Requirements
11
+ 1. Create a markdown file named `dynamodb_model_validation.md` in the current working directory.
12
+ 2. Transform the JSON data into a well-structured, readable markdown report.
13
+ 3. Display the generated markdown content to the user.
14
+
15
+ ## Markdown Structure
16
+ The output markdown should include:
17
+
18
+ ### Header
19
+ - Title: "DynamoDB Data Model Validation Report"
20
+ - Timestamp of the validation
21
+ - Overall validation effectiveness score
22
+
23
+ ### Executive Summary
24
+ - Overall validation status and success rate
25
+ - Key issues identified
26
+ - Data model effectiveness assessment
27
+ - Test coverage summary
28
+
29
+ ### Resource Creation Results
30
+ - Infrastructure setup summary
31
+ - Status of each table creation (success/failure with error details)
32
+ - GSI creation results
33
+ - Data insertion results
34
+
35
+ ### Access Pattern Results
36
+ List EVERY pattern individually in sequential order. For each access pattern in the `validation_response` array, include:
37
+ - Pattern ID (from `pattern_id` field)
38
+ - Description (from `description` field)
39
+ - DynamoDB Operation Type (from `dynamodb_operation` field)
40
+ - Command Executed (only for failed patterns, formatted as code block)
41
+ - Response Summary (extract key information from the response field)
42
+ - Items Returned (count and sample data if applicable - mark empty results with HTTP 200 as ✅ Success)
43
+ - Error Details (if error field is present in response)
44
+ - External Integration Patterns (for patterns with `reason` field - mark as ✅ Success with integration guidance)
45
+ - Empty Result Explanation (for patterns returning 0 items with HTTP 200 - explain why this is expected/valid)
46
+
47
+ ### Recommendations
48
+ - Specific fixes for failed patterns based on validation results
49
+ - Integration guidance for external service patterns
50
+
51
+ ### Formatting Guidelines
52
+ - Use proper markdown headers (##, ###)
53
+ - Format JSON responses in code blocks with syntax highlighting
54
+ - Use tables where appropriate for structured data
55
+ - Include clear success/error indicators (✅/❌/⚠️/🔄)
56
+ - Calculate and display data model effectiveness percentage
57
+ - Provide specific, actionable recommendations
58
+ - Ensure proper spacing and readability
59
+
60
+ ## Example Output Structure
61
+ ```markdown
62
+ # DynamoDB Data Model Validation Report
63
+
64
+ **Validation Date:** [timestamp]
65
+ **Data Model Effectiveness:** X% (calculated from test coverage and success rates)
66
+
67
+ ## Executive Summary
68
+
69
+ ### Overall Status: ✅ PASSED / ❌ NEEDS ATTENTION / ⚠️ PARTIAL SUCCESS
70
+
71
+ - **Success Rate:** X% (Y out of Z patterns successful)
72
+ - **Critical Issues:** X high-priority failures identified
73
+ - **Test Coverage:** X patterns tested across Y tables
74
+ - **External Integration Patterns:** X patterns require external service integration
75
+
76
+ ### Key Findings
77
+ - Brief summary of major successes
78
+ - Critical issues that need immediate attention
79
+ - Overall assessment of data model design
80
+
81
+ ## Resource Creation Results
82
+
83
+ ### Tables ✅/❌
84
+ - **Table 1:** ✅ Created successfully
85
+ - **Table 2:** ✅ Created successfully
86
+ - **Table 3:** ✅ Created successfully
87
+ - **Table 4:** ✅ Created successfully
88
+ - **Table 5:** ✅ Created successfully
89
+
90
+ ### Global Secondary Indexes ✅/❌
91
+ - **GSI 1:** ✅ Created successfully
92
+
93
+ ### Test Data Insertion ✅/❌
94
+ - **Sample Data Set 1:** ✅ Inserted successfully
95
+ - **Sample Data Set 2:** ✅ Inserted successfully
96
+ - **Sample Data Set 3:** ✅ Inserted successfully
97
+
98
+ ## Access Pattern Results
99
+
100
+ ### ✅ SUCCESSFUL PATTERNS
101
+
102
+ #### Access Patterns
103
+ [List patterns that executed successfully and returned data]
104
+
105
+ #### Access Patterns with empty results
106
+ [List patterns that returned 0 items but with successful HTTP 200 status]
107
+
108
+ #### External Integration Required
109
+ [List patterns that cannot be tested with DynamoDB operations due to external service requirements]
110
+
111
+ ### ❌ FAILED PATTERNS
112
+ [List patterns that failed with errors]
113
+
114
+ ##### Pattern 1: Retrieve entity data with related records
115
+ Operation: Query
116
+ Items Returned: 3
117
+ Items:
118
+ ```json
119
+ {
120
+ "entity_data": {"field1": "value1", "field2": "value2"},
121
+ "related_items": [{"name": "Item A", "quantity": 2}],
122
+ "historical_records": [{"date": "2024-10-20", "amount": 99.99}]
123
+ }
124
+ ```
125
+
126
+ ##### Pattern 3: Search items by name/keyword
127
+ Integration Type: OpenSearch
128
+ Reason: Delegated to external search service due to DynamoDB's limited text search capabilities
129
+
130
+ ##### Pattern X: Create entity record (FAILED EXAMPLE)
131
+ Operation: TransactWriteItems
132
+ Command:
133
+ ```bash
134
+ aws dynamodb transact-write-items --transact-items '[{"Put":{"TableName":"Table1","Item":{"pk":{"S":"entity123"},"sk":{"S":"TYPE_A"},"attribute1":{"S":"Value A"},"attribute2":{"S":"unique_value@example.com"}}}},{"Put":{"TableName":"Table2","Item":{"unique_field":{"S":"unique_value@example.com"},"reference_id":{"S":"entity123"}},"ConditionExpression":"attribute_not_exists(unique_field)"}}]'
135
+ ```
136
+
137
+ **Error Details:**
138
+ - **Error:** TransactionCanceledException
139
+ - **Reason:** ConditionalCheckFailed - Unique constraint violation
140
+ - **Impact:** Data integrity constraint working as designed
141
+
142
+ ##### Pattern Y: Create relationship record (FAILED EXAMPLE)
143
+ Operation: PutItem
144
+ Command:
145
+ ```bash
146
+ aws dynamodb put-item --table-name Table3 --item '{"entity_id":{"S":"entity456"},"related_id":{"S":"entity123"},"relation_type":{"S":"ASSOCIATION"},"timestamp":{"S":"2024-10-23T12:01:00Z"}}' --condition-expression 'attribute_not_exists(related_id)'
147
+ ```
148
+
149
+ **Error Details:**
150
+ - **Error:** ConditionalCheckFailedException
151
+ - **Reason:** The conditional request failed - Relationship already exists
152
+ - **Impact:** Duplicate relationship prevention working as designed
153
+
154
+ ## Recommendations
155
+
156
+ **Based on Validation Results:**
157
+
158
+ 1. **Fix Failed Patterns:** Address constraint violations in failed test cases
159
+ 2. **External Service Integration:** Implement required integrations for delegated patterns
160
+ 3. **Test Data Enhancement:** Add more test data if empty results were encountered
161
+
162
+ **Pattern-Specific Actions:**
163
+ - For ConditionalCheckFailed errors: Use unique values in test data
164
+ - For external integration patterns: Follow provided integration guidance
165
+ - For empty result patterns: Verify if additional test data is needed
166
+ ```
167
+
168
+ Transform the validation results and create a comprehensive, professional markdown report that provides clear insights into the DynamoDB data model validation outcomes. Focus on actionable recommendations and clear assessment of the data model's effectiveness.