Skip to main content
Glama
r3-yamauchi

Amazon Bedrock Knowledge Base MCP Server

by r3-yamauchi

create_bedrock_kb_role

Create an IAM service role for Amazon Bedrock Knowledge Base with trust policies restricted to your AWS account and region.

Instructions

Amazon Bedrock Knowledge Base用のサービスロールを作成します。

このツールは、Bedrock Knowledge Baseが使用するIAMロールを作成します。 ロールには以下の信頼ポリシーが設定されます:

  • Service: bedrock.amazonaws.com

  • Condition: aws:SourceAccountとaws:SourceArnによる制限

    • aws:SourceAccount: 現在のAWSアカウントID

    • aws:SourceArn: arn:aws:bedrock:[REGION]:[ACCOUNT_ID]:knowledge-base/*

Args: role_name: 作成するIAMロールの名前(必須) 例: "BedrockKnowledgeBaseRole" 注意: ロール名はAWSアカウント内で一意である必要があります region: Knowledge Baseを作成する先のリージョン(デフォルト: "us-east-1") 例: "us-east-1", "ap-northeast-1" 注意: 信頼ポリシーのaws:SourceArnにこのリージョンが使用されます このリージョンは、Knowledge Baseを作成する際に指定するリージョンと一致させる必要があります description: ロールの説明(デフォルト: "Bedrock Knowledge Base access") max_session_duration: 最大セッション時間(秒)(デフォルト: 3600秒 = 1時間) 範囲: 3600秒(1時間)から43200秒(12時間)まで

Returns: IAMRoleCreateResponseDict: ロール作成結果 - role_name: 作成されたロール名 - role_arn: ロールのARN(arn:aws:iam::ACCOUNT_ID:role/service-role/ROLE_NAME形式) - path: ロールのパス(/service-role/) - status: 作成ステータス("created")

Raises: ValueError: role_nameが空の場合、またはmax_session_durationが無効な範囲の場合 ClientError: AWS API呼び出しが失敗した場合 例: ロール名が既に使用されている、権限がないなど

Example: # 基本的なロール作成(デフォルトリージョン) create_bedrock_kb_role("BedrockKnowledgeBaseRole")

# 特定のリージョン用のロール作成
create_bedrock_kb_role("BedrockKnowledgeBaseRole", region="ap-northeast-1")

# カスタム説明とセッション時間を指定
create_bedrock_kb_role(
    "MyBedrockRole",
    description="Custom Bedrock KB role",
    max_session_duration=7200
)

Note: - ロールは /service-role/ パスに作成されます - 信頼ポリシーには、現在のAWSアカウントIDとリージョンが自動的に設定されます - ロール作成後、適切な権限ポリシーをアタッチする必要があります - ロール名が既に使用されている場合、EntityAlreadyExistsエラーが発生します

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
role_nameYes
regionNous-east-1
descriptionNoBedrock Knowledge Base access
max_session_durationNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
statusYes
role_arnYes
role_nameYes

Implementation Reference

  • The actual implementation of the bedrock_client.create_bedrock_kb_role method, which handles AWS API calls to create the IAM role.
    def create_bedrock_kb_role(
        self,
        role_name: str,
        region: str = "us-east-1",
        description: str = "Bedrock Knowledge Base access",
        max_session_duration: int = 3600,
    ) -> IAMRoleCreateResponseDict:
        """
        Amazon Bedrock Knowledge Base用のサービスロールを作成します。
        
        このメソッドは、Bedrock Knowledge Baseが使用するIAMロールを作成します。
        ロールには以下の信頼ポリシーが設定されます:
        - Service: bedrock.amazonaws.com
        - Condition: aws:SourceAccountとaws:SourceArnによる制限
        
        Args:
            role_name: 作成するIAMロールの名前(必須)
                例: "BedrockKnowledgeBaseRole"
            region: Knowledge Baseを作成する先のリージョン(デフォルト: "us-east-1")
                    このリージョンは、Knowledge Baseを作成する際に指定するリージョンと一致させる必要があります
            description: ロールの説明(デフォルト: "Bedrock Knowledge Base access")
            max_session_duration: 最大セッション時間(秒)(デフォルト: 3600秒 = 1時間)
        
        Returns:
            IAMRoleCreateResponseDict: ロール作成結果
                - role_name: 作成されたロール名
                - role_arn: ロールのARN(arn:aws:iam::ACCOUNT_ID:role/service-role/ROLE_NAME形式)
                - path: ロールのパス(/service-role/)
                - status: 作成ステータス("created")
        
        Raises:
            ClientError: AWS API呼び出しが失敗した場合
                例: ロール名が既に使用されている、権限がないなど
        
        Note:
            - ロール名はAWSアカウント内で一意である必要があります
            - ロールは /service-role/ パスに作成されます
            - 信頼ポリシーには、現在のAWSアカウントIDとリージョンが自動的に設定されます
        """
        import json
        from bedrock_kb_mcp_server.utils import get_aws_account_id
        
        try:
            # リージョンを使用(既定値はus-east-1)
            role_region = region
            
            # AWSアカウントIDを取得
            account_id = get_aws_account_id()
            
            # 信頼ポリシー(Trust Policy)を構築
            # Bedrockサービスがこのロールを引き受けることを許可します
            trust_policy = {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": "bedrock.amazonaws.com"
                        },
                        "Action": "sts:AssumeRole",
                        "Condition": {
                            "StringEquals": {
                                "aws:SourceAccount": account_id
                            },
                            "ArnLike": {
                                "aws:SourceArn": f"arn:aws:bedrock:{role_region}:{account_id}:knowledge-base/*"
                            }
  • The MCP tool wrapper function create_bedrock_kb_role that exposes the tool to the MCP client.
    @mcp.tool()  # MCPツールとして公開
    @handle_errors  # エラーハンドリングデコレータを適用
    def create_bedrock_kb_role(
        role_name: str,
        region: str = "us-east-1",
        description: str = "Bedrock Knowledge Base access",
        max_session_duration: int = 3600,
    ) -> IAMRoleCreateResponseDict:
        """
        Amazon Bedrock Knowledge Base用のサービスロールを作成します。
        
        このツールは、Bedrock Knowledge Baseが使用するIAMロールを作成します。
        ロールには以下の信頼ポリシーが設定されます:
        - Service: bedrock.amazonaws.com
        - Condition: aws:SourceAccountとaws:SourceArnによる制限
          - aws:SourceAccount: 現在のAWSアカウントID
          - aws:SourceArn: arn:aws:bedrock:[REGION]:[ACCOUNT_ID]:knowledge-base/*
    
        Args:
            role_name: 作成するIAMロールの名前(必須)
                例: "BedrockKnowledgeBaseRole"
                注意: ロール名はAWSアカウント内で一意である必要があります
            region: Knowledge Baseを作成する先のリージョン(デフォルト: "us-east-1")
                例: "us-east-1", "ap-northeast-1"
                注意: 信頼ポリシーのaws:SourceArnにこのリージョンが使用されます
                このリージョンは、Knowledge Baseを作成する際に指定するリージョンと一致させる必要があります
            description: ロールの説明(デフォルト: "Bedrock Knowledge Base access")
            max_session_duration: 最大セッション時間(秒)(デフォルト: 3600秒 = 1時間)
                範囲: 3600秒(1時間)から43200秒(12時間)まで
    
        Returns:
            IAMRoleCreateResponseDict: ロール作成結果
                - role_name: 作成されたロール名
                - role_arn: ロールのARN(arn:aws:iam::ACCOUNT_ID:role/service-role/ROLE_NAME形式)
                - path: ロールのパス(/service-role/)
                - status: 作成ステータス("created")
        
        Raises:
            ValueError: role_nameが空の場合、またはmax_session_durationが無効な範囲の場合
            ClientError: AWS API呼び出しが失敗した場合
                例: ロール名が既に使用されている、権限がないなど
        
        Example:
            # 基本的なロール作成(デフォルトリージョン)
            create_bedrock_kb_role("BedrockKnowledgeBaseRole")
            
            # 特定のリージョン用のロール作成
            create_bedrock_kb_role("BedrockKnowledgeBaseRole", region="ap-northeast-1")
            
            # カスタム説明とセッション時間を指定
            create_bedrock_kb_role(
                "MyBedrockRole",
                description="Custom Bedrock KB role",
                max_session_duration=7200
            )
        
        Note:
            - ロールは /service-role/ パスに作成されます
            - 信頼ポリシーには、現在のAWSアカウントIDとリージョンが自動的に設定されます
            - ロール作成後、適切な権限ポリシーをアタッチする必要があります
            - ロール名が既に使用されている場合、EntityAlreadyExistsエラーが発生します
        """
        # 入力値のバリデーション(共通関数を使用)
        role_name = validate_required_string(role_name, "role_name")
        
        # ロール名の基本的なバリデーション
        # IAMロール名のルールに従う必要があります
        if len(role_name) < 1 or len(role_name) > 64:
            raise ValueError("role_name must be between 1 and 64 characters")
        
        # ロール名は英数字、ハイフン、アンダースコア、ピリオドのみ使用可能
        import re
        if not re.match(r'^[\w+=,.@-]+$', role_name):
            raise ValueError(
                "role_name must contain only alphanumeric characters, hyphens, "
                "underscores, periods, plus signs, equals signs, commas, and @ symbols"
            )
        
        # max_session_durationのバリデーション
        # IAMの制限: 3600秒(1時間)から43200秒(12時間)まで
        if max_session_duration < 3600 or max_session_duration > 43200:
            raise ValueError("max_session_duration must be between 3600 and 43200 seconds")
        
        # リージョンを正規化(前後の空白を削除、空文字列の場合はus-east-1を使用)
        region_cleaned = region.strip() if region else "us-east-1"
        
        # BedrockクライアントからIAMロールを作成
        result = bedrock_client.create_bedrock_kb_role(
            role_name=role_name,  # 前後の空白は既に削除済み
            region=region_cleaned,  # 既定値はus-east-1
            description=description,
            max_session_duration=max_session_duration,
        )
        return result
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It does an excellent job describing what gets created (IAM role with specific trust policy), constraints (role name must be unique, region must match Knowledge Base region), error conditions (ValueError, ClientError), and post-creation requirements (attaching permission policies). The only minor gap is lack of explicit rate limit or authentication requirement information.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (Args, Returns, Raises, Example, Note) and front-loaded purpose statement. While comprehensive, some sections could be slightly more concise (e.g., the Example section has multiple similar examples). Every sentence adds value, but there's minor redundancy in the parameter explanations.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of creating an AWS IAM role with specific trust policies, no annotations, and 0% schema coverage, the description provides complete context. It explains the tool's purpose, all parameters, return values (though an output schema exists), error conditions, usage examples, and important implementation notes. Nothing essential appears missing for this type of infrastructure creation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description fully compensates by providing detailed semantic information for all 4 parameters: purpose, examples, constraints, and important notes. Each parameter gets specific guidance beyond what the bare schema provides, including default values, valid ranges, and usage implications.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('creates an IAM role') and resource ('for Amazon Bedrock Knowledge Base'), distinguishing it from sibling tools like create_knowledge_base or create_s3_bucket. It explicitly mentions the trust policy configuration, which further clarifies its specialized purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool (to create a service role for Bedrock Knowledge Base) and mentions prerequisites like attaching appropriate permission policies afterward. However, it doesn't explicitly state when NOT to use it or name specific alternatives among the sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/r3-yamauchi/bedrock-kb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server