7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[ARC306-R] re:Invent 2025で学んだKiro CLI + MCPによるAWS図の自動生成(入門編)

Last updated at Posted at 2025-12-05

はじめに

AWS re:Invent 2025のワークショップ「[ARC306-R]Architecture diagrams with generative AI: Leveraging AI agents」に参加して、生成AIを使ったアーキテクチャ図の自動生成を体験しました。

この記事では、Kiro CLIとModel Context Protocol (MCP) Serverを使って、以下を実践します。

  • テキストプロンプトからAWSアーキテクチャ図を自動生成
  • 既存の図を分析して技術ドキュメントを作成
  • 画像をMermaid形式のシーケンス図に変換
  • 最新のAWSドキュメントを参照しながら分析

今回はKiro CLIの基本的な使い方に焦点を当てます。
カスタムエージェントを使った高度なワークフローについては、別の記事などでご紹介できればと思います。

環境構築

必要なもの

  • macOS / Linux / Windows
  • Python 3.10以上
  • AWS Builder ID
  • Kiro CLI
  • Graphviz

1. Kiro CLIのインストール

curl -fsSL https://cli.kiro.dev/install | bash

# または公式サイトからダウンロード
# https://kiro.dev

2. AWS Builder IDでログイン

kiro-cli login --use-device-flow

ブラウザが開くので、AWS Builder IDでサインインします(無料アカウントでOK)。

3. Pythonとuvのインストール

# uvのインストール(Python環境管理ツール)
curl -LsSf https://astral.sh/uv/install.sh | sh

# または
brew install uv

4. Graphvizのインストール

# macOS
brew install graphviz

# Ubuntu/Debian
sudo apt-get install graphviz

# 確認
dot -V

MCP Serverの設定

Kiro CLIでMCPサーバーを使えるようにします。

プロジェクトディレクトリの作成

mkdir -p my-diagram-project/.kiro/settings
cd my-diagram-project

mcp.jsonの作成

.kiro/settings/mcp.jsonを作成します。

{
  "mcpServers": {
    "aws-knowledge": {
      "command": "uvx",
      "args": ["awslabs.aws-documentation-mcp-server@latest"],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "disabled": false
    },
    "aws-diagrams": {
      "command": "uvx",
      "args": ["awslabs.aws-diagram-mcp-server"],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "disabled": false
    }
  }
}

注意: パッケージ名は awslabs.aws-diagram-mcp-server です。ハイフンとドットの位置に注意してください。

MCPサーバーの説明

サーバー名 用途 ドキュメント
aws-knowledge AWSドキュメントの検索 aws-documentation-mcp-server
aws-diagrams Python Diagramsで図を生成 aws-diagram-mcp-server

実践:AWS図を生成してみる

Kiro CLIを起動

kiro-cli chat

起動時に以下のようにMCPサーバーがロードされることを確認します。

✓ aws-diagrams loaded in 1.93 s
✓ aws-knowledge loaded in 2.55 s

ツールの確認

/tools コマンドで利用可能なツールを確認します。

/tools

以下のようなツールが表示されればOKです。

aws-diagrams (MCP)
- generate_diagram                   not trusted
- get_diagram_examples               not trusted
- list_icons                         not trusted

図を生成する

プロンプトを入力:

Create an AWS Cloud architecture diagram showing a serverless API architecture with:
1. User - The client making requests
2. Amazon API Gateway - The API management layer
3. AWS Lambda - The serverless compute layer
4. Amazon DynamoDB - For read operations
5. Amazon S3 - For write operations

Use the generate_diagram tool to create and save the diagram as serverless-api.png

ツールの実行許可を求められたら y で承認します。数秒で serverless-api.png が生成されます!

プレビュー画面例
image.png

実践:既存の図を分析する

先ほど生成した serverless-api.png を分析してみましょう。

kiro-cli chat

プロンプトを入力:

Analyze the architecture diagram in generated-diagrams/serverless-api.png
Use the aws-knowledge tools to research each AWS service.
Save the analysis as analysis-report.md

マークダウン形式の詳細な分析レポートが生成されます。

プレビュー画面例(抜粋)
image.png

実践:画像をMermaid図に変換

kiro-cli chat

プロンプト:

Convert the diagram in generated-diagrams/serverless-api.png into a Mermaid formatted sequence diagram.
Save it as sequence-diagram.md

プレビュー画面例(抜粋)
image.png

Tips & Tricks

ツールの自動承認

頻繁に使うツールは mcp.json で自動承認できます。

{
  "mcpServers": {
    "aws-diagrams": {
      "command": "uvx",
      "args": ["awslabs.aws-diagram-mcp-server"],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "autoApprove": ["generate_diagram", "list_icons"],
      "disabled": false
    }
  }
}

トラブルシューティング

Graphvizがインストールされていない

dot -V
# command not found の場合
brew install graphviz  # macOS

MCPサーバーはロードされるがツールが表示されない

/mcp でサーバーがロードされているのに /tools にツールが表示されない場合:

  1. Kiro CLIを再起動してみる
  2. mcp.json のパッケージ名が正しいか確認(awslabs.aws-diagram-mcp-server
  3. uvxのフルパスを指定してみる:
{
  "mcpServers": {
    "aws-diagrams": {
      "command": "/Users/YOUR_USERNAME/.local/bin/uvx",
      "args": ["awslabs.aws-diagram-mcp-server"],
      "env": {
        "FASTMCP_LOG_LEVEL": "ERROR"
      },
      "disabled": false
    }
  }
}

まとめ

Kiro CLI + MCP Serverを使うことで、テキストプロンプトからAWSアーキテクチャ図を生成し、その図を分析してドキュメント化、さらにMermaid形式への変換まで、すべてチャットベースで完結できました。

今回はKiro CLIの基本的な使い方をご紹介しましたが、実はカスタムエージェントを作成することで、より高度なワークフローを構築できます。例えば、

  • 特定のプロジェクト向けにカスタマイズされた図生成ルール
  • 複数のMCPサーバーを組み合わせた分析パイプライン
  • CI/CDに組み込んだドキュメント自動生成

ぜひお試しください!

参考リンク

7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?