Skip to content

Commit c5b0453

Browse files
feat(aws-iac-mcp-server): CDK best practices tool (#1832)
* feat(aws-iac-mcp-server): CDK best practices tool * feat(aws-iac-mcp-server): CDK best practices tool * feat(aws-iac-mcp-server): CDK best practices tool * chore(aws-iac-mcp-server): CDK best practices updates * chore(aws-iac-mcp-server): CDK best practices tool usage instruction * chore(aws-iac-mcp-server): updated CDK best practices * chore(aws-iac-mcp-server): update CDK Nag text in best practices --------- Co-authored-by: Jimin Kim <[email protected]>
1 parent 7bace1f commit c5b0453

File tree

6 files changed

+808
-2
lines changed

6 files changed

+808
-2
lines changed

.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
"filename": "src/aws-iac-mcp-server/README.md",
134134
"hashed_secret": "df99ad98cabfe1616640820bcfb345ef5b10077f",
135135
"is_verified": false,
136-
"line_number": 188,
136+
"line_number": 194,
137137
"is_secret": false
138138
}
139139
],
@@ -906,5 +906,5 @@
906906
}
907907
]
908908
},
909-
"generated_at": "2025-11-21T19:55:13Z"
909+
"generated_at": "2025-11-24T17:57:50Z"
910910
}

src/aws-iac-mcp-server/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ Searches CDK code samples, examples, constructs, and patterns documentation.
101101
- `query` (required): Search query for CDK samples and constructs
102102
- `language` (optional): Programming language filter (default: "typescript")
103103

104+
### cdk_best_practices
105+
Provides CDK best practices for application configuration, coding, constructs, security, and testing.
106+
107+
**Parameters:**
108+
- None
109+
104110
## Prerequisites
105111

106112
1. Install `uv` from [Astral](https://docs.astral.sh/uv/getting-started/installation/) or the [GitHub README](https://github.com/astral-sh/uv#installation)
@@ -256,6 +262,12 @@ Search CloudFormation documentation for AWS::Lambda::Function properties
256262
Find CDK code samples for serverless API with TypeScript
257263
```
258264

265+
### Consult CDK best practices
266+
267+
```
268+
Suggest improvements to my CDK setup based on the best practices
269+
```
270+
259271
## Security Considerations
260272

261273
⚠️ **Privacy Notice**: This MCP server executes AWS API calls using your credentials and shares the response data with your third-party AI model provider (e.g., Amazon Q, Claude Desktop, Cursor, VS Code). Users are responsible for understanding your AI provider's data handling practices and ensuring compliance with your organization's security and privacy requirements when using this tool with AWS resources.

src/aws-iac-mcp-server/awslabs/aws_iac_mcp_server/server.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from .sanitizer import sanitize_tool_response
2323
from .tools.cdk_tools import (
2424
SupportedLanguages,
25+
cdk_best_practices_tool,
2526
read_cdk_documentation_page_tool,
2627
search_cdk_documentation_tool,
2728
search_cdk_samples_and_constructs_tool,
@@ -50,6 +51,7 @@
5051
- Use `search_cdk_samples_and_constructs` when: You need working code examples, implementation patterns, or community constructs
5152
- Use `read_cdk_documentation_page` when: You have a specific documentation URL from search results and need complete content with pagination support
5253
- Use `search_cloudformation_documentation` when: You need Cloudformation related official documentation, resource type information or template syntax
54+
- Use `cdk_best_practices` when: You need to generate or review CDK code
5355
5456
""",
5557
)
@@ -475,6 +477,50 @@ async def search_cdk_samples_and_constructs(
475477
return sanitize_tool_response(json.dumps(response_dict))
476478

477479

480+
@mcp.tool()
481+
async def cdk_best_practices() -> str:
482+
"""Returns CDK best practices and security guidelines.
483+
484+
## Usage
485+
486+
This tool provides comprehensive CDK development guidelines, security best practices, and architectural recommendations. Always run this tool when asked to generate or review CDK code and follow the guidelines returned.
487+
488+
## When to Use
489+
490+
- Get CDK security best practices and compliance guidelines
491+
- Look up architectural patterns and recommendations
492+
- Get guidance on CDK application structure and organization
493+
- Research performance optimization techniques
494+
- Learn about proper construct usage and design patterns
495+
- Understand deployment and testing best practices
496+
497+
## Result Interpretation
498+
499+
Returns JSON with:
500+
- knowledge_response: Details of the response
501+
- results: Array with single result containing:
502+
- rank: Always 1
503+
- title: Document title or filename
504+
- url: Source URL of the CDK best practices
505+
- context: A summary of the CDK best practices
506+
- next_step_guidance: If present, suggested next actions to take for answering user query
507+
508+
## Args
509+
510+
No parameters required - this tool returns the complete best practices guide.
511+
512+
## Returns
513+
514+
Complete best practices documentation as text, including security guidelines, architectural patterns, development workflow, and compliance requirements.
515+
"""
516+
result = await cdk_best_practices_tool()
517+
518+
# Convert CDKToolResponse to dict for JSON serialization
519+
response_dict = asdict(result)
520+
521+
return sanitize_tool_response(json.dumps(response_dict))
522+
523+
478524
@mcp.resource('cfn://context/template-examples-and-best-practices')
479525
def get_template_examples() -> str:
480526
"""CloudFormation Template Examples and Best Practices.

0 commit comments

Comments
 (0)