tos_list_objects
List objects in a TOS bucket with optional filtering by prefix, delimiter, and maximum results to manage storage content effectively.
Instructions
列举 TOS 对象
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket_name | Yes | 存储桶名称 | |
| delimiter | No | 分隔符 | |
| max_keys | No | 最大返回对象数量 | |
| prefix | No | 对象键前缀 |
Implementation Reference
- src/tos_mcp_server/handlers.py:142-173 (handler)The main handler function that lists objects in a TOS bucket using tos_client.list_objects_type2, parses the response into a structured JSON format including objects, common prefixes, truncation status, and next token.async def list_objects(args: Dict[str, Any]) -> List[TextContent]: """列举对象""" bucket_name = args["bucket_name"] prefix = args.get("prefix", "") delimiter = args.get("delimiter", "") max_keys = args.get("max_keys", 1000) try: resp = tos_client.list_objects_type2(bucket_name, prefix=prefix, delimiter=delimiter, max_keys=max_keys) result = { "objects": [], "common_prefixes": [], "is_truncated": resp.is_truncated, "next_continuation_token": resp.next_continuation_token } for obj in resp.contents: result["objects"].append({ "key": obj.key, "last_modified": str(obj.last_modified) if obj.last_modified else None, "size": obj.size, "etag": obj.etag, "storage_class": str(obj.storage_class) if obj.storage_class else None }) for prefix in resp.common_prefixes: result["common_prefixes"].append(prefix.prefix) return [TextContent(type="text", text=json.dumps(result, indent=2, ensure_ascii=False))] except Exception as e: return [TextContent(type="text", text=f"列举对象失败: {str(e)}")]
- src/tos_mcp_server/server.py:146-174 (schema)Defines the Tool schema for tos_list_objects, including input parameters like bucket_name (required), prefix, delimiter, max_keys with descriptions and defaults.Tool( name="tos_list_objects", description="列举 TOS 对象", inputSchema={ "type": "object", "properties": { "bucket_name": { "type": "string", "description": "存储桶名称" }, "prefix": { "type": "string", "description": "对象键前缀", "default": "" }, "delimiter": { "type": "string", "description": "分隔符", "default": "" }, "max_keys": { "type": "integer", "description": "最大返回对象数量", "default": 1000 } }, "required": ["bucket_name"] } ),
- src/tos_mcp_server/server.py:349-350 (registration)Registers the tool dispatch in the call_tool handler by mapping the tool name to the list_objects function call.elif name == "tos_list_objects": return await list_objects(arguments)