PutBucket
Create and configure a new OSS storage bucket in AlibabaCloud with options for region, storage class, and data redundancy type for efficient resource management.
Instructions
创建一个新的OSS存储空间。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| BucketName | Yes | AlibabaCloud OSS Bucket Name | |
| DataRedundancyType | No | The data disaster recovery type of AlibabaCloud OSS Bucket, LRS (default): Locally redundant LRS, which stores your data redundantly on different storage devices in the same availability zone. ZRS: Intra-city redundant ZRS, which uses a multi-availability zone (AZ) mechanism to store your data redundantly in three availability zones in the same region. | LRS |
| RegionId | No | AlibabaCloud region ID | cn-hangzhou |
| StorageClass | No | The Storage Type of AlibabaCloud OSS Bucket, The value range is as follows: Standard (default): standard storage, IA: infrequent access, Archive: archive storage, ColdArchive: cold archive storage, DeepColdArchive: deep cold archive storage | Standard |
Implementation Reference
- Handler function for the OSS_PutBucket tool. Creates a new OSS bucket using the Alibaba Cloud OSS SDK with specified parameters for region, storage class, and data redundancy.@tools.append def OSS_PutBucket( BucketName: str = Field(description='AlibabaCloud OSS Bucket Name'), RegionId: str = Field(description='AlibabaCloud region ID', default='cn-hangzhou'), StorageClass: str = Field(description='The Storage Type of AlibabaCloud OSS Bucket, The value range is as follows: ' 'Standard (default): standard storage, ' 'IA: infrequent access, Archive: archive storage, ' 'ColdArchive: cold archive storage, ' 'DeepColdArchive: deep cold archive storage', default='Standard'), DataRedundancyType: str = Field(description='The data disaster recovery type of AlibabaCloud OSS Bucket, ' 'LRS (default): Locally redundant LRS, which stores your data ' 'redundantly on different storage devices in the same availability zone. ' 'ZRS: Intra-city redundant ZRS, which uses a multi-availability zone ' '(AZ) mechanism to store your data redundantly in three availability ' 'zones in the same region.', default='LRS') ): """创建一个新的OSS存储空间。""" client = create_client(region_id=RegionId) result = client.put_bucket(oss.PutBucketRequest( bucket=BucketName, create_bucket_configuration=oss.CreateBucketConfiguration( storage_class=StorageClass, data_redundancy_type=DataRedundancyType ) )) return result.__str__()
- src/alibaba_cloud_ops_mcp_server/server.py:86-87 (registration)Registration of all OSS tools (including OSS_PutBucket) into the FastMCP server instance.for tool in oss_tools.tools: mcp.tool(tool)
- Helper function to create an OSS client instance with credentials and region configuration, used by OSS_PutBucket.def create_client(region_id: str) -> oss.Client: credentials_provider = CredentialsProvider() cfg = oss.config.load_default() cfg.user_agent = 'alibaba-cloud-ops-mcp-server' cfg.credentials_provider = credentials_provider cfg.region = region_id return oss.Client(cfg)
- Custom credentials provider class for OSS client, fetches credentials from headers or credential client.class CredentialsProvider(EnvironmentVariableCredentialsProvider): def __init__(self) -> None: credentials = get_credentials_from_header() if credentials: access_key_id = credentials.get('AccessKeyId', None) access_key_secret = credentials.get('AccessKeySecret', None) session_token = credentials.get('SecurityToken', None) else: credentialsClient = CredClient() access_key_id = credentialsClient.get_credential().access_key_id access_key_secret = credentialsClient.get_credential().access_key_secret session_token = credentialsClient.get_credential().security_token self._credentials = Credentials( access_key_id, access_key_secret, session_token) def get_credentials(self) -> Credentials: return self._credentials
- src/alibaba_cloud_ops_mcp_server/tools/oss_tools.py:80-80 (registration)Decorator that appends the OSS_PutBucket function to the local tools list for later registration.@tools.append