Skip to main content
Glama

Alibaba Cloud Operations MCP Server

by RadiumGu

describe_vswitches

Retrieve a list of virtual switches (vSwitches) in Alibaba Cloud by specifying a region and optionally a VPC ID, enabling efficient network resource management.

Instructions

查询交换机列表

Args: region: 区域ID,如cn-beijing vpc_id: VPC ID(可选)

Input Schema

NameRequiredDescriptionDefault
regionNocn-beijing
vpc_idNo

Input Schema (JSON Schema)

{ "properties": { "region": { "default": "cn-beijing", "title": "Region", "type": "string" }, "vpc_id": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Vpc Id" } }, "title": "describe_vswitchesArguments", "type": "object" }

Implementation Reference

  • The main handler function for the 'describe_vswitches' MCP tool. It dynamically searches for and invokes an underlying tool function containing 'vswitch' in its name from common_api_tools, passing RegionId and optional VpcId.
    @app.tool() def describe_vswitches(region: str = "cn-beijing", vpc_id: Optional[str] = None) -> str: """查询交换机列表 Args: region: 区域ID,如cn-beijing vpc_id: VPC ID(可选) """ try: sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'alibaba_cloud_ops_mcp_server')) from tools import common_api_tools for tool_func in common_api_tools.tools: if hasattr(tool_func, '__name__') and 'vswitch' in tool_func.__name__.lower(): kwargs = {'RegionId': region} if vpc_id: kwargs['VpcId'] = vpc_id result = tool_func(**kwargs) return str(result) return f"交换机查询功能可用,查询region: {region}" except Exception as e: return f"交换机查询失败: {str(e)}"
  • Configuration entry registering 'DescribeVSwitches' as a supported API under the 'Vpc' service, likely used to generate specific tool functions.
    'Vpc': [ 'DescribeVpcs', 'DescribeVSwitches' ],
  • Core helper function _tools_api_call used by dynamically generated API tools (including VPC_DescribeVSwitches) to perform the actual Alibaba Cloud API call to DescribeVSwitches.
    def _tools_api_call(service: str, api: str, parameters: dict, ctx: Context): service = service.lower() api_meta, _ = ApiMetaClient.get_api_meta(service, api) version = ApiMetaClient.get_service_version(service) method = 'POST' if api_meta.get('methods', [])[0] == 'post' else 'GET' path = api_meta.get('path', '/') style = ApiMetaClient.get_service_style(service) # 处理特殊参数格式 processed_parameters = parameters.copy() if service == 'ecs': for param_name, param_value in parameters.items(): if param_name in ECS_LIST_PARAMETERS and isinstance(param_value, list): processed_parameters[param_name] = json.dumps(param_value) req = open_api_models.OpenApiRequest( query=OpenApiUtilClient.query(processed_parameters) ) params = open_api_models.Params( action=api, version=version, protocol='HTTPS', pathname=path, method=method, auth_type='AK', style=style, req_body_type='formData', body_type='json' ) client = create_client(service, processed_parameters.get('RegionId', 'cn-hangzhou')) runtime = util_models.RuntimeOptions() return client.call_api(params, req, runtime)
  • Function that generates and registers dynamic tool functions for each API in the config, including the underlying 'VPC_DescribeVSwitches' tool invoked by the describe_vswitches handler.
    def create_api_tools(mcp: FastMCP, config:dict): for service_code, apis in config.items(): for api_name in apis: _create_and_decorate_tool(mcp, service_code, api_name)
  • Generates the input schema (Pydantic dataclass fields) for dynamically created tools based on API meta data, defining parameters like RegionId and VpcId for DescribeVSwitches.
    def _create_function_schemas(service, api, api_meta): schemas = {} schemas[api] = {} parameters = api_meta.get('parameters', []) required_params = [] optional_params = [] for parameter in parameters: name = parameter.get('name') # TODO 目前忽略了带'.'的参数 if '.' in name: continue schema = parameter.get('schema', '') required = schema.get('required', False) if required: required_params.append(parameter) else: optional_params.append(parameter) def process_parameter(parameter): name = parameter.get('name') schema = parameter.get('schema', '') description = schema.get('description', '') example = schema.get('example', '') type_ = schema.get('type', '') description = f'{description} 参数类型: {type_},参数示例:{example}' required = schema.get('required', False) if service.lower() == 'ecs' and name in ECS_LIST_PARAMETERS and type_ == 'string': python_type = list else: python_type = type_map.get(type_, str) field_info = ( python_type, field( default=None, metadata={'description': description, 'required': required} ) ) return name, field_info for parameter in required_params: name, field_info = process_parameter(parameter) schemas[api][name] = field_info for parameter in optional_params: name, field_info = process_parameter(parameter) schemas[api][name] = field_info if 'RegionId' not in schemas[api]: schemas[api]['RegionId'] = ( str, field( default='cn-hangzhou', metadata={'description': '地域ID', 'required': False} ) ) return schemas def _create_tool_function_with_signature(service: str, api: str, fields: dict, description: str): """ Dynamically creates a lambda function with a custom signature based on the provided fields. """ parameters = [] annotations = {} defaults = {} for name, (type_, field_info) in fields.items(): field_description = field_info.metadata.get('description', '') is_required = field_info.metadata.get('required', False) default_value = field_info.default if not is_required else ...

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/RadiumGu/alicloud-ops-mcp'

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