Skip to main content
Glama
r3-yamauchi

Amazon Bedrock Knowledge Base MCP Server

by r3-yamauchi

update_knowledge_base

Modify an Amazon Bedrock Knowledge Base by updating its name, description, or IAM role. Empty parameters preserve existing values.

Instructions

Amazon Bedrock Knowledge Baseを更新します。

Knowledge Baseの名前、説明、IAMロールを更新できます。 空文字列のパラメータは更新されません(既存の値が保持されます)。

Args: knowledge_base_id: 更新対象のKnowledge BaseのID name: 新しい名前(オプション、空文字列の場合は更新されない) description: 新しい説明(オプション、空文字列の場合は更新されない) role_arn: 新しいIAMロールARN(オプション、空文字列の場合は更新されない)

Returns: KnowledgeBaseResponseDict: 更新されたKnowledge Baseのステータス - knowledge_base_id: Knowledge BaseのID - status: Knowledge Baseのステータス - arn: Knowledge BaseのARN(オプション)

Raises: ValueError: knowledge_base_idが空の場合

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
knowledge_base_idYes
nameNo
descriptionNo
role_arnNo

Implementation Reference

  • The MCP tool handler for "update_knowledge_base", which performs input validation and calls the Bedrock client.
    @mcp.tool()  # MCPツールとして公開
    @handle_errors  # エラーハンドリングデコレータを適用
    def update_knowledge_base(
        knowledge_base_id: str,
        name: str = "",
        description: str = "",
        role_arn: str = "",
    ) -> KnowledgeBaseResponseDict:
        """
        Amazon Bedrock Knowledge Baseを更新します。
        
        Knowledge Baseの名前、説明、IAMロールを更新できます。
        空文字列のパラメータは更新されません(既存の値が保持されます)。
    
        Args:
            knowledge_base_id: 更新対象のKnowledge BaseのID
            name: 新しい名前(オプション、空文字列の場合は更新されない)
            description: 新しい説明(オプション、空文字列の場合は更新されない)
            role_arn: 新しいIAMロールARN(オプション、空文字列の場合は更新されない)
    
        Returns:
            KnowledgeBaseResponseDict: 更新されたKnowledge Baseのステータス
                - knowledge_base_id: Knowledge BaseのID
                - status: Knowledge Baseのステータス
                - arn: Knowledge BaseのARN(オプション)
        
        Raises:
            ValueError: knowledge_base_idが空の場合
        """
        # 入力値のバリデーション(共通関数を使用)
        knowledge_base_id = validate_required_string(knowledge_base_id, "knowledge_base_id")
        
        # Bedrockクライアントを使用してKnowledge Baseを更新
        # 空文字列の場合はNoneに変換して、既存の値を保持する
        result = bedrock_client.update_knowledge_base(
            knowledge_base_id=knowledge_base_id,
            name=name.strip() if name else None,
            description=description.strip() if description else None,
            role_arn=role_arn.strip() if role_arn else None,
        )
        return result
  • The helper method in BedrockKBClient that interacts with the AWS Bedrock Agent API to perform the update.
    def update_knowledge_base(
        self,
        knowledge_base_id: str,
        name: Optional[str] = None,
        description: Optional[str] = None,
        role_arn: Optional[str] = None,
    ) -> KnowledgeBaseResponseDict:
        """
        Knowledge Baseの情報を更新します。
        
        Knowledge Baseの名前、説明、IAMロールを更新できます。
        Noneが指定されたパラメータは更新されません(既存の値が保持されます)。
    
        Args:
            knowledge_base_id: 更新対象のKnowledge BaseのID
            name: 新しい名前(オプション、Noneの場合は更新されない)
            description: 新しい説明(オプション、Noneの場合は更新されない)
            role_arn: 新しいIAMロールARN(オプション、Noneの場合は更新されない)
    
        Returns:
            KnowledgeBaseResponseDict: 更新されたKnowledge Baseのステータス
                - knowledge_base_id: Knowledge BaseのID
                - status: Knowledge Baseのステータス
                - arn: Knowledge BaseのARN(オプション、更新時は含まれない場合がある)
        
        Raises:
            ClientError: AWS API呼び出しが失敗した場合
        
        Note:
            少なくとも1つのパラメータ(name、description、role_arn)を
            指定する必要があります。
        """
        try:
            # 更新パラメータを構築(指定されたパラメータのみを含める)
            update_params = {"knowledgeBaseId": knowledge_base_id}
            
            # 指定されたパラメータを追加
            if name:
                update_params["name"] = name
            if description:
                update_params["description"] = description
            if role_arn:
                update_params["roleArn"] = role_arn
    
            # AWS Bedrock APIを呼び出してKnowledge Baseを更新
            response = self.bedrock_agent.update_knowledge_base(**update_params)
            
            # 更新成功をログに記録
            logger.info(f"Updated knowledge base: {knowledge_base_id}")
            
            # 更新結果を整形して返す
            # 更新APIのレスポンスにはarnが含まれない場合があるため、Optionalとして扱います
            return {
                "knowledge_base_id": response["knowledgeBase"]["id"],
                "status": response["knowledgeBase"]["status"],
                "arn": response["knowledgeBase"].get("knowledgeBaseArn"),  # オプション
            }
        except ClientError as e:
            logger.error(f"Error updating knowledge base {knowledge_base_id}: {e}")
            raise

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