Skip to main content
Glama

getObject

Download files from cloud storage buckets by specifying the file path. This tool enables retrieval of stored objects for access or processing.

Instructions

下载存储桶内的文件

Input Schema

NameRequiredDescriptionDefault
objectKeyYes文件的路径

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:272-296 (registration)
    Registration of the MCP tool 'getObject' using server.tool(), including schema and inline 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, }; }, );
  • The handler function that executes the 'getObject' tool logic, delegating to COSInstance.getObject and formatting the MCP response.
    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 defining the 'objectKey' parameter for the 'getObject' tool.
    { objectKey: z.string().describe('文件的路径'), },
  • Supporting method in CosService that performs the actual COS getObject operation and converts the result to MCP-compatible content format (image/audio/text).
    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/xiaomizhoubaobei/MCP'

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