upload_text_data
Transfer text data to Qiniu Cloud Storage by specifying a bucket, key, and optional overwrite setting. Ideal for managing and storing textual content in Qiniu's cloud infrastructure.
Instructions
Upload text data to Qiniu bucket.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bucket | Yes | Qiniu Cloud Storage bucket Name | |
| data | Yes | The data to upload. | |
| key | Yes | The key under which a file is saved in Qiniu Cloud Storage serves as the unique identifier for the file within that space, typically using the filename. | |
| overwrite | No | Whether to overwrite the existing object if it already exists. |
Implementation Reference
- MCP tool handler for 'upload_text_data', decorated with tool metadata including input schema. Delegates to StorageService.upload_text_data and returns formatted TextContent response.@tools.tool_meta( types.Tool( name="upload_text_data", description="Upload text data to Qiniu bucket.", inputSchema={ "type": "object", "properties": { "bucket": { "type": "string", "description": _BUCKET_DESC, }, "key": { "type": "string", "description": "The key under which a file is saved in Qiniu Cloud Storage serves as the unique identifier for the file within that space, typically using the filename.", }, "data": { "type": "string", "description": "The data to upload.", }, "overwrite": { "type": "boolean", "description": "Whether to overwrite the existing object if it already exists.", }, }, "required": ["bucket", "key", "data"], } ) ) def upload_text_data(self, **kwargs) -> list[types.TextContent]: urls = self.storage.upload_text_data(**kwargs) return [types.TextContent(type="text", text=str(urls))]
- src/mcp_server/core/storage/tools.py:236-247 (registration)Registration of the upload_text_data tool handler instance in the tools.auto_register_tools call.def register_tools(storage: StorageService): tool_impl = _ToolImpl(storage) tools.auto_register_tools( [ tool_impl.list_buckets, tool_impl.list_objects, tool_impl.get_object, tool_impl.upload_text_data, tool_impl.upload_local_file, tool_impl.get_object_url, ] )
- Core helper method in StorageService that performs the actual upload_text_data using Qiniu SDK, generates upload token with policy, uploads data, and returns object URLs.def upload_text_data(self, bucket: str, key: str, data: str, overwrite: bool = False) -> list[dict[str:Any]]: policy = { "insertOnly": 1, } if overwrite: policy["insertOnly"] = 0 policy["scope"] = f"{bucket}:{key}" token = self.auth.upload_token(bucket=bucket, key=key, policy=policy) ret, info = qiniu.put_data(up_token=token, key=key, data=bytes(data, encoding="utf-8")) if info.status_code != 200: raise Exception(f"Failed to upload object: {info}") return self.get_object_url(bucket, key)