Skip to main content
Glama
Tencent

Tencent Cloud COS MCP Server

Official
by Tencent

getObject

Download files from specified buckets in Tencent Cloud COS MCP Server by providing the file path as input, enabling direct access to stored objects for processing or retrieval.

Instructions

下载存储桶内的文件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
objectKeyYes文件的路径

Implementation Reference

  • src/server.ts:272-296 (registration)
    Registration of the 'getObject' MCP tool using server.tool, including inline schema and handler.
    server.tool( 'getObject', '下载存储桶内的文件', { objectKey: z.string().describe('文件的路径'), }, async ({ objectKey = '/' }) => { const res = await COSInstance.getObject(objectKey); if (!res.isSuccess) { return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: true }; } return { content: [res.data] as any, isError: false, }; }, );
  • Zod input schema for the 'getObject' tool defining the objectKey parameter.
    { objectKey: z.string().describe('文件的路径'), },
  • Inline handler function for 'getObject' tool: calls COSInstance.getObject, handles errors, and returns MCP-formatted content.
    async ({ objectKey = '/' }) => { const res = await COSInstance.getObject(objectKey); if (!res.isSuccess) { return { content: [ { type: 'text', text: JSON.stringify(res.data, null, 2), }, ], isError: true }; } return { content: [res.data] as any, isError: false, }; },
  • CosService.getObject method: core logic for fetching object from COS bucket, processing buffer into MCP-compatible content (image/audio/text/base64), handling errors.
    async getObject(objectKey = '/') { try { // 下载文件 const cosParams: COS.GetObjectParams = { Bucket: this.bucket, Region: this.region, Key: objectKey, }; const result = await this.cos.getObject(cosParams); // 统一处理 buffer const buffer = Buffer.isBuffer(result.Body) ? result.Body : Buffer.from(result.Body ?? ''); // 获取 Content-Type,统一小写 let contentType = result.headers && (result.headers['content-type'] || result.headers['Content-Type']); contentType = typeof contentType === 'string' ? contentType.toLowerCase() : ''; let mcpData; if (contentType.startsWith('image/')) { mcpData = { type: 'image', data: buffer.toString('base64'), mimeType: contentType }; } else if (contentType.startsWith('audio/')) { mcpData = { type: 'audio', data: buffer.toString('base64'), mimeType: contentType }; } else if (contentType.startsWith('text/') || TEXT_TYPES.includes(contentType)) { mcpData = { type: 'text', text: buffer.toString('utf-8') }; } else { mcpData = { type: 'text', text: buffer.toString('base64') }; } return { isSuccess: true, message: '下载文件成功', data: mcpData, }; } catch (error) { return { isSuccess: false, message: '下载文件失败', data: error instanceof Error ? error.message : error, }; } }

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/Tencent/cos-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server