lzwdct/MCP-Server-Cdk
If you are the rightful owner of MCP-Server-Cdk and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This project is a production-ready implementation of the Model Context Protocol (MCP) server, deployed on AWS using CDK, featuring a secure private VPC architecture, AI integration with Amazon Bedrock, and a modern React frontend.
create_item
Create new database item
list_items
List all database items
get_item
Get specific item by ID
delete_item
Delete item by ID
bedrock_chat
AI agent with action execution
bedrock_analyze_items
AI analysis of database items
MCP Server on AWS with CDK
A production-ready implementation of the Model Context Protocol (MCP) server deployed on AWS using CDK, featuring secure private VPC architecture, AI integration with Amazon Bedrock, and a modern React frontend.
๐๏ธ Architecture Overview
This project implements a pure MCP (Model Context Protocol) server with HTTP bridge for browser compatibility, deployed on AWS using a secure private VPC architecture.
graph TB
subgraph "External"
User[๐ค User]
Browser[๐ Web Browser]
end
subgraph "AWS Account"
subgraph "VPC (10.0.0.0/16)"
subgraph "Public Subnet (10.0.1.0/24)"
ALB[๐ Application Load Balancer]
NAT[๐ช NAT Gateway]
end
subgraph "Private Subnet (10.0.2.0/24)"
subgraph "ECS Fargate Cluster"
MCPServer[๐ก MCP Server Container<br/>FastAPI + MCP Bridge<br/>Port 8000]
Frontend[โ๏ธ React Frontend<br/>Material-UI + Vite<br/>Port 3000]
end
end
end
subgraph "AWS Services"
DynamoDB[(๐๏ธ DynamoDB<br/>mcp-items table)]
Bedrock[๐ค Amazon Bedrock<br/>AI Models]
CloudWatch[๐ CloudWatch Logs]
end
end
User --> Browser
Browser --> ALB
ALB --> Frontend
ALB --> MCPServer
MCPServer --> DynamoDB
MCPServer --> Bedrock
MCPServer --> CloudWatch
Frontend --> CloudWatch
classDef aws fill:#ff9900,stroke:#333,stroke-width:2px,color:#fff
classDef private fill:#e1f5fe,stroke:#01579b,stroke-width:2px
classDef public fill:#f3e5f5,stroke:#4a148c,stroke-width:2px
classDef external fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px
class ALB,NAT,DynamoDB,Bedrock,CloudWatch aws
class MCPServer,Frontend private
class User,Browser external
๐ง MCP Protocol Flow
The system implements the Model Context Protocol with an HTTP bridge for browser compatibility:
sequenceDiagram
participant Frontend as React Frontend
participant Bridge as MCP HTTP Bridge
participant Server as MCP Server
participant DB as DynamoDB
participant AI as Amazon Bedrock
Frontend->>Bridge: POST /mcp<br/>{"method": "tools/list"}
Bridge->>Server: handle_list_tools()
Server->>Bridge: [Tool definitions]
Bridge->>Frontend: {"result": {"tools": [...]}}
Frontend->>Bridge: POST /mcp<br/>{"method": "tools/call", "params": {"name": "bedrock_chat"}}
Bridge->>Server: handle_call_tool("bedrock_chat", {...})
Server->>AI: invoke_model()
AI->>Server: AI response with JSON action
Server->>DB: execute_action() (if needed)
DB->>Server: operation_result
Server->>Bridge: [TextContent result]
Bridge->>Frontend: {"result": {"content": [...]}}
๐ ๏ธ Technology Stack
Backend (MCP Server)
- MCP Protocol: Official Model Context Protocol implementation
- FastAPI: HTTP bridge for browser compatibility
- Amazon Bedrock: AI model integration (Titan, Claude)
- DynamoDB: NoSQL database for item storage
- Python: Core server implementation
Frontend
- React 18: Modern UI framework
- Material-UI (MUI): Component library
- Vite: Fast build tool
- MCP Client: Direct MCP protocol communication
Infrastructure (AWS CDK)
- ECS Fargate: Serverless container platform
- Application Load Balancer: Traffic routing and SSL termination
- VPC: Secure private network with public/private subnets
- DynamoDB: Managed NoSQL database
- CloudWatch: Logging and monitoring
- IAM: Fine-grained access control
๐ Security Features
Network Security
- Private VPC: All application resources in private subnets
- Security Groups: Restrictive firewall rules
- NAT Gateway: Outbound internet access for private resources
- ALB: Public-facing load balancer with health checks
Access Control
- IAM Roles: Fine-grained permissions for ECS tasks
- Service-to-Service: Secure communication between components
- No Public IPs: Application containers have no direct internet access
Data Protection
- DynamoDB Encryption: Data encrypted at rest
- CloudWatch Logs: Centralized, secure logging
- VPC Endpoints: Private AWS service communication (optional)
๐ Project Structure
mcp-server-cdk-package/
โโโ lib/
โ โโโ mcp-server-stack.ts # CDK infrastructure definition
โโโ mcp-server/
โ โโโ main.py # MCP server + HTTP bridge
โ โโโ requirements.txt # Python dependencies
โ โโโ Dockerfile # Container configuration
โโโ simple-frontend/
โ โโโ src/
โ โ โโโ App.jsx # React MCP client
โ โโโ package.json # Frontend dependencies
โ โโโ Dockerfile # Container configuration
โโโ bin/
โ โโโ mcp-server-cdk-package.ts # CDK app entry point
โโโ cdk.json # CDK configuration
โโโ README.md # This file
๐ ๏ธ Prerequisites
- Node.js 18 or later
- AWS CLI configured with appropriate credentials
- Docker (for local development)
- AWS CDK CLI (
npm install -g aws-cdk
)
๐ Quick Start
1. Clone and Setup
git clone <repository-url>
cd mcp-server-cdk-package
npm install
2. Deploy to AWS
# Bootstrap CDK (first time only)
cdk bootstrap
# Deploy the entire stack
cdk deploy
3. Access Your Application
After deployment, you'll see outputs with URLs:
- Application URL: Main frontend application
- MCP API: Backend MCP protocol endpoint
- Health Check URL: Backend health status
๐๏ธ Deployment Architecture
graph LR
subgraph "Development"
Dev[๐จโ๐ป Developer]
CDK[๐ฆ CDK Code]
end
subgraph "CI/CD Pipeline"
Deploy[๐ cdk deploy]
Build[๐จ Container Build]
end
subgraph "AWS Production"
ECR[๐ฆ ECR Registry]
ECS[๐ณ ECS Services]
ALB[โ๏ธ Load Balancer]
Apps[๐ฑ Applications]
end
Dev --> CDK
CDK --> Deploy
Deploy --> Build
Build --> ECR
ECR --> ECS
ECS --> ALB
ALB --> Apps
๐ฏ Key Features
MCP Protocol Implementation
- Pure MCP: Full Model Context Protocol compliance
- HTTP Bridge: Browser-compatible JSON-RPC 2.0 over HTTP
- Tool Execution: Create, read, update, delete database items
- Resource Access: List and read data sources
- AI Integration: Bedrock-powered intelligent command processing
AI Agent Capabilities
- Natural Language: Process user commands in plain English
- Action Execution: Parse commands and execute MCP tool calls
- JSON Output: Structured action directives for reliable execution
- Error Handling: Graceful error responses and user feedback
Production Ready
- Auto Scaling: ECS Fargate with configurable scaling
- Health Checks: ALB health monitoring
- Logging: Comprehensive CloudWatch integration
- Monitoring: Container and application metrics
๐ ๏ธ Available MCP Tools
Tool | Description | Parameters |
---|---|---|
create_item | Create new database item | name , description , category , metadata |
list_items | List all database items | limit (optional) |
get_item | Get specific item by ID | item_id |
delete_item | Delete item by ID | item_id |
bedrock_chat | AI agent with action execution | message , model_id (optional) |
bedrock_analyze_items | AI analysis of database items | analysis_type , model_id (optional) |
๐ Available MCP Resources
Resource | Description | Data Format |
---|---|---|
items://all | All database items | JSON array |
bedrock://models | Available Bedrock models | JSON array |
๐ API Documentation
MCP HTTP Bridge Endpoints
- POST /mcp: MCP protocol messages (JSON-RPC 2.0)
- GET /health: Health check endpoint
- GET /docs: FastAPI auto-generated documentation
MCP Protocol Methods
tools/list
: List available toolstools/call
: Execute a tool with parametersresources/list
: List available resourcesresources/read
: Read resource content
๐ง Local Development
Run MCP server locally
cd mcp-server
pip install -r requirements.txt
python main.py
Run frontend locally
cd simple-frontend
npm install
npm run dev
Docker Development
# Build and run backend
cd mcp-server
docker build -t mcp-server .
docker run -p 8000:8000 mcp-server
# Build and run frontend
cd simple-frontend
docker build -t mcp-frontend .
docker run -p 3000:3000 mcp-frontend
๐ Usage Examples
Direct MCP Protocol
// List available tools
const tools = await mcpClient.listTools();
// Create an item
const result = await mcpClient.callTool('create_item', {
name: 'My Item',
description: 'Item description',
category: 'test'
});
AI Agent Commands
"create an item called laptop with description work computer"
"list all items"
"delete item abc-123-def"
"analyze all items for insights"
๐ก๏ธ Security Considerations
Network Security
- Private subnets for all application components
- Security groups with minimal required access
- NAT Gateway for outbound internet access
- No direct public IP assignment to containers
IAM Permissions
- Principle of least privilege
- Service-specific roles and policies
- No hardcoded credentials
Data Security
- DynamoDB encryption at rest
- CloudWatch logs encryption
- VPC flow logs (optional)
๐ Monitoring & Logging
CloudWatch Logs
- MCP Server:
/ecs/mcp-server
- Frontend:
/ecs/frontend
- Retention: 7 days
Health Checks
- ALB Health Check:
/health
endpoint - Container Health: ECS task health monitoring
- Database Health: DynamoDB connection validation
๐งช Testing
Test MCP Protocol
# Health check
curl http://your-alb-url/health
# List MCP tools
curl -X POST http://your-alb-url/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "1", "method": "tools/list"}'
# Create an item via MCP
curl -X POST http://your-alb-url/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "2", "method": "tools/call", "params": {"name": "create_item", "arguments": {"name": "Test Item", "description": "A test item", "category": "test"}}}'
Test AI Agent
curl -X POST http://your-alb-url/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": "3", "method": "tools/call", "params": {"name": "bedrock_chat", "arguments": {"message": "create an item called laptop"}}}'
๐ CI/CD Pipeline
The project supports automated deployment through:
- CDK Deploy:
cdk deploy
for infrastructure updates - Container Updates: ECS service updates with zero downtime
- Health Checks: Automated rollback on failed deployments
Cleanup
Clean removal of all AWS resources:
cdk destroy
๐ง Configuration
Environment Variables
DYNAMODB_TABLE_NAME
: DynamoDB table name (default:mcp-items
)AWS_DEFAULT_REGION
: AWS region (default:us-east-1
)NODE_ENV
: Node environment (default:production
)
CDK Configuration
- VPC CIDR:
10.0.0.0/16
- Container Resources: 256 CPU, 512 MB memory
- Auto Scaling: 1-10 tasks based on CPU/memory utilization
๐จ Troubleshooting
Common Issues
- CDK Bootstrap Error: Run
cdk bootstrap
manually - Docker Build Issues: Ensure Docker is running
- Permission Errors: Check AWS IAM permissions
- Port Conflicts: Use different ports for local development
Logs
Check CloudWatch logs:
/ecs/mcp-server
- Backend logs/ecs/frontend
- Frontend logs
๐จ Frontend Features
- Modern UI: Clean, responsive design with Material-UI
- MCP Protocol: Direct MCP communication via HTTP bridge
- AI Chat: Interactive AI agent with natural language commands
- Item Management: Full CRUD operations via MCP tools
- Real-time Updates: Automatic refresh after AI actions
- Responsive: Works on desktop and mobile devices
๐ก๏ธ Production Considerations
- Add SSL certificates for HTTPS
- Configure custom domain names
- Set up backup strategies for DynamoDB
- Implement monitoring and alerting
- Add authentication and authorization
- Configure WAF for additional security
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
For issues and questions:
- Create an issue in the repository
- Check the troubleshooting section
- Review AWS CloudWatch logs
๐ Happy coding with your MCP Server! ๐