Deploy real-time coding security validation by using an MCP server with Kiro
Ivan Girardi and Iker Reina Fuente, Amazon Web Services
Summary
This pattern describes how to implement a Model Context Protocol (MCP) server that integrates three widely used security scanning tools to provide code security analysis. The server enables AI coding assistants (such as Kiro, Amazon Q Developer, and Cline) to automatically scan code snippets and infrastructure as code (IaC) configurations. With these scans, the coding assistants can help identify security vulnerabilities, misconfigurations, and compliance violations.
AI code generators are trained on large volumes of code whose security quality can vary. This pattern provides real-time security validation during code generation, helping developers identify and understand potential security issues as they code. This approach also helps developers address both direct vulnerabilities and risks inherited from dependencies. By combining AI efficiency with security checks, this pattern supports the adoption of AI-powered development tools.
This pattern helps organizations enhance their development security practices through AI-assisted coding tools, providing on-demand security scanning across multiple programming languages and infrastructure definitions. The solution combines the capabilities of the following tools:
Checkov for scanning IaC files, including Terraform, AWS CloudFormation, and Kubernetes manifests
Semgrep for analyzing multiple programming languages such as Python, JavaScript, Java, and others
Bandit for specialized Python security scanning
Key features of this solution include the following:
Delta scanning of new code segments, reducing computational overhead
Isolated security tool environments, preventing cross-tool contamination
Integration with AI coding assistants (Kiro, Amazon Q Developer, Cline, and others)
Real-time security feedback during code generation
Customizable scanning rules for organizational compliance
This pattern provides a unified interface for security scanning with standardized response formats, making it easier to integrate security checks into development workflows. It uses Python and the MCP framework to deliver automated security feedback. This approach helps developers identify and address security issues early in the development process while they learn about security best practices through detailed findings.
Prerequisites and limitations
Prerequisites
An active AWS account with access to use Kiro or Amazon Q Developer, if you want to use either of those coding assistants
Python version 3.10 or later installed
uvpackage manager installedFamiliarity with security scanning tools and concepts
Basic understanding of infrastructure as code (IaC) and application security
Limitations
Bandit scanning supports Python files only.
Real-time scanning might impact performance for large codebases.
Each scanning tool supports only specific file formats and languages.
Manual review is required to validate security findings.
Security expertise is required to interpret scanning results.
Some AWS services aren’t available in all AWS Regions. For Region availability, see AWS Services by Region
. For specific endpoints, see Service endpoints and quotas, and choose the link for the service.
Product versions
Python version 3.10 or later
Checkov version 3.0.0 or later
Semgrep version 1.45.0 or later
Bandit version 1.7.5 or later
MCP[cli] version 1.11.0 or later
Pydantic version 1.10.0 or later
Loguru version 0.6.0 or later
Architecture
The following diagram shows the architecture for this solution.

The diagram shows the following workflow:
The developer uses AI assistants (for example, Kiro, Cline, Amazon Q Developer, or Roo Code) to generate or analyze code. The AI assistant sends the code for security scanning.
The Model Context Protocol (MCP) security scanner server processes the request by routing it to the appropriate specialized scanner: Checkov for infrastructure as code (IaC) files, Semgrep for analysis of multiple programming languages, or Bandit for Python-specific security scanning.
The MCP security scanner server sends scanner results, including security findings, severity levels, detailed descriptions, and suggested fixes, back to the developer through the AI assistant.
The developer receives real-time security validation through a continuous feedback loop, which enables automated fixes through AI assistants and promotes security best practices during development.
The architecture helps mitigate the following common security risks:
Command injection
Prompt injection
Path traversal
Dependency attacks
Resource exhaustion
The architecture helps mitigate these risks through the following practices:
The server writes all user and AI model inputs to temporary files.
The server doesn't provide direct inputs to command line interface (CLI) commands.
The server restricts file system access to temporary directories and files only.
The server automatically cleans up temporary files.
The server sanitizes scanning responses.
The server enforces process isolation that restricts process capabilities.
The server logs all scanning activities.
Automation and scale
The pattern supports automation through the following capabilities:
Integration with AI coding assistants for automatic code scanning
Standardized API responses for automated processing
Configuration through MCP configuration files
Support for batch processing of multiple files
Scalable scanning across multiple programming languages and IaC formats
You can automate the scanning process through the following API endpoints:
scan_with_checkovfor IaC scanningscan_with_semgrepfor multi-language code scanningscan_with_banditfor Python-specific scanningget_supported_formatsfor format validation
When extending the scanning tools, follow the design principles and best practices described earlier in this section. Also see Best practices.
Tools
AWS services
Kiro
is an agentic coding service that works alongside developers to turn prompts into detailed specs, then into working code, docs, and tests. Kiro agents help developers solve challenging problems and automate tasks like generating documentation and unit tests. Amazon Q Developer is a generative AI-powered conversational assistant that can help you understand, build, extend, and operate AWS applications.
Other tools
Bandit
is a Python security scanner. It detects common Python security issues like insecure functions, hardcoded secrets, and injection vulnerabilities. Bandit provides detailed confidence and severity ratings. Checkov
is a static code-analysis tool that checks infrastructure as code (IaC) for security and compliance misconfigurations. Cline
is an AI-powered coding assistant that runs in Visual Studio Code. Loguru
is a logging library for Python. Model Context Protocol (MCP)
is an open source framework for building AI-assisted development tools. Pydantic
is a data validation library for Python. Semgrep
analyzes source code for security vulnerabilities and bugs. It supports multiple programming languages. Semgrep uses security-focused rulesets for analysis. It provides detailed confidence and severity ratings.
Code repository
The code for this pattern is available in the GitHub MCP Security Scanner: Real-Time Protection for AI Code Assistants
The repository structure includes:
security_scanner_mcp_server/- Main server implementationdocs/- Documentation and demo materialstests/- Test filesmcp-config-example.json- Example MCP configurationrequirements.txt- Project dependencies
Best practices
Security scanning implementation
Review security findings to validate and prioritize issues.
Keep scanning tools (Checkov, Semgrep, and Bandit) updated to the latest versions.
Use this pattern’s Model Context Protocol (MCP) security tool with other security measures and tools.
Update security rule sets and policies regularly.
Configuration management
Store the MCP configuration files in your version control repository.
Document custom rules and configurations.
Integration
Integrate security scanning early in the development cycle.
Set up automated scanning in pre-commit hooks or continuous integration and continuous deployment (CI/CD) pipelines.
Configure severity thresholds that match your organization’s risk tolerance and environment.
Establish procedures for triaging and remediating security findings.
Operational considerations
Monitor scanning performance and resource usage.
Implement error handling and logging for scan failures.
Establish a process for reviewing and updating security rules.
Follow these additional best practices:
Validate security findings in your specific context.
Keep dependencies up to date.
Use multiple security tools to broaden coverage.
Incorporate secure coding practices into your development process.
Epics
| Task | Description | Skills required |
|---|---|---|
Configure MCP settings. | You can edit the configuration files in Kiro either by (Option 1) manually locating the configuration files or (Option 2) by using the Kiro IDE.
| App developer |
| Task | Description | Skills required |
|---|---|---|
Configure MCP settings. | To configure the MCP settings manually, use the following steps:
| App developer |
| Task | Description | Skills required |
|---|---|---|
Configure MCP settings. | To configure the MCP settings manually, use the following steps:
| App developer |
| Task | Description | Skills required |
|---|---|---|
Perform code analysis. | To perform code analysis by using Python and Bandit, use the following steps:
| App developer |
| Task | Description | Skills required |
|---|---|---|
Perform code analysis. | To perform code analysis by using Terraform and Checkov, use the following steps:
| App developer |
| Task | Description | Skills required |
|---|---|---|
Perform targeted scanning. | Following are examples of requests that you can use to perform a targeted scan:
| App developer |
Use security scanning with code generation. | To resolve security findings by using code generation loops, use the following steps (this example uses Kiro as the coding assistant):
| App developer |
Troubleshooting
| Issue | Solution |
|---|---|
Environment setup issues |
|
Scanner issues |
|
Integration problems |
|
Additional support |
|
Related resources
AWS documentation
Infrastructure as code (AWS Whitepaper Introduction to DevOps on AWS)
Other AWS resources
Other resources
Additional information
Example MCP configuration with auto approved enabled
Without autoApprove configured, you must grant approval before the code assistant sends the code to the MCP security server for scanning. When autoApprove is configured, the code assistant can invoke the tools without your approval. These tools run locally on your machine. They don't send data outside your machine, and they only perform a code scan.
The following configuration automatically runs all security scanning functions:
{ "mcpServers": { "security-scanner": { "command": "uvx", "args": [ "--from", "git+https://github.com/aws-samples/sample-mcp-security-scanner.git@main", "security_scanner_mcp_server" ], "env": { "FASTMCP_LOG_LEVEL": "ERROR" }, "disabled": false, "autoApprove": [ "scan_with_checkov", "scan_with_semgrep", "scan_with_bandit", "get_supported_formats" ] } } }
To enable debug logging, set "FASTMCP_LOG_LEVEL" to "DEBUG".
File formats supported by security scanning tools
Each security scanning tool in this solution supports the following file formats:
Checkov (IaC)
Terraform – .tf, .tfvars, .tfstate
CloudFormation – .yaml, .yml, .json, .template
Kubernetes – .yaml, .yml
Dockerfile – Dockerfile
ARM – .json (Azure Resource Manager)
Bicep – .bicep
Serverless – .yml, .yaml
Helm – .yaml, .yml, .tpl
GitHub Actions – .yml, .yaml
GitLab CI – .yml, .yaml
Ansible – .yml, .yaml
Semgrep (Source code)
Python – .py
JavaScript – .js
TypeScript – .ts
Java – .java
Go – .go
C – .c
C++ – .cpp
C# – .cs
Ruby – .rb
PHP – .php
Scala – .scala
Kotlin – .kt
Rust – .rs
Bandit (Python only)
Python – .py
Demos
For code scanning, try the following sample prompts with your AI assistant:
"Scan the current script and tell me the results."
"Scan lines 20–60 and tell me the results."
"Scan this Amazon DynamoDB table resource and tell me the results."
For more information, see this code scanning demo
To generate secure code, try the following sample prompts:
"Generate a Terraform configuration to create a DynamoDB table with encryption enabled and scan it for security issues."
"Create a Python Lambda function that writes to DynamoDB and scan it for vulnerabilities."
"Generate a CloudFormation template for an Amazon S3 bucket with encryption and public access blocking enabled, and verify it passes security checks."
"Write a Python script to query DynamoDB with pagination and scan for security best practices."
"Create a Kubernetes deployment manifest for a microservice with security hardening and validate it."
For more information, see this code generation with security scanning