getObjectUrl
Generate signed download URLs for files stored in cloud storage buckets to enable secure access and sharing.
Instructions
获取存储桶内的文件的带签名的下载链接
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| objectKey | Yes | 文件的路径 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"objectKey": {
"description": "文件的路径",
"type": "string"
}
},
"required": [
"objectKey"
],
"type": "object"
}
Implementation Reference
- src/server.ts:251-269 (registration)Registration of the MCP tool 'getObjectUrl' with description, Zod input schema, and inline handler function that invokes the COS service and returns formatted response.server.tool( 'getObjectUrl', '获取存储桶内的文件的带签名的下载链接', { objectKey: z.string().describe('文件的路径'), }, async ({ objectKey = '/' }) => { const res = await COSInstance.getObjectUrl(objectKey); return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: !res.isSuccess, }; }, );
- src/services/cos/cos.service.ts:381-406 (handler)Core implementation of getObjectUrl in COSService class, using Tencent COS SDK to generate signed download URL for the object.async getObjectUrl(ObjectKey: string) { try { const result = await new Promise((resolve, reject) => { this.cos.getObjectUrl( { Bucket: this.bucket, Region: this.region, Key: ObjectKey, }, (error, data) => (error ? reject(error) : resolve(data)), ); }); return { isSuccess: true, message: '获取带签名 ObjectUrl 成功', data: result, }; } catch (error) { return { isSuccess: false, message: '获取带签名 ObjectUrl 失败', data: error, }; } }
- src/server.ts:254-256 (schema)Zod input schema for the getObjectUrl tool, defining the objectKey parameter.{ objectKey: z.string().describe('文件的路径'), },