tos_put_object
Upload objects to TOS storage by providing bucket name, object key, and content, supporting base64 encoding and content type specification.
Instructions
上传对象到 TOS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket_name | Yes | 存储桶名称 | |
| content | Yes | 文件内容(base64编码)或文本内容 | |
| content_type | No | 内容类型 | application/octet-stream |
| is_base64 | No | 内容是否为base64编码 | |
| object_key | Yes | 对象键名 |
Implementation Reference
- src/tos_mcp_server/handlers.py:80-100 (handler)Core handler function that executes the tos_put_object tool: extracts arguments, handles base64 or text content, calls tos_client.put_object to upload, and returns success or error message.async def put_object(args: Dict[str, Any]) -> List[TextContent]: """上传对象""" bucket_name = args["bucket_name"] object_key = args["object_key"] content = args["content"] content_type = args.get("content_type", "application/octet-stream") is_base64 = args.get("is_base64", False) try: if is_base64: content_bytes = base64.b64decode(content) else: content_bytes = content.encode('utf-8') resp = tos_client.put_object(bucket_name, object_key, content=content_bytes, content_type=content_type, content_length=len(content_bytes)) return [TextContent(type="text", text=f"成功上传对象: {object_key} (ETag: {resp.etag})")] except Exception as e: return [TextContent(type="text", text=f"上传对象失败: {str(e)}")]
- src/tos_mcp_server/server.py:91-122 (schema)Input schema definition for the tos_put_object tool, specifying parameters like bucket_name, object_key, content (base64 or text), content_type, and is_base64 flag.Tool( name="tos_put_object", description="上传对象到 TOS", inputSchema={ "type": "object", "properties": { "bucket_name": { "type": "string", "description": "存储桶名称" }, "object_key": { "type": "string", "description": "对象键名" }, "content": { "type": "string", "description": "文件内容(base64编码)或文本内容" }, "content_type": { "type": "string", "description": "内容类型", "default": "application/octet-stream" }, "is_base64": { "type": "boolean", "description": "内容是否为base64编码", "default": False } }, "required": ["bucket_name", "object_key", "content"] } ),
- src/tos_mcp_server/server.py:345-346 (registration)Registers the tool handler dispatch in the call_tool function: routes calls to name 'tos_put_object' to the put_object handler.elif name == "tos_put_object": return await put_object(arguments)
- src/tos_mcp_server/server.py:91-122 (registration)Tool registration in list_tools(): adds tos_put_object to the list of available tools with its schema and description.Tool( name="tos_put_object", description="上传对象到 TOS", inputSchema={ "type": "object", "properties": { "bucket_name": { "type": "string", "description": "存储桶名称" }, "object_key": { "type": "string", "description": "对象键名" }, "content": { "type": "string", "description": "文件内容(base64编码)或文本内容" }, "content_type": { "type": "string", "description": "内容类型", "default": "application/octet-stream" }, "is_base64": { "type": "boolean", "description": "内容是否为base64编码", "default": False } }, "required": ["bucket_name", "object_key", "content"] } ),