Skip to main content
Glama
r3-yamauchi

Amazon Bedrock Knowledge Base MCP Server

by r3-yamauchi

list_s3_documents

Retrieve a list of documents from an Amazon S3 bucket, optionally filtering by folder prefix to locate specific files for knowledge base management.

Instructions

S3バケット内のドキュメント一覧を取得します。

指定されたプレフィックス(フォルダ)に一致するドキュメントのみを 取得することもできます。

Args: bucket_name: S3バケット名 prefix: フィルタリングするS3プレフィックス(オプション) 例: "documents/" を指定すると、documents/フォルダ内の ファイルのみが返されます

Returns: S3DocumentListResponseDict: ドキュメント一覧 - count: ドキュメントの数 - bucket: バケット名 - prefix: 使用されたプレフィックス(指定した場合) - documents: ドキュメントの詳細情報のリスト 各要素には以下の情報が含まれます: - key: S3オブジェクトキー(ファイルパス) - size: ファイルサイズ(バイト) - last_modified: 最終更新日時(ISO形式)

Raises: ValueError: bucket_nameが空の場合

Example: # すべてのドキュメントを取得 list_s3_documents("my-bucket")

# 特定のプレフィックスのドキュメントのみを取得
list_s3_documents("my-bucket", "documents/")

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bucket_nameYes
prefixNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
countYes
bucketYes
prefixYes
documentsYes

Implementation Reference

  • Implementation of the S3 document listing logic using the S3 client paginator.
    def list_s3_documents(
        self, bucket_name: str, prefix: str = ""
    ) -> List[Dict[str, Any]]:
        """
        S3バケット内のドキュメント一覧を取得します。
        
        ページネーションを使用して、すべてのドキュメントを取得します。
        指定されたプレフィックス(フォルダ)に一致するドキュメントのみを
        取得することもできます。
    
        Args:
            bucket_name: S3バケット名
            prefix: フィルタリングするS3プレフィックス(オプション)
                    例: "documents/" を指定すると、documents/フォルダ内の
                        ファイルのみが返されます
    
        Returns:
            List[Dict[str, Any]]: ドキュメントの詳細情報のリスト
                各要素には以下の情報が含まれます:
                - key: S3オブジェクトキー(ファイルパス)
                - size: ファイルサイズ(バイト)
                - last_modified: 最終更新日時(ISO形式)
        
        Raises:
            ClientError: AWS API呼び出しが失敗した場合
                例: バケットが存在しない、権限がないなど
        
        Note:
            大量のドキュメントがある場合、この関数の実行に時間がかかる場合があります。
        """
        try:
            documents = []
            
            # ページネーターを取得(複数ページの結果を自動的に処理)
            paginator = self.s3_client.get_paginator("list_objects_v2")
            
            # すべてのページをループして結果を収集
            for page in paginator.paginate(Bucket=bucket_name, Prefix=prefix):
                # 各ページからオブジェクト情報を取得
                for obj in page.get("Contents", []):
                    # ドキュメント情報を整形してリストに追加
                    documents.append(
                        {
                            "key": obj["Key"],  # S3オブジェクトキー
                            "size": obj["Size"],  # ファイルサイズ(バイト)
                            "last_modified": obj["LastModified"].isoformat(),  # ISO形式の日時
                        }
                    )
            
            # 取得したドキュメントの数をログに記録
            logger.info(f"Retrieved {len(documents)} documents from S3")
            return documents
        except ClientError as e:
            logger.error(f"Error listing S3 documents: {e}")
            raise
  • MCP tool registration and wrapper function for list_s3_documents.
    @mcp.tool()  # MCPツールとして公開
    @handle_errors  # エラーハンドリングデコレータを適用
    def list_s3_documents(bucket_name: str, prefix: str = "") -> S3DocumentListResponseDict:
        """
        S3バケット内のドキュメント一覧を取得します。
        
        指定されたプレフィックス(フォルダ)に一致するドキュメントのみを
        取得することもできます。
    
        Args:
            bucket_name: S3バケット名
            prefix: フィルタリングするS3プレフィックス(オプション)
                    例: "documents/" を指定すると、documents/フォルダ内の
                        ファイルのみが返されます
    
        Returns:
            S3DocumentListResponseDict: ドキュメント一覧
                - count: ドキュメントの数
                - bucket: バケット名
                - prefix: 使用されたプレフィックス(指定した場合)
                - documents: ドキュメントの詳細情報のリスト
                    各要素には以下の情報が含まれます:
                    - key: S3オブジェクトキー(ファイルパス)
                    - size: ファイルサイズ(バイト)
                    - last_modified: 最終更新日時(ISO形式)
        
        Raises:
            ValueError: bucket_nameが空の場合
        
        Example:
            # すべてのドキュメントを取得
            list_s3_documents("my-bucket")
            
            # 特定のプレフィックスのドキュメントのみを取得
            list_s3_documents("my-bucket", "documents/")
        """
        # 入力値のバリデーション(共通関数を使用)
        bucket_name = validate_required_string(bucket_name, "bucket_name")
        
        # プレフィックスはオプションなので、指定されている場合のみstripを適用
        prefix_cleaned = prefix.strip() if prefix else ""
        
        # BedrockクライアントからS3ドキュメント一覧を取得
        documents = bedrock_client.list_s3_documents(
            bucket_name,  # 前後の空白は既に削除済み
            prefix_cleaned
        )
        return {
            "count": len(documents),
            "bucket": bucket_name,  # 前後の空白は既に削除済み
            "prefix": prefix_cleaned,
            "documents": documents,
        }
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses the read-only nature through '取得します' (retrieves) and mentions error conditions (ValueError for empty bucket_name). However, it doesn't cover important behavioral aspects like pagination, rate limits, authentication requirements, or whether it lists all objects recursively within prefixes.

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) and uses both Japanese and English effectively. While comprehensive, some information could be more concise - the prefix explanation uses multiple lines when one might suffice. Overall, most sentences earn their place.

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, no annotations, but with output schema coverage, the description is reasonably complete. It explains parameters thoroughly, documents the return structure in detail, shows error conditions, and provides usage examples. The main gap is lack of behavioral context like pagination or authentication requirements.

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 parameter semantics. It explains both parameters thoroughly: bucket_name as S3 bucket name, prefix as optional filtering parameter with a clear example showing how it works. The Japanese and English explanations add clarity beyond what the bare schema provides.

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バケット内のドキュメント一覧を取得します' (retrieves a list of documents in an S3 bucket). It specifies the verb (取得/retrieve) and resource (ドキュメント一覧/document list), but doesn't explicitly differentiate from sibling tools like 'list_data_sources' or 'list_knowledge_bases' beyond the S3 context.

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 through the optional prefix parameter explanation and examples, showing when to use it for filtering. However, it doesn't explicitly state when to choose this tool over alternatives like 'upload_document_to_s3' or 'list_data_sources', nor does it mention prerequisites or exclusions.

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