describe_vpcs
Fetch and filter VPC details on Alibaba Cloud by region, ID, name, tags, or owner. Supports pagination and resource group filtering for efficient VPC management.
Instructions
Query VPC list.
Args:
region_id: The region ID of the VPC.
vpc_id: The ID of the VPC. Up to 20 VPC IDs can be specified, separated by commas.
vpc_name: The name of the VPC.
resource_group_id: The resource group ID of the VPC to query.
page_number: The page number of the list. Default: 1.
page_size: The number of entries per page. Maximum value: 50. Default: 10.
vpc_owner_id: The Alibaba Cloud account ID of the VPC owner.
tags: The tags of the resource.
Returns:
Dict[str, Any]: The response containing the list of VPCs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_number | No | ||
| page_size | No | ||
| region_id | Yes | ||
| resource_group_id | No | ||
| tags | No | ||
| vpc_id | No | ||
| vpc_name | No | ||
| vpc_owner_id | No |
Input Schema (JSON Schema)
{
"properties": {
"page_number": {
"default": 1,
"title": "Page Number",
"type": "integer"
},
"page_size": {
"default": 10,
"title": "Page Size",
"type": "integer"
},
"region_id": {
"title": "Region Id",
"type": "string"
},
"resource_group_id": {
"default": null,
"title": "Resource Group Id",
"type": "string"
},
"tags": {
"default": null,
"items": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"title": "Tags",
"type": "array"
},
"vpc_id": {
"default": null,
"title": "Vpc Id",
"type": "string"
},
"vpc_name": {
"default": null,
"title": "Vpc Name",
"type": "string"
},
"vpc_owner_id": {
"default": null,
"title": "Vpc Owner Id",
"type": "integer"
}
},
"required": [
"region_id"
],
"title": "describe_vpcsArguments",
"type": "object"
}
Implementation Reference
- Handler function for the 'describe_vpcs' MCP tool. Calls Alibaba Cloud VPC API via get_vpc_client to list VPCs with optional filters.@mcp.tool(annotations=READ_ONLY_TOOL) async def describe_vpcs( region_id: str, vpc_id: str = None, vpc_name: str = None, resource_group_id: str = None, page_number: int = 1, page_size: int = 10, vpc_owner_id: int = None, tags: List[Dict[str, str]] = None ) -> Dict[str, Any]: """Query VPC list. Args: region_id: The region ID of the VPC. vpc_id: The ID of the VPC. Up to 20 VPC IDs can be specified, separated by commas. vpc_name: The name of the VPC. resource_group_id: The resource group ID of the VPC to query. page_number: The page number of the list. Default: 1. page_size: The number of entries per page. Maximum value: 50. Default: 10. vpc_owner_id: The Alibaba Cloud account ID of the VPC owner. tags: The tags of the resource. Returns: Dict[str, Any]: The response containing the list of VPCs. """ try: # Initialize the client client = get_vpc_client(region_id) # Create request request = vpc_20160428_models.DescribeVpcsRequest( region_id=region_id, page_number=page_number, page_size=page_size ) # Add optional parameters if provided if vpc_id: request.vpc_id = vpc_id if vpc_name: request.vpc_name = vpc_name if resource_group_id: request.resource_group_id = resource_group_id if vpc_owner_id: request.vpc_owner_id = vpc_owner_id if tags: request.tag = tags # Make the API request response = client.describe_vpcs(request) return response.to_map() except Exception as e: logger.error(f"Error occurred while querying VPCs: {str(e)}") raise OpenAPIError(f"Failed to query VPCs: {str(e)}")
- Helper function to create and return VPCClient instance using credentials and region.def get_vpc_client(region_id: str) -> VpcClient: """Get VPC client instance. Args: region_id: The region ID for the VPC client. Returns: VpcClient: The VPC client instance for the specified region. """ ak, sk, sts = get_aksk() config = Config( access_key_id=ak, access_key_secret=sk, security_token=sts, region_id=region_id, protocol="https", connect_timeout=10 * 1000, read_timeout=300 * 1000 ) return VpcClient(config)
- src/alibabacloud_rds_openapi_mcp_server/server.py:602-602 (registration)MCP tool registration decorator for describe_vpcs.@mcp.tool(annotations=READ_ONLY_TOOL)