Skip to main content
Glama
156554395

Tencent Cloud COS MCP Server

by 156554395

upload_file

Upload a single file from your local system to Tencent Cloud Object Storage (COS) for secure cloud storage management.

Instructions

上传单个文件到腾讯云COS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
custom_domainNo自定义访问域名(可选)
file_pathYes本地文件路径
object_keyNo上传后在COS中的对象键名,如果未提供则使用文件名

Implementation Reference

  • MCP tool handler for 'upload_file': validates local file path existence and delegates upload to cosService.uploadFile, returning formatted success response.
    case 'upload_file':
      const cleanPath = validateFileExists(args.file_path);
      const result = await cosService.uploadFile(cleanPath, {
        key: args.object_key,
        customDomain: args.custom_domain
      });
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({ success: true, data: result }, null, 2)
          }
        ]
      };
  • Schema definition for 'upload_file' tool, including input parameters: file_path (required), object_key, custom_domain.
    upload_file: {
      name: 'upload_file',
      description: '上传单个文件到腾讯云COS',
      inputSchema: {
        type: 'object',
        properties: {
          file_path: {
            type: 'string',
            description: '本地文件路径'
          },
          object_key: {
            type: 'string',
            description: '上传后在COS中的对象键名,如果未提供则使用文件名'
          },
          custom_domain: {
            type: 'string',
            description: '自定义访问域名(可选)'
          }
        },
        required: ['file_path']
      }
    },
  • Core uploadFile method in cosService: handles both small file direct upload and large file slice upload (delegates to _uploadLargeFile if >5MB), manages temp files, returns upload result with URL and metadata.
    async uploadFile(localPath, {
      key = null,
      customDomain = null,
      useSliceUpload = false,
      chunkSize = 1024 * 1024, // 1MB
      concurrency = 3,
      onProgress = null
    } = {}) {
      this._checkConfig();
    
      try {
        // 获取文件状态
        const stats = await fs.stat(localPath);
        const fileSize = stats.size;
    
        // 生成key,如果没提供则使用文件名
        const objectKey = key || path.basename(localPath);
    
        // 判断是否使用分片上传 (文件大于5MB或强制指定)
        const shouldUseSliceUpload = useSliceUpload || fileSize > (5 * 1024 * 1024);
    
        if (shouldUseSliceUpload) {
          return await this._uploadLargeFile(localPath, objectKey, {
            customDomain,
            chunkSize,
            concurrency,
            onProgress,
            fileSize
          });
        }
    
        // 小文件直接上传
        const buffer = await fs.readFile(localPath);
        const params = {
          Bucket: this.config.Bucket,
          Region: this.config.Region,
          Key: objectKey,
          Body: buffer,
        };
    
        const response = await this.cos.putObject(params);
    
        // 上传成功后清理相关临时文件
        try {
          await this._cleanupUploadTempFiles(objectKey);
        } catch (clearErr) {
          // 清理临时文件失败时静默处理,不影响上传成功的结果
        }
    
        // 生成访问URL
        const domain = customDomain || this.config.Domain || `https://${this.config.Bucket}.cos.${this.config.Region}.myqcloud.com`;
        const fileUrl = `${domain}/${objectKey}`;
    
        return {
          success: true,
          url: fileUrl,
          key: objectKey,
          etag: response.ETag,
          location: response.Location,
          size: fileSize,
          uploadType: 'direct'
        };
      } catch (error) {
        // 上传失败时,清理可能产生的临时文件
        try {
          await this._cleanupUploadTempFiles(objectKey);
        } catch (clearErr) {
          // 清理失败时静默处理
        }
    
        console.error('上传失败:', error);
        throw new Error(`文件上传失败: ${error.message}`);
      }
    }
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 this is an upload operation (implying a write/mutation), but doesn't mention authentication requirements, rate limits, error conditions, what happens on success, or whether the operation is idempotent. The description is minimal and lacks important behavioral context.

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 extremely concise - a single Chinese sentence that directly states the tool's purpose. There's zero wasted language, and it's front-loaded with the core functionality. This is an example of efficient communication.

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 mutation tool (file upload) with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after upload, what gets returned, error handling, or important constraints. The combination of mutation behavior + lack of structured metadata requires more descriptive context than provided.

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?

With 100% schema description coverage, the schema already documents all three parameters thoroughly. The description adds no additional parameter information beyond what's in the schema. This meets the baseline of 3 when schema coverage is high, but doesn't provide extra 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 ('上传' - upload) and target resource ('单个文件到腾讯云COS' - single file to Tencent Cloud COS), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from its sibling 'upload_multiple', which handles multiple files instead of single files.

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 the sibling 'upload_multiple' for batch operations, nor does it explain when to choose this over other storage operations like 'get_signed_url' or 'list_objects'.

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

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