Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Amazon Bedrock Agents で入門・実践する MCP

Avatar for Keigo Ibaraki Keigo Ibaraki
April 26, 2025
560

Amazon Bedrock Agents で入門・実践する MCP

本資料は、Amazon Bedrock AgentsとMCP(Model Context Protocol)についての入門と実践方法を紹介する。MCPは生成AIに統一的に情報提供する標準プロトコルであり、Bedrock Agentsとの連携を容易にする。実践例として、AWSコスト分析を行う「Cost Explorer MCP」と、Terraform構成を可視化する「Diagram MCP」の2例が示され、環境構築から実行手順まで解説されている。MCPサーバー導入は容易であり、即座に実践が可能とまとめられている​

Avatar for Keigo Ibaraki

Keigo Ibaraki

April 26, 2025
Tweet

Transcript

  1. 茨木 啓瑚(いばらき けいご) • 所属 ◦ サイバーエージェント > AI 事業本部

    • 業務内容 ◦ 広告配信システムの構築 @oyasumi_pant s 4
  2. その前に AI Agent とは 8 ユーザーの入力を複数の小さなタスクに分割し タスクごと適切な処理を行うことで回答を生成させるアプローチ ユーザー LLM 今日の晩ご飯を考えてください。

    ユーザーの好みを探ろう。 今週食べたご飯とは被らない様にしよう。 家で食べるか、外で食べるか確認しないと。 https://pages.awscloud.com/rs/112-TZM-766/images/AWS-Black-Belt_2024_Amazon-Bedrock-Overview_v1.pdf
  3. Agent のメリットと課題 10 Agent (LLM) 検索 結果 検索 結果 ある検索ツール

    A ある検索ツール B クエリ 最終的な回答 ある検索ツール C 検索 結果 バラバラなので使いづらい... https://speakerdeck.com/minorun365/yasasiimcpru-men 様々なツールにアクセスできるが、実装方法がバラバラだった
  4. MCP -Model Context Protocol- とは 11 Agent (LLM) 検索 結果

    検索 結果 ある検索ツール A ある検索ツール B クエリ 最終的な回答 ある検索ツール C 検索 結果 https://zenn.dev/cloud_ace/articles/model-context-protocol MCP 呼び出し方が 統一され Agent へのデータ 提供が容易 に! 生成 AI に情報を渡しやすくするための標準化されたプロトコル
  5. MCP の構成要素 12 Host with MCP Client (Claude, IDEs, Tools)

    MCP Server A MCP Server B Local Data Source A Local Data Source B Remote Data Source C MCP Server C Local Computer Internet MCP Protocol MCP Protocol MCP Protocol Web APIs https://aws.amazon.com/jp/blogs/news/harness-the-power-of-mcp-servers-with-amazon-bedrock-agents/
  6. AWS の MCP Servers 13 https://github.com/awslabs/mcp • Core MCP Server

    • AWS Documentation MCP Server • Amazon Bedrock Knowledge Bases Retrieval MCP Server • AWS CDK MCP Server • Cost Analysis MCP Server • Amazon Nova Canvas MCP Server • AWS Diagram MCP Server • AWS Lambda MCP Server • AWS Terraform MCP Server • Use Cases for the Servers 様々なサーバー用意されており 継続的に追加もされている 本資料でも使う MCP Server
  7. 今回の構成図 18 Amazon Bedrock Inline Agent Cost Explorer MCP Perplexity

    MCP Local Computer Internet MCP Protocol MCP Protocol ユーザー AWS Data Source AWS Cloud コスト情報 の取得 分析結果のまとめ https://aws.amazon.com/jp/blogs/news/harness-the-power-of-mcp-servers-with-amazon-bedrock-agents/
  8. 用意するもの 19 1. AWS 関連の準備 • AWS アカウント • Amazon

    Bedrock の基礎知識 • AWS CLI のインストールと認証情報の設定 • AWS CDK CLI のインストール • IAM 認証情報の設定 AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY を使用 2. ソフトウェアとツール • Python:バージョン 3.11 以降 • Docker:MCP サーバーをローカルで実行するために Docker をインストールし、デーモンを起動 3. モデルと API アクセス • Bedrock で Anthropic のClaude 3.5 Sonnet v2 モデルへのアクセス • Perplexity API キーの取得 https://aws.amazon.com/jp/blogs/news/harness-the-power-of-mcp-servers-with-amazon-bedrock-agents/
  9. 用意するもの 20 4. GitHub Repository https://aws.amazon.com/jp/blogs/news/harness-the-power-of-mcp-servers-with-amazon-bedrock-agents/ Bedrock の Inline Agent

    を提供する Local で起動する MCP Server を提供する https://github.com/awslabs/amazon-bedrock-agent-samples https://github.com/aws-samples/sample-cloud-spend-mcp-serve r
  10. 実行ログ ① 21 Processing request of type ListToolsRequest Connected to

    server with tools:['get_bedrock_daily_usage_stats', 'get_bedrock_hourly_usage_stats', 'get_ec2_spend_last_day', 'get_detailed_breakdown_by_day'] Processing request of type ListToolsRequest Processing request of type ListToolsRequest Perplexity MCP Server running on stdio with Ask, Research, and Reason tools Connected to server with tools:['perplexity_ask', 'perplexity_research', 'perplexity_reason'] SessionId: 2d1a194f-2b06-4d1c-94c9-954bad13a81c 2025-04-26 12:51:01,049 - botocore.credentials - INFO - Found credentials in shared credentials file: ~/.aws/credentials Input Tokens: 1711 Output Tokens: 157 Thought: Let me break this down into two parts: 1. First, I'll research about Amazon Bedrock using Perplexity 2. Then, I'll get the cost breakdown for the last 30 days and create a visualization Let me start with getting information about Amazon Bedrock. MCP Server への接続
  11. 実行ログ ② 22 ------------------------------------------------------------- ---- Date: 2025-04-23 ======================================== == Region:

    NoRegion ---------------------------------------- +------------------------------------+------+ | Service | Cost | +------------------------------------+------+ | Amazon Glacier | -0.0 | | AmazonCloudWatch | -0.0 | | Amazon Simple Notification Service | -0.0 | | Amazon Simple Queue Service | -0.0 | | AWS Glue | -0.0 | +------------------------------------+------+ ... and 6 more services totaling -0.09 USD Region: ap-northeast-1 ---------------------------------------- +-------------------------------+------+ | Service | Cost | +-------------------------------+------+ | Amazon Virtual Private Cloud | 0.24 | | Amazon GuardDuty | 0.02 | | AWS Key Management Service | 0.0 | | Amazon Simple Storage Service | 0.0 | | AWS Secrets Manager | 0.0 | +-------------------------------+------+ ... and 6 more services totaling 0.00 USD Region: ap-northeast-2 ---------------------------------------- +-----------------------------+------+ | Service | Cost | +-----------------------------+------+ | Amazon GuardDuty | 0.01 | | AWS Key Management Service | 0.0 | | AWS Secrets Manager | 0.0 | | AWS Glue | 0.0 | | Amazon Simple Queue Service | 0.0 | +-----------------------------+------+ ... and 3 more services totaling 0.00 USD Region: ap-northeast-3 ---------------------------------------- +-----------------------------+------+ | Service | Cost | +-----------------------------+------+ | Amazon GuardDuty | 0.01 | | AWS Key Management Service | 0.0 | | AWS Secrets Manager | 0.0 | | AWS Glue | 0.0 | | Amazon Simple Queue Service | 0.0 | +-----------------------------+------+ ... and 3 more services totaling 0.00 USD Daily のコスト状況が分析される
  12. 結果 23 Files saved in output directory Input Tokens: 76867

    Output Tokens: 209 Amazon Bedrock is a fully managed service that provides access to foundation models (FMs) from leading AI companies through a single API. It enables organizations to build and scale generative AI applications with features like private customization, security controls, and seamless AWS integration. Based on the cost analysis of the last 30 days, your highest AWS service costs were: 1. Amazon RDS (Relational Database Service): ~$5.79 2. EC2 (Elastic Compute Cloud): ~$3.05 3. Amazon VPC (Virtual Private Cloud): ~$2.16 4. Elastic Load Balancing: ~$0.58 5. Amazon GuardDuty: ~$0.48 I've created a bar graph visualizing these costs for better understanding. The majority of your spending is concentrated in database and compute services, with security and networking services making up a smaller portion of the costs. Files saved in output directory Bedrock の概要 30日間のコスト状況
  13. Diagram MCP の例 27 database module ecr module network module

    ecs module Terraform Diagram MCP MCP Protocol ユーザー Terraform 実装 構成図の Output Local Computer
  14. Bedrock Agent で詰まる... 28 Returns: Dictionary with the path to

    the generated diagram and status information ' at 'actionGroups.1.member.functionSchema.functions.1.member.description' failed to satisfy constraint: Member must have length less than or equal to 1200; Value 'Get example code for different types of diagrams. AWS Bedrock Agents (もしくはそれに準拠したMCPサーバなど) で、Function定義(スキーマ)に渡した description フィールドの文字数が制限(最大1200文字以内)を超えた...
  15. 参考 35 • Amazon Bedrock Overview • やさしい MCP 入門

    • Model Context Protocol(MCP)とは?生成 AI の可能性を広げる新しい標準 • Amazon Bedrock Agents で MCP サーバーを活用する • GitHub awslabs / mcp