Skip to main content
Glama
Tencent

Tencent Cloud COS MCP Server

Official
by Tencent

putObjectSourceUrl

Download files from a specified URL and upload them directly to a Tencent Cloud COS storage bucket, specifying the target directory and file name.

Instructions

通过 url下载文件并将文件上传到存储桶

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fileNameNo文件名 (存在存储桶里的名称)
sourceUrlYes可下载的文件 url
targetDirNo目标目录 (存在存储桶的哪个目录)

Implementation Reference

  • Core implementation of putObjectSourceUrl: validates params, downloads file stream from sourceUrl using axios, generates filename if missing, builds COS key, pipes stream to COS putObject, returns structured success/error response.
    async uploadFileSourceUrl(params: UploadFileParams) {
      // 验证并解析参数
      const validParams = UploadFileParamsSchema.parse(params);
      const { targetDir = '', fileName, sourceUrl } = validParams;
      try {
        const response = await axios({
          method: 'get',
          url: sourceUrl,
          responseType: 'stream'
        });
        const actualFileName = fileName ? fileName : generateOutPutFileId('');
        const cosPath = this.buildCosPath(actualFileName, targetDir);
        const req = response.data;
        const passThrough = new PassThrough();
        const result = await this.cos.putObject({
          Bucket: this.bucket,
          Region:this.region,
          Key: cosPath,
          Body: req.pipe(passThrough),
        });
        return {
          isSuccess: true,
          message: '上传成功',
          data: result,
        };
      } catch (error) {
        return {
          isSuccess: false,
          message: '上传失败',
          data: error,
        };
      }
    }
  • src/server.ts:221-248 (registration)
    Registers the 'putObjectSourceUrl' tool in the MCP server, defines input schema with zod validators, and delegates execution to CosService.uploadFileSourceUrl, formatting response for MCP.
    server.tool(
      'putObjectSourceUrl',
      '通过 url下载文件并将文件上传到存储桶',
      {
        sourceUrl: z.string().describe('可下载的文件 url'),
        fileName: z.string().optional().describe('文件名 (存在存储桶里的名称)'),
        targetDir: z
          .string()
          .optional()
          .describe('目标目录 (存在存储桶的哪个目录)'),
      },
      async ({ sourceUrl, fileName, targetDir}) => {
        const res = await COSInstance.uploadFileSourceUrl({
          targetDir,
          fileName,
          sourceUrl,
        });
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(res.data, null, 2),
            },
          ],
          isError: !res.isSuccess,
        };
      },
    );
  • Zod schema definition for UploadFileParams type, used to validate inputs in uploadFileSourceUrl and other upload methods (note: sourceUrl made optional here for reuse).
    export const UploadFileParamsSchema = z.object({
      filePath: z.string().optional(),
      targetDir: z.string().optional(),
      fileName: z.string().optional(),
      sourceUrl: z.string().optional()
    });
    export type UploadFileParams = z.infer<typeof UploadFileParamsSchema>;
  • Helper method to construct the full COS object key by combining targetDir (normalized) and fileName.
    private buildCosPath(fileName: string, targetDir?: string): string {
      if (!targetDir) {
        return fileName;
      }
      
      // 规范化目标目录:移除头尾斜杠
      const normalizedDir = targetDir.replace(/^\/+|\/+$/g, '');
      return normalizedDir ? `${normalizedDir}/${fileName}` : fileName;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions downloading from a URL and uploading to a bucket, implying a write/mutation operation, but doesn't disclose behavioral traits such as required permissions, rate limits, error handling, or what happens if the file already exists. For a tool with no annotations, this is a significant gap in transparency.

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 sentence: '通过 url下载文件并将文件上传到存储桶'. It's front-loaded with the core action and has no wasted words, making it highly concise and well-structured.

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?

Given the tool's complexity (involving download and upload operations), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects, error cases, or return values, leaving gaps that could hinder an agent's ability to use the tool effectively.

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?

The description adds no parameter semantics beyond what the input schema provides. Schema description coverage is 100%, with clear descriptions for 'fileName', 'sourceUrl', and 'targetDir'. The description doesn't explain parameter interactions, formats, or constraints, so it meets the baseline of 3 where the schema does the heavy lifting.

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 tool's purpose: '通过 url下载文件并将文件上传到存储桶' (download a file via URL and upload it to a storage bucket). It specifies the verb (download and upload) and resource (file to storage bucket). However, it doesn't explicitly differentiate from sibling tools like 'putObject' (which likely uploads from local source), making it clear but not fully sibling-distinctive.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'putObject' or 'getObjectUrl', nor does it specify prerequisites, exclusions, or contexts for usage. This leaves the agent with no explicit usage instructions.

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

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

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