AWS Thai Blog

ตัวอย่างการใช้งาน Model Context Protocol(MCP) หลายๆ server เพื่อเพิ่มความสามารถของ Amazon Q Developer CLI

บทความนี้จะต่อยอดมาจาก blog เรื่อง “แนะนำการใช้งาน Model Context Protocol (MCP) ที่จะช่วยเพิ่มขีดความสามารถให้ Amazon Q Developer CLI ทำงานกับเครื่องมือต่าง ๆ ได้” ซึ่งจะอธิบายเกี่ยวกับ Model Context Protocol(MCP) คืออะไร, การตั้งค่า MCP บน Amazon Q Developer CLI และการใช้งาน MCP เบื้องต้นไปแล้ว ซึ่งบทความนี้จะเป็นตัวอย่างของการนำ Model Context Protocol(MCP) หลาย ๆ Server มาใช้งานจริงเพื่อให้เห็นถึงความสามารถและประสิทธิภาพที่เพิ่มขึ้นของ Amazon Q Developer CLI


ซึ่งใน use case ตัวอย่างที่จะเป็นในส่วนของการช่วยในการทำ AWS Solution Architecture และเรื่องอื่น ๆ ที่เกี่ยวข้องซึ่งโดยปกติแล้ว คนส่วนใหญ่เวลาทำ Solution Architecture/ออกแบบ Solution ก็จะมีกระบวนการและ Challenges คร่าว ๆ ดังต่อไปนี้

  • เริ่มจากการทำ Solution Design อาจจะเขียนบน white board หรือมี idea เร็ว ๆ อาจจะเขียนไว้ที่อื่น ๆ ที่สะดวก แต่พอจะใช้งานจริงจำเป็นต้องสร้าง Solution Architecture/Diagram บน draw.io เป็นต้น
  • จะรู้ได้อย่างไรว่า Solution Architecture ที่เขียนหรือออกแบบขึ้นมา ออกแบบตาม AWS Best Practices? หรือควรมี component อะไรเพิ่มเติม
  • Solution Architecture ที่ออกแบบมาโดยเบื้องต้นมีค่าใช้ประมาณเท่าไร (Cost)
  • ถ้า Solution Architecture ที่ออกแบบมาอยากจะ Deploy ซึ่งอยากจะ Create เป็น IaC (Infrastructure as a Code) จะต้องเขียน Code แบบไหน?

ซึ่งใน scenario ที่จะทำการทดสอบกัน จะใช้งาน Amazon Q Developer CLI ร่วมกับ MCP หลาย ๆ Server เพื่อมาตอบสนอง หรือ Challenge ดังกล่าว ซึ่งในบทความนี้จะใช้ MCP Server ดังนี้

  1. awslabsaws_diagram_mcp_server : สำหรับการเขียน diagram
  2. awslabsterraform_mcp_server : สำหรับการตรวจสอบ terrafrom
  3. awslabscost_analysis_mcp_server : สำหรับการวิเคราะห์ราคา
  4. awslabsaws_documentation_mcp_server : สำหรับการ review architect

สำหรับ MCP Server ที่ AWS มี สามารถดูรายละเอียดได้จาก link AWS MCP Server . ซึ่งแต่ละ MCP Server จะออกแบบมาเฉพาะทางเพื่อช่วยให้ทำงานของคุณมีประสิทธิภาพที่มากขึ้น

แนะนำการใช้งาน Amazon Q Developer ใน VS Code

1. การสร้าง Diagram

1.1 เริ่มจากไอเดีย ไม่ว่าจาก ภาพที่วาดด้วยมือหรือจะบน whiteboard หรือ บนกระดาษเปล่า ไปเป็น AWS diagram

สั่งให้ Amazon Q Developer CLI ในการอ่านไฟล์ภาพ และทำการสร้าง diagram

Prompt

Read the AWS diagram at aws-diagram.jpg and create a AWS architecture diagram with edge label (labeled connections) using diagram mcp server

โดยหลักการจะอาศัยความสามารถในการรองรับ multimodal ของ Amazon Q Developer CLI ที่สามารถอ่านและทำความเข้าใจภาพได้ หลังจากนั้นจึงไปเรียก MCP Diagram เพื่อแปลงภาพนั้นไปเป็น AWS diagram

ผลลัพธ์ที่ได้จะเป็นดังภาพ

Result

1.2 ถ้าทางผู้ใช้งานอยากได้ในรูปแบบ ของ Draw.io ก็สามารถเขียนเพิ่มเข้าไปใน prompt ต่อได้ดังนี้

Prompt

Create a draw.io xml file for the diagram

Prompt นี้จะเป็นการสร้างไฟล์ draw.io. สามารถนำไป import ไปใน draw.io ได้ ซึ่งผลลัพธ์จะได้ประมาณรูปข้างล่างนี้
หมายเหตุ : รูป diagram ที่ได้อาจจะแตกต่างกันไปไม่เหมือนกับที่แสดงข้างล่าง

2. Infrastructure as Code สำหรับการ deployment

หลังจากเราได้ diagram มาแล้ว ขั้นตอนถัดมาคือ เราจะลอง deploy solution นี้ได้อย่างไร ,ในที่นี้เราจะใช้ code generation ของ Amazon Q Developer CLI ในการเขียน Terraform code และใช้ MCP Terrafrom ในการ validate code นั้น เพื่อให้ได้ค่าที่ถูกต้องโดยระบุข้อมูลเพิ่มเติมดังตัวอย่างต่อไปนี้

2.1 เริ่มต้นจากเขียน Terraform code

Prompt

I want to test this architecture out , create a terraform code with the following information , assume sensible defaults
Project: “mywebapp”
Environment: “prod”
Region: “ap-southeast-7”

Networking:
VPC CIDR: “10.0.0.0/16”
Public subnets: “10.0.1.0/24”, “10.0.2.0/24”
Private subnets: “10.0.3.0/24”, “10.0.4.0/24”
AZs: “ap-southeast-7a”, “ap-southeast-7b”

Application:
Container image: “123456789012.dkr.ecr.ap-southeast-7.amazonaws.com/myapp:latest”
App port: 3000
ECS vCPU: 2, Memory: 256MB per task
Desired tasks: 4

Database:
Engine: MySQL 8.0
Instance: db.r6g.large
-storage: 50 GB
DB name: “webapp_db”
Master user: “admin”

Domain:
Domain: “myapp.example.com”
Health check: “/health”
S3 bucket: “myapp-static-assets”

ผลลัพธ์ที่ได้คือ Terrafrom file ของ component ทั้งหมด ซึ่งเราสามารถเข้าไปปรับแต่งแก้ไข code ได้ทีหลัง

Result

Perfect! I've created a comprehensive Terraform configuration for your AWS web application architecture. Here's what I've built for you:

## 📁 Generated Files

All files are saved in /Users/admin/qcli/generated-iac/


    ## 🏗️ Architecture Features Implemented

    ### ✅ Exactly as per your diagram:
    ○    Route 53 DNS → CloudFront CDN → ALB → ECS → Aurora MySQL
    ○    S3 static content served via CloudFront
    ○    ACM certificates for SSL/TLS
    ○    VPC with public/private subnets

    ### 🚀 Production-Ready Enhancements:
    ○    Multi-AZ deployment across 2 availability zones
    ○    Auto Scaling ready ECS service
    ○    Secrets Manager for database credentials
    ○    CloudWatch logging for ECS tasks
    ○    Health checks and monitoring
    ○    Security groups with least privilege
    ○    Encryption for S3 and RDS

2.2 ใช้ MCP Terrafrom ในการ validate code ก่อนนำไป deploy จริง (awslabsterraform_mcp_server)

Prompt

I have terraform code at generated-iac folder , use terraform mcp server to validate the code for me

Result

Great! I can see you have a comprehensive Terraform project with multiple resource files. Now let me initialize and
validate the Terraform code using the Terraform MCP server.


🛠️  Using tool: ExecuteTerraformCommand from mcp server awslabsterraform_mcp_server
 ⋮
 ● Running ExecuteTerraformCommand with the param:
 ⋮  {
 ⋮    "arguments": {
 ⋮      "command": "init",
 ⋮      "working_directory": "/Users/sithimai/qcli/generated-iac"
 ⋮    },
 ⋮    "name": "ExecuteTerraformCommand"

Terraform MCP จะทำการตรวจสอบและเสนอข้อแนะนำ โดยจะเห็นได้ว่า mcp เจอปัญหาในส่วนของ route53.tf

Now I can see the issue clearly. The validation error shows that in your route53.tf file, line 40, you're using "Failure"
as the value for insufficient_data_health_status, but this parameter only accepts one of these three values: "Healthy",
"Unhealthy", or "LastKnownStatus".

Let me fix this for you:


🛠️  Using tool: fs_write
 ⋮
 ● Path: qcli/generated-iac/route53.tf

- 40    :   insufficient_data_health_status = "Failure"
+     40:   insufficient_data_health_status = "Unhealthy"

Perfect! 🎉 Your Terraform code is now valid. Here's a summary of what I found and fixed:

ขั้นตอนสุดท้ายคือการสรุปผล

## Validation Results

✅ Status: All validation checks passed successfully

🔧 Issue Fixed:
•	**File**: route53.tf (line 40)
•	**Problem**: Invalid value "Failure" for insufficient_data_health_status parameter
•	**Solution**: Changed to "Unhealthy" (one of the accepted values: "Healthy", "Unhealthy", or "LastKnownStatus")

## Your Terraform Project Structure
Your project includes these components:
•	**Infrastructure**: VPC, security groups, ALB, ECS
•	**Storage**: S3, RDS
•	**CDN**: CloudFront with ACM certificates
•	**DNS**: Route53 with health checks
•	**Security**: IAM roles and policies
•	**Configuration**: Variables and outputs properly defined

The configuration is now syntactically correct and ready for planning and deployment. You can proceed with terraform plan
to see what resources will be created.

หมายเหตุ: เราสามารถเขียนเพิ่มเติมให้ Amazon Q Developer CLI ตรวจสอบเบื้องต้นก่อนว่า แต่ละ service สามารถใช้งานใน region ที่ต้องการจะติดตั้งหรือไม่

Prompt

Check if this architecture can be deployed in ap-southeast-7, are all the required services available?

ถ้าต้องการ สามารถสั่งให้ MCP Terraform ทำการติดตั้ง solution นี้บน AWS ต่อได้

3.วิเคราะห์ราคา (awslabscost_analysis_mcp_server)

หลังจากที่ได้ Terraform code ในการ deploy solution นี้แล้ว ก่อน deploy เราอยากทราบว่าถ้า deploy ตามนี้ไป จะเสียค่าใช้จ่ายเท่าไหร่ เราสามารถใช้ MCP Cost Analysis เข้ามาช่วยตรงนี้ได้

Cost analysis จะมีหลายเครื่องมือด้วยกันในการตรวจสอบราคา เช่น get_pricing_from_web และ get_pricing_from_api ซึ่งในตัวอย่างจะใช้งาน get_pricing_from_api เพื่อทำการประเมิณราคาเบื้องต้น

Prompt

Use cost_analysis_mcp_server get_pricing_from_api to determine an estimate on how much this architecture will cost, save the report as cost.md file

ระบบก็จะทำการตรวจสอบราคาของ โปรเจคนี้ รวมไปถึงข้อแนะนำสำหรับการทำ cost optimization ซึ่งเราสามารถทำการ save เป็น report ในรูปแบบของ markdown ได้

4. รีวิว solution (awslabsaws_documentation_mcp_server)

จาก solution ที่มี เราอยากทราบว่า solution ที่ออกแบบมาดีเป็นไปตาม best practice แล้วหรือยัง มีจุดไหนที่สามารถเพิ่มเติมปรับปรุงได้อีก ในส่วนนี้สามารถใช้ MCP Documentation เข้าไปอ่าน AWS Well Architected Framwork เพื่อมารีวิว solution ได้

Prompt

Review the architecture based on AWS well architect framework using documentation mcp server, provide suggestion for improvements

ระบบก็จะทำการอ่าน document ในแต่ละหัวข้อของ Well Architected Framework แล้วสรุปให้ว่าควรปรับเปลี่ยนหรือเพิ่มเติมส่วนไหนบ้าง

Result

Now let me get specific details about each pillar to properly assess our architecture:

🛠️ Using tool: read_documentation from mcp server awslabsaws_documentation_mcp_server
⋮
● Running read_documentation with the param:
⋮ {
⋮ "arguments": {
⋮ "max_length": 2000,
⋮ "url": "https://docs.aws.amazon.com/wellarchitected/latest/framework/security.html“
⋮ },
⋮ "name": "read_documentation"
⋮ }

ยกตัวอย่าง(ส่วนหนึ่ง) Amazon Q Deverloper CLI เสนอให้ปรับปรุงในส่วนของ security pillar ดังนี้

Result

 ### 2. Security Pillar - ⚠️ Needs Enhancement
    Current Issues:
    ○    No WAF protection
    ○    Missing network segmentation details
    ○    No monitoring/logging shown
    Recommendations:
    Enhanced Security:
Add AWS WAF to CloudFront and ALB
Implement VPC Flow Logs
Add CloudTrail for API logging
Configure Security Groups with least privilege
Add AWS Shield Advanced for DDoS protection

ซึ่งจะเห็นว่าระบบแนะนำให้เพิ่ม WAF, CloudTrail และ service อื่นๆตาม best practice

5. ทำการรวบรวมข้อมูลออกมาเป็น report

มาถึงขั้นตอนนี้เราจะนำข้อมูลที่ได้มาทั้งหมดมาทำเป็น report เพื่อให้สะดวกต่อการอ่านหรือการแชร์ให้คนอื่น

โดยใน prompt ข้างล่างนี้จะมีการสั่งให้สร้าง diagram เพิ่มโดยอ้างอิงจากข้อแนะนำที่ทำไว้ในข้อ 4 เพื่อแสดงการเปรียบเทียบก่อนและหลัง, มีการระบุสไตล์และเนื้อหา ของ report ที่ต้องการ

Prompt

Create a html report that includes the architecture review and the cost analysis.
Also create the new diagram based on the recommendations, put previous and purposed diagram in the report for comparison.
Use CloudScape design as the template. The web page must look clean, professional and easy to read.
Here are the topics for the report.
Architecture overview ,
Key metrics, Infrastructure components,
Network configuration, cost analysis,
Cost breakdown,
Recommendations and conclusion

Result

ผลลัพธ์ที่ได้จะเป็น report ที่อยู่ในรูปแบบ file html ซึ่งเราสามารถ save ออกมาเป็น PDF ได้

หรือถ้าต้องการ report ในรูปแบบของการนำเสนอสามารถเขียน prompt เพิ่มเติมได้ดังนี้

Prompt

Read the report output at aws-web-app-architecture-analysis.html,
I want to create this as a powerpoint-style html report.
A4 landscape size.
Never crop the content ,If content is too long for one slide, split it across multiple slides.

Result

รูปแบบของรายงานที่ได้จะแสดงผลเป็นแนวนอนแทนแนวตั้ง แบ่งเป็นหน้าๆ เหมาะสำหรับการนำไปนำเสนอมากขึ้น

 Perfect! I've successfully converted the report into a PowerPoint-style HTML presentation with the following key features:
    ## ✅ PowerPoint-Style Presentation Features
    ### 1. Slide-Based Layout
    ○    10 slides total - each fitting within 100vh viewport
    ○    No content cropping - all information preserved across slides
    ○    Proper slide breaks with page-break-after for printing
    ○    Slide numbering (1/10, 2/10, etc.) in bottom right
    ### 2. Professional Slide Design
    ○    AWS CloudScape colors maintained throughout
    ○    Clean slide headers with titles and subtitles
    ○    Consistent spacing and typography
    ○    Professional card layouts for content organization

หมายเหตุ : เราสามารถระบุรายละเอียดและรุปแบบของ reportได้ ไม่ว่าจะเป็นหัวข้อ,โทนสี, ข้อมูลที่ต้องการ หรือ สไตล์ ในที่นี้จะใช้ดีไซน์ต้นแบบจาก Cloudscape

การทำรายงานในส่วนของ report นั้นสามารถนำวิธีนี้ไปประยุกต์ใช้ได้กับการใช้งานส่วนอื่นได้ เช่น ให้วิเคราะห์ข้อมูลจาก Trust Advisor แล้วสรุปเป็นรายงาน , วิเคราะห์ VPC flow log หรือแม้แต่ CloudTrail log เป็นต้น

สรุป

จากตัวอย่างข้างบนจะเห็นได้ว่า เราสามารถนำ MCP server หลายๆ server มาใช้งานร่วมกันเพื่อสร้างสิ่งที่เราต้องการได้ เช่นในกรณีที่ต้องทำรายงานแบบในตัวอย่างด้วยตัวเองทั้งหมด อาจจะใช้เวลาหลายชั่วโมงหรือหลายวัน แต่ด้วยความสามารถของ Amazon Q Developer CLI และ MCP server สามารถช่วยสร้างขึ้นหรือแก้ไขสิ่งที่เราต้องการได้ในเวลาอันสั้น ซึ่ง ณ ปัจจุบัน MCP server มีการใช้งานอย่างแพร่หลายรวมถึง AWS เองก็มี official MCP server ให้เลือกใช้งานได้งานตามความเหมาะสม เพื่อเข้ามาช่วยเพิ่มประสิทธิภาพในการทำงานได้