Skip to main content
Glama
r3-yamauchi

Amazon Bedrock Knowledge Base MCP Server

by r3-yamauchi

create_knowledge_base

Create a knowledge base in Amazon Bedrock to store and organize documents for retrieval-augmented generation (RAG), supporting vector search, custom parsing, and chunking strategies.

Instructions

新しいAmazon Bedrock Knowledge Baseを作成します。

Args: name: Knowledge Baseの名前(1-100文字) description: Knowledge Baseの説明(1文字以上) role_arn: Knowledge Baseが使用するIAMロールのARN - 完全な形式: "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME" - アカウントIDなし: "arn:aws:iam::role/ROLE_NAME" または "role/ROLE_NAME"(自動補完) storage_type: ストレージタイプ - 'S3': 標準的なS3ストレージ(デフォルト) - 'S3_VECTORS': S3 Vectorsを使用したベクトル検索対応ストレージ bucket_arn: ドキュメントを保存するS3バケットのARNまたはS3 URI - ARN形式: "arn:aws:s3:::BUCKET_NAME" - URI形式: "s3://BUCKET_NAME" または "s3://BUCKET_NAME/path" S3_VECTORSの場合はベクトルバケットARNまたはURIを指定 region: Knowledge Baseを作成する先のリージョン(デフォルト: "us-east-1") 例: "us-east-1", "ap-northeast-1" 注意: Knowledge Baseのリージョンは作成時に決定され、後から変更できません embedding_model_arn: 埋め込みモデルのARN(S3_VECTORSタイプの場合必須) 形式: "arn:aws:bedrock:REGION::foundation-model/MODEL_ID"

    サポートされている埋め込みモデル:
    - Amazon Titan Embeddings G1 - Text:
      "arn:aws:bedrock:REGION::foundation-model/amazon.titan-embed-text-v1"
      (ベクトル次元数: 1536、タイプ: Floating-point)
    
    - Amazon Titan Text Embeddings V2:
      "arn:aws:bedrock:REGION::foundation-model/amazon.titan-embed-text-v2:0"
      (ベクトル次元数: 256, 512, 1024、タイプ: Floating-point, binary)
    
    - Cohere Embed Multilingual:
      "arn:aws:bedrock:REGION::foundation-model/cohere.embed-multilingual-v3"
      (ベクトル次元数: 1024、タイプ: Floating-point, binary)
    
    - Amazon Nova Multimodal Embeddings v1:
      "arn:aws:bedrock:REGION::foundation-model/amazon.nova-2-multimodal-embeddings-v1:0"
      (ベクトル次元数: 1024、タイプ: Floating-point)
      (マルチモーダル対応: テキスト、画像、動画、音声を処理可能)
      注意: マルチモーダルコンテンツを処理する場合は、supplementalDataStorageConfiguration
      でマルチモーダルストレージ先を指定する必要があります
    
    例: "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
    注意: リージョンは実際に使用するリージョンに置き換えてください

パーシング設定(オプション):
parsing_strategy: パーシング戦略
    - 'BEDROCK_FOUNDATION_MODEL': Foundation Modelを使用したパーシング
      (マルチモーダルデータ(画像、表、グラフなど)を処理可能、プロンプトカスタマイズ可能)
    - 'BEDROCK_DATA_AUTOMATION': Bedrock Data Automationを使用したパーシング
      (マルチモーダルデータを処理可能、完全マネージド、追加プロンプト不要)
    注意: 指定しない場合はデフォルトパーサーが使用されます(テキストのみ、無料)
parsing_model_arn: Foundation ModelのARN(parsing_strategy='BEDROCK_FOUNDATION_MODEL'の場合必須)
    例: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0"
    サポートされているモデル: Claude 3 Sonnet, Claude 3 Opus, Claude 3 Haikuなど
parsing_modality: マルチモーダル設定
    - 'MULTIMODAL': テキストと画像の両方を処理(オプション)
parsing_prompt_text: パーシングプロンプトのテキスト(オプション)
    Foundation Modelにドキュメントの解釈方法を指示するテキスト
    例: "Extract all text, tables, and figures from this document."

チャンキング設定(オプション):
chunking_strategy: チャンキング戦略
    - 'FIXED_SIZE': 固定サイズのチャンクに分割(推奨: max_tokens=1000, overlap_percentage=20)
    - 'HIERARCHICAL': 階層的なチャンクに分割(大きなチャンクと小さなチャンクの2層)
    - 'SEMANTIC': セマンティックなチャンクに分割(NLPを使用して類似コンテンツでグループ化)
    - 'NONE': チャンクに分割しない(各ファイルが1つのチャンクとして扱われる)
    注意: 指定しない場合はデフォルトのチャンキングが使用されます
chunking_max_tokens: 最大トークン数(chunking_strategy='FIXED_SIZE'または'SEMANTIC'の場合に使用)
    - FIXED_SIZE: 1以上(推奨: 500-2000)
    - SEMANTIC: 1以上(推奨: 1000-3000)
chunking_overlap_percentage: オーバーラップ率(chunking_strategy='FIXED_SIZE'の場合に使用)
    範囲: 1-99(推奨: 10-30)
    隣接するチャンク間で重複するトークンの割合
chunking_overlap_tokens: オーバーラップトークン数(chunking_strategy='HIERARCHICAL'の場合に使用)
    階層チャンキングで使用する重複トークン数
chunking_buffer_size: バッファサイズ(chunking_strategy='SEMANTIC'の場合に使用)
    範囲: 0-1(推奨: 1)
    文を比較する際の移動コンテキストウィンドウのサイズ
chunking_breakpoint_threshold: ブレークポイントのパーセンタイル閾値(chunking_strategy='SEMANTIC'の場合に使用)
    範囲: 50-99(推奨: 80-95)
    チャンクを分割するための類似度閾値(低いほど多くのチャンクが作成される)

Returns: KnowledgeBaseResponseDict: Knowledge Baseの作成結果 - knowledge_base_id: 作成されたKnowledge BaseのID - status: Knowledge Baseのステータス('CREATING', 'ACTIVE', 'FAILED'など) - arn: Knowledge BaseのARN(オプション)

Raises: ValueError: 入力値が無効な場合(バリデーションエラー) - storage_typeが無効な値の場合 - S3_VECTORSタイプでembedding_model_arnが指定されていない場合 - parsing_strategy='BEDROCK_FOUNDATION_MODEL'でparsing_model_arnが指定されていない場合 - ARN形式が無効な場合

Examples: # 基本的なKnowledge Baseの作成(デフォルト設定) create_knowledge_base( name="My Knowledge Base", description="Example KB", role_arn="arn:aws:iam::123456789012:role/BedrockKBRole", storage_type="S3", bucket_arn="s3://my-bucket" # S3 URI形式も使用可能 )

# S3 Vectorsを使用したKnowledge Baseの作成
create_knowledge_base(
    name="Vector KB",
    description="Vector search enabled KB",
    role_arn="role/BedrockKBRole",  # アカウントIDなし形式も使用可能(自動補完)
    storage_type="S3_VECTORS",
    bucket_arn="s3://vector-bucket",  # S3 URI形式も使用可能
    embedding_model_arn="arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
)

# カスタムパーシングとチャンキング設定を使用
create_knowledge_base(
    name="Custom KB",
    description="KB with custom parsing and chunking",
    role_arn="arn:aws:iam::123456789012:role/BedrockKBRole",
    storage_type="S3",
    bucket_arn="arn:aws:s3:::my-bucket",
    parsing_strategy="BEDROCK_FOUNDATION_MODEL",
    parsing_model_arn="arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0",
    parsing_modality="MULTIMODAL",
    chunking_strategy="FIXED_SIZE",
    chunking_max_tokens=1000,
    chunking_overlap_percentage=20
)

# Amazon Nova Multimodal Embeddings v1を使用したマルチモーダルKnowledge Base
create_knowledge_base(
    name="Multimodal KB",
    description="KB with Nova Multimodal Embeddings",
    role_arn="arn:aws:iam::123456789012:role/BedrockKBRole",
    storage_type="S3_VECTORS",
    bucket_arn="arn:aws:s3:::vector-bucket",
    embedding_model_arn="arn:aws:bedrock:us-east-1::foundation-model/amazon.nova-2-multimodal-embeddings-v1:0",
    multimodal_storage_s3_uri="s3://multimodal-storage-bucket/"
)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
descriptionYes
role_arnYes
storage_typeNoS3
bucket_arnNo
embedding_model_arnNo
regionNous-east-1
parsing_strategyNo
parsing_model_arnNo
parsing_modalityNo
parsing_prompt_textNo
chunking_strategyNo
chunking_max_tokensNo
chunking_overlap_percentageNo
chunking_overlap_tokensNo
chunking_buffer_sizeNo
chunking_breakpoint_thresholdNo
multimodal_storage_s3_uriNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
arnYes
statusYes
knowledge_base_idYes

Implementation Reference

  • The actual implementation of the create_knowledge_base tool, which interfaces with the AWS Bedrock Agent API.
    def create_knowledge_base(
        self,
        name: str,
        description: str,
        role_arn: str,
        storage_configuration: Dict[str, Any],
        knowledge_base_configuration: Optional[Dict[str, Any]] = None,
        vector_ingestion_configuration: Optional[Dict[str, Any]] = None,
    ) -> KnowledgeBaseResponseDict:
        """
        新しいKnowledge Baseを作成します。
        
        Args:
            name: Knowledge Baseの名前
            description: Knowledge Baseの説明
            role_arn: Knowledge Baseが使用するIAMロールのARN
            storage_configuration: ストレージ設定の辞書
                - type: ストレージタイプ("S3" または "S3_VECTORS")
                - s3Configuration (S3の場合): S3設定
                    - bucketArn: S3バケットARN
                - s3VectorsConfiguration (S3_VECTORSの場合): S3 Vectors設定
                    - vectorBucketArn: ベクトルを保存するS3バケットのARN
                    - indexName (オプション): ベクトルインデックスの名前
                    - indexArn (オプション): ベクトルインデックスのARN
            knowledge_base_configuration: Knowledge Base設定の辞書(S3_VECTORSの場合必須)
                - type: "VECTOR"を指定
                - vectorKnowledgeBaseConfiguration: ベクトル設定
                    - embeddingModelArn: 埋め込みモデルのARN
            vector_ingestion_configuration: ベクトル取り込み設定の辞書(オプション)
                - parsingConfiguration: パーシング設定(オプション)
                - chunkingConfiguration: チャンキング設定(オプション)
        
        Returns:
            KnowledgeBaseResponseDict: Knowledge Baseの作成結果
                - knowledge_base_id: 作成されたKnowledge BaseのID
                - status: Knowledge Baseのステータス
                - arn: Knowledge BaseのARN(オプション)
        
        Raises:
            ClientError: AWS API呼び出しが失敗した場合
        """
        try:
            # API呼び出しパラメータを構築
            # boto3のcreate_knowledge_baseメソッドに渡すパラメータを辞書形式で構築します
            api_params = {
                "name": name,  # Knowledge Baseの名前
                "description": description,  # Knowledge Baseの説明
                "roleArn": role_arn,  # IAMロールのARN(Knowledge BaseがAWSサービスにアクセスするために使用)
                "storageConfiguration": storage_configuration,  # ストレージ設定(S3またはS3_VECTORS)
            }
            
            # Knowledge Base設定が指定されている場合は追加
            # S3_VECTORSタイプの場合、knowledgeBaseConfigurationが必須です
            # この設定には、埋め込みモデルのARNが含まれます
            if knowledge_base_configuration:
                api_params["knowledgeBaseConfiguration"] = knowledge_base_configuration
            
            # ベクトル取り込み設定が指定されている場合は追加
            # パーシング設定やチャンキング設定を含むことができます
            if vector_ingestion_configuration:
                api_params["vectorIngestionConfiguration"] = vector_ingestion_configuration
            
            # AWS Bedrock APIを呼び出してKnowledge Baseを作成
            # このAPI呼び出しは非同期で実行され、Knowledge Baseの作成が開始されます
            # 作成が完了するまでには時間がかかる場合があります(ステータスで確認可能)
            response = self.bedrock_agent.create_knowledge_base(**api_params)
            
            # 作成成功をログに記録
            # Knowledge BaseのIDをログに記録します(機密情報は自動的にマスクされます)
            logger.info(f"Created knowledge base: {response['knowledgeBaseId']}")
            
            # レスポンスを整形して返す
            # AWS APIのレスポンスから必要な情報を抽出し、統一された形式で返します
            # knowledgeBaseArnはオプションのため、存在しない場合は空文字列を返します
            return {
                "knowledge_base_id": response["knowledgeBaseId"],  # 作成されたKnowledge BaseのID
                "status": response["knowledgeBaseStatus"],  # Knowledge Baseのステータス(通常は"CREATING")
                "arn": response.get("knowledgeBaseArn", ""),  # Knowledge BaseのARN(オプション)
            }
        except ClientError as e:
            # エラーをログに記録して再発生
            # AWS API呼び出しでエラーが発生した場合、エラー情報をログに記録し、
            # エラーハンドリングデコレータ(handle_errors)が適切に処理できるように再発生させます
            logger.error(f"Error creating knowledge base: {e}")
            raise
  • The MCP tool handler function in main.py, which serves as the entry point for the "create_knowledge_base" tool request. It prepares arguments and calls the BedrockClient implementation.
    def create_knowledge_base(
        name: str,
        description: str,
        role_arn: str,
        storage_type: str = "S3",
        bucket_arn: str = "",
        embedding_model_arn: str = "",
        region: str = "us-east-1",
        # パーシング設定(オプション)
        parsing_strategy: str = "",
        parsing_model_arn: str = "",
        parsing_modality: str = "",
        parsing_prompt_text: str = "",
        # チャンキング設定(オプション)
        chunking_strategy: str = "",
        chunking_max_tokens: int = 0,
        chunking_overlap_percentage: int = 0,
        chunking_overlap_tokens: int = 0,
        chunking_buffer_size: int = 0,
        chunking_breakpoint_threshold: int = 0,
        # マルチモーダルストレージ設定(オプション)
        multimodal_storage_s3_uri: str = "",
    ) -> KnowledgeBaseResponseDict:
        """
        新しいAmazon Bedrock Knowledge Baseを作成します。
        
        Args:
            name: Knowledge Baseの名前(1-100文字)
            description: Knowledge Baseの説明(1文字以上)
            role_arn: Knowledge Baseが使用するIAMロールのARN
                - 完全な形式: "arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME"
                - アカウントIDなし: "arn:aws:iam::role/ROLE_NAME" または "role/ROLE_NAME"(自動補完)
            storage_type: ストレージタイプ
                - 'S3': 標準的なS3ストレージ(デフォルト)
                - 'S3_VECTORS': S3 Vectorsを使用したベクトル検索対応ストレージ
            bucket_arn: ドキュメントを保存するS3バケットのARNまたはS3 URI
                - ARN形式: "arn:aws:s3:::BUCKET_NAME"
                - URI形式: "s3://BUCKET_NAME" または "s3://BUCKET_NAME/path"
                S3_VECTORSの場合はベクトルバケットARNまたはURIを指定
            region: Knowledge Baseを作成する先のリージョン(デフォルト: "us-east-1")
                例: "us-east-1", "ap-northeast-1"
                注意: Knowledge Baseのリージョンは作成時に決定され、後から変更できません
            embedding_model_arn: 埋め込みモデルのARN(S3_VECTORSタイプの場合必須)
                形式: "arn:aws:bedrock:REGION::foundation-model/MODEL_ID"
                
                サポートされている埋め込みモデル:
                - Amazon Titan Embeddings G1 - Text:
                  "arn:aws:bedrock:REGION::foundation-model/amazon.titan-embed-text-v1"
                  (ベクトル次元数: 1536、タイプ: Floating-point)
                
                - Amazon Titan Text Embeddings V2:
                  "arn:aws:bedrock:REGION::foundation-model/amazon.titan-embed-text-v2:0"
                  (ベクトル次元数: 256, 512, 1024、タイプ: Floating-point, binary)
                
                - Cohere Embed Multilingual:
                  "arn:aws:bedrock:REGION::foundation-model/cohere.embed-multilingual-v3"
                  (ベクトル次元数: 1024、タイプ: Floating-point, binary)
                
                - Amazon Nova Multimodal Embeddings v1:
                  "arn:aws:bedrock:REGION::foundation-model/amazon.nova-2-multimodal-embeddings-v1:0"
                  (ベクトル次元数: 1024、タイプ: Floating-point)
                  (マルチモーダル対応: テキスト、画像、動画、音声を処理可能)
                  注意: マルチモーダルコンテンツを処理する場合は、supplementalDataStorageConfiguration
                  でマルチモーダルストレージ先を指定する必要があります
                
                例: "arn:aws:bedrock:us-east-1::foundation-model/amazon.titan-embed-text-v1"
                注意: リージョンは実際に使用するリージョンに置き換えてください
            
            パーシング設定(オプション):
            parsing_strategy: パーシング戦略
                - 'BEDROCK_FOUNDATION_MODEL': Foundation Modelを使用したパーシング
                  (マルチモーダルデータ(画像、表、グラフなど)を処理可能、プロンプトカスタマイズ可能)
                - 'BEDROCK_DATA_AUTOMATION': Bedrock Data Automationを使用したパーシング
                  (マルチモーダルデータを処理可能、完全マネージド、追加プロンプト不要)
                注意: 指定しない場合はデフォルトパーサーが使用されます(テキストのみ、無料)
            parsing_model_arn: Foundation ModelのARN(parsing_strategy='BEDROCK_FOUNDATION_MODEL'の場合必須)
                例: "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0"
                サポートされているモデル: Claude 3 Sonnet, Claude 3 Opus, Claude 3 Haikuなど
            parsing_modality: マルチモーダル設定
                - 'MULTIMODAL': テキストと画像の両方を処理(オプション)
            parsing_prompt_text: パーシングプロンプトのテキスト(オプション)
                Foundation Modelにドキュメントの解釈方法を指示するテキスト
                例: "Extract all text, tables, and figures from this document."
            
            チャンキング設定(オプション):
            chunking_strategy: チャンキング戦略
                - 'FIXED_SIZE': 固定サイズのチャンクに分割(推奨: max_tokens=1000, overlap_percentage=20)
                - 'HIERARCHICAL': 階層的なチャンクに分割(大きなチャンクと小さなチャンクの2層)
                - 'SEMANTIC': セマンティックなチャンクに分割(NLPを使用して類似コンテンツでグループ化)
                - 'NONE': チャンクに分割しない(各ファイルが1つのチャンクとして扱われる)
                注意: 指定しない場合はデフォルトのチャンキングが使用されます
            chunking_max_tokens: 最大トークン数(chunking_strategy='FIXED_SIZE'または'SEMANTIC'の場合に使用)
                - FIXED_SIZE: 1以上(推奨: 500-2000)
                - SEMANTIC: 1以上(推奨: 1000-3000)
            chunking_overlap_percentage: オーバーラップ率(chunking_strategy='FIXED_SIZE'の場合に使用)
                範囲: 1-99(推奨: 10-30)
                隣接するチャンク間で重複するトークンの割合
            chunking_overlap_tokens: オーバーラップトークン数(chunking_strategy='HIERARCHICAL'の場合に使用)
                階層チャンキングで使用する重複トークン数
            chunking_buffer_size: バッファサイズ(chunking_strategy='SEMANTIC'の場合に使用)
                範囲: 0-1(推奨: 1)
                文を比較する際の移動コンテキストウィンドウのサイズ
            chunking_breakpoint_threshold: ブレークポイントのパーセンタイル閾値(chunking_strategy='SEMANTIC'の場合に使用)
                範囲: 50-99(推奨: 80-95)
                チャンクを分割するための類似度閾値(低いほど多くのチャンクが作成される)
    
        Returns:
            KnowledgeBaseResponseDict: Knowledge Baseの作成結果
                - knowledge_base_id: 作成されたKnowledge BaseのID
                - status: Knowledge Baseのステータス('CREATING', 'ACTIVE', 'FAILED'など)
                - arn: Knowledge BaseのARN(オプション)
        
        Raises:
            ValueError: 入力値が無効な場合(バリデーションエラー)
                - storage_typeが無効な値の場合
                - S3_VECTORSタイプでembedding_model_arnが指定されていない場合
                - parsing_strategy='BEDROCK_FOUNDATION_MODEL'でparsing_model_arnが指定されていない場合
                - ARN形式が無効な場合
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. It discloses key behavioral traits: the region is immutable after creation, certain parameters are required conditionally (e.g., embedding_model_arn for S3_VECTORS), and it raises ValueError for invalid inputs. It also notes default values and recommendations, though it lacks details on permissions, rate limits, or costs.

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

Conciseness3/5

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

The description is well-structured with sections for args, parsing settings, chunking settings, returns, raises, and examples. However, it is very long and dense, which may overwhelm. While informative, some details could be streamlined or moved to schema descriptions for better conciseness, though it remains organized.

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 high complexity (18 parameters, 0% schema coverage, no annotations) and the presence of an output schema, the description is highly complete. It covers all parameters thoroughly, explains returns and errors, and provides multiple examples. The output schema handles return values, so the description appropriately focuses on inputs and behavior.

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?

The schema description coverage is 0%, so the description must compensate fully. It provides extensive parameter semantics: detailed explanations for each parameter, including formats, allowed values, examples, dependencies, and recommendations. This adds significant value beyond the bare schema, making parameters understandable and actionable.

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 tool's purpose: '新しいAmazon Bedrock Knowledge Baseを作成します' (creates a new Amazon Bedrock Knowledge Base). It specifies the exact resource (Knowledge Base) and distinguishes it from siblings like update_knowledge_base (which modifies) and get_knowledge_base (which retrieves).

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 for when to use this tool (to create a Knowledge Base) and includes examples with different configurations. However, it does not explicitly state when not to use it or compare it to alternatives like update_knowledge_base for modifications, though the purpose implies it's for initial creation only.

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