getBucket
Retrieve a list of files from a specified bucket in Tencent Cloud COS using the MCP protocol, enabling direct access and management of stored data without coding.
Instructions
查询存储桶内的文件列表
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "getBucket"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Prefix | No | 文件列表的路径前缀,默认根路径 |
Implementation Reference
- src/server.ts:297-315 (handler)MCP tool registration and handler for 'getBucket'. Defines input schema for Prefix parameter, executes by calling CosService.getBucket(Prefix), and returns JSON-formatted result with error flag.
server.tool( 'getBucket', '查询存储桶内的文件列表', { Prefix: z.string().optional().describe('文件列表的路径前缀,默认根路径'), }, async ({ Prefix = '' }) => { const res = await COSInstance.getBucket(Prefix); return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: !res.isSuccess, }; }, ); - src/server.ts:300-302 (schema)Input schema for getBucket tool using Zod: optional Prefix string.
{ Prefix: z.string().optional().describe('文件列表的路径前缀,默认根路径'), }, - Helper method in CosService that performs the actual COS getBucket API call with bucket/region/Prefix/Delimiter, handles try-catch, returns structured response.
async getBucket(Prefix = '') { try { const result = await this.cos.getBucket({ Bucket: this.bucket, Region: this.region, Prefix, Delimiter: '', }); return { isSuccess: true, message: '获取列表成功', data: result, }; } catch (error) { return { isSuccess: false, message: '获取列表失败', data: error, }; }