Skip to main content
Glama
r3-yamauchi

Amazon Bedrock Knowledge Base MCP Server

by r3-yamauchi

upload_document_to_s3

Upload local files to an S3 bucket for use as data sources in Amazon Bedrock Knowledge Bases, enabling document ingestion for RAG applications.

Instructions

ローカルファイルをS3バケットにアップロードします。

アップロードされたファイルは、Knowledge Baseのデータソースとして 使用できます。

Args: local_file_path: アップロードするローカルファイルのパス bucket_name: アップロード先のS3バケット名 s3_key: S3オブジェクトキー(バケット内のパス) 例: "documents/myfile.pdf" のようにパスを指定可能

Returns: S3UploadResponseDict: アップロード結果 - s3_uri: アップロードされたファイルのS3 URI(s3://bucket/key形式) - status: アップロードステータス("uploaded")

Raises: ValueError: パラメータが空の場合、またはファイルが存在しない場合

Example: upload_document_to_s3( "/path/to/document.pdf", "my-bucket", "documents/document.pdf" ) # 戻り値: {"s3_uri": "s3://my-bucket/documents/document.pdf", "status": "uploaded"}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
local_file_pathYes
bucket_nameYes
s3_keyYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
s3_uriYes
statusYes

Implementation Reference

  • The core handler logic that executes the S3 file upload using boto3.
    def upload_document_to_s3(
        self, local_file_path: str, bucket_name: str, s3_key: str
    ) -> S3UploadResponseDict:
        """
        ローカルファイルをS3バケットにアップロードします。
        
        アップロードされたファイルは、Knowledge Baseのデータソースとして
        使用できます。
    
        Args:
            local_file_path: アップロードするローカルファイルのパス
            bucket_name: アップロード先のS3バケット名
            s3_key: S3オブジェクトキー(バケット内のパス)
                    例: "documents/myfile.pdf" のようにパスを指定可能
    
        Returns:
            S3UploadResponseDict: アップロード結果
                - s3_uri: アップロードされたファイルのS3 URI(s3://bucket/key形式)
                - status: アップロードステータス("uploaded")
        
        Raises:
            ClientError: AWS API呼び出しが失敗した場合
                例: バケットが存在しない、権限がない、ファイルが大きすぎるなど
        """
        try:
            # S3クライアントを使用してファイルをアップロード
            self.s3_client.upload_file(local_file_path, bucket_name, s3_key)
            
            # S3 URIを構築
            s3_uri = f"s3://{bucket_name}/{s3_key}"
            
            # アップロード成功をログに記録
            logger.info(f"Uploaded document to {s3_uri}")
            
            # アップロード結果を返す
            return {"s3_uri": s3_uri, "status": "uploaded"}
        except ClientError as e:
            logger.error(f"Error uploading document to S3: {e}")
            raise
  • The MCP tool registration and input validation wrapper for 'upload_document_to_s3'.
    def upload_document_to_s3(
        local_file_path: str, bucket_name: str, s3_key: str
    ) -> S3UploadResponseDict:
        """
        ローカルファイルをS3バケットにアップロードします。
        
        アップロードされたファイルは、Knowledge Baseのデータソースとして
        使用できます。
    
        Args:
            local_file_path: アップロードするローカルファイルのパス
            bucket_name: アップロード先のS3バケット名
            s3_key: S3オブジェクトキー(バケット内のパス)
                    例: "documents/myfile.pdf" のようにパスを指定可能
    
        Returns:
            S3UploadResponseDict: アップロード結果
                - s3_uri: アップロードされたファイルのS3 URI(s3://bucket/key形式)
                - status: アップロードステータス("uploaded")
        
        Raises:
            ValueError: パラメータが空の場合、またはファイルが存在しない場合
        
        Example:
            upload_document_to_s3(
                "/path/to/document.pdf",
                "my-bucket",
                "documents/document.pdf"
            )
            # 戻り値: {"s3_uri": "s3://my-bucket/documents/document.pdf", "status": "uploaded"}
        """
        import os
        
        # 入力値のバリデーション(共通関数を使用)
        # すべてのパラメータは必須です
        local_file_path = validate_required_string(local_file_path, "local_file_path")
        bucket_name = validate_required_string(bucket_name, "bucket_name")
        s3_key = validate_required_string(s3_key, "s3_key")
        
        # ファイルの存在確認
        # ローカルファイルシステム上にファイルが存在することを確認します
        # ファイルが存在しない場合、S3へのアップロードは失敗するため、事前にチェックします
        if not os.path.exists(local_file_path):
            raise ValueError(f"File not found: {local_file_path}")
        
        # 注意: ファイルサイズのチェックは行っていません
        # 非常に大きなファイルの場合、アップロードに時間がかかる可能性があります
    
        # Bedrockクライアントを使用してS3にアップロード
        result = bedrock_client.upload_document_to_s3(
            local_file_path,  # 前後の空白は既に削除済み
            bucket_name,  # 前後の空白は既に削除済み
            s3_key  # 前後の空白は既に削除済み
        )
        return result
Behavior3/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 reveal some behavioral traits: it describes the return format (S3UploadResponseDict with s3_uri and status), error conditions (ValueError for empty parameters or missing files), and provides an example. However, it lacks details on permissions needed, rate limits, file size constraints, or whether the operation is idempotent/destructive.

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 sections (Args, Returns, Raises, Example) and front-loaded with the core purpose. It's appropriately sized for a 3-parameter tool with output schema. Some minor redundancy exists (e.g., repeating parameter info in example), but overall it's efficient and organized.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no annotations, but has output schema), the description is fairly complete. It covers purpose, parameters, return values, errors, and provides an example. The output schema existence means it doesn't need to explain return values in detail. However, it could better address integration with sibling tools and operational constraints.

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

Parameters4/5

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

Schema description coverage is 0%, so the description must compensate. It provides clear semantics for all three parameters: local_file_path (path to upload), bucket_name (destination bucket), and s3_key (S3 object key with example). The example further clarifies usage. However, it doesn't specify constraints like path formats, bucket naming rules, or key structure limitations beyond the example.

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

Purpose4/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: 'ローカルファイルをS3バケットにアップロードします' (Upload local files to an S3 bucket). It specifies the verb (upload) and resource (local files to S3 bucket). However, it doesn't explicitly differentiate from sibling tools like 'create_s3_bucket' or 'list_s3_documents', which would be needed for a perfect score.

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

Usage Guidelines3/5

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

The description provides implied usage context by mentioning that uploaded files can be used as Knowledge Base data sources, which suggests integration with other sibling tools. However, it doesn't explicitly state when to use this tool versus alternatives (e.g., vs. 'create_data_source' or 'start_ingestion_job'), nor does it provide clear exclusions or prerequisites beyond parameter validation.

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