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

TableJSON Schema
NameRequiredDescriptionDefault
objectKeyYes文件的路径

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,
        };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states it downloads files but doesn't describe what happens during download (e.g., file format preservation, error handling, authentication requirements, rate limits, or whether it streams or saves files). For a download operation with zero annotation coverage, this leaves significant behavioral questions unanswered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient Chinese phrase that directly states the tool's function. There's no wasted language or unnecessary elaboration - every word contributes to understanding the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a file download tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns (file content, metadata, download status), error conditions, authentication needs, or how it differs from similar tools like getObjectUrl. The minimal description leaves too many contextual questions unanswered.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% with the single parameter 'objectKey' well-documented as '文件的路径' (file path). The description doesn't add any additional parameter context beyond what the schema already provides, so it meets the baseline for high schema coverage without compensating value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '下载存储桶内的文件' clearly states the action (下载/download) and resource (存储桶内的文件/file in bucket). It distinguishes from siblings like getBucket (which retrieves bucket info) and putObject (which uploads files). However, it doesn't specify the exact scope or format of the download operation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided about when to use this tool versus alternatives like getObjectUrl (which might generate URLs instead of downloading) or other file retrieval methods. The description doesn't mention prerequisites, constraints, or typical use cases for this specific download approach.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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