Skip to content

Support custom endpoint domain for HCSO / on-premise deployments #137

@filhocf

Description

@filhocf

Problem

The current implementation in assets/utils/hwc_tools.py (create_api_client function) hardcodes the endpoint domain to myhuaweicloud.com based on the x-host field from OpenAPI JSON files:

def create_api_client(ak, sk, x_host, region="cn-north-4"):
    endpoint = x_host
    if x_host.find("com") != -1:
        endpoint = f"https://{x_host}"
    if endpoint.find("{region}") != -1:
        endpoint = endpoint.replace("{region}", region)

This works for the public Huawei Cloud, but does not work for Huawei Cloud Stack Online (HCSO) on-premise deployments, where the API endpoints use a different domain (e.g., {service}.{region}.customer-domain.com instead of {service}.{region}.myhuaweicloud.com).

Use Case

We are running HCSO on-premise with:

  • Region: la-south-6001
  • Console: https://console.hcso.customer-domain.com
  • API endpoints follow a different domain pattern than myhuaweicloud.com

When we try to use the MCP server, it constructs URLs like https://ecs.la-south-6001.myhuaweicloud.com which are unreachable from our on-premise environment.

Proposed Solution

Add support for a custom endpoint domain via:

  1. Environment variable HUAWEI_ENDPOINT_DOMAIN (highest priority):

    export HUAWEI_ENDPOINT_DOMAIN="hcso.customer-domain.com"
    # Result: https://ecs.la-south-6001.hcso.customer-domain.com
  2. Config YAML endpoint_domain field:

    service_code: ecs
    transport: stdio
    endpoint_domain: hcso.customer-domain.com
  3. Full endpoint override HUAWEI_ENDPOINT_OVERRIDE for cases where the URL pattern is completely different:

    export HUAWEI_ENDPOINT_OVERRIDE="https://ecs.custom-endpoint.com"

Implementation Sketch

In hwc_tools.py:

def create_api_client(ak, sk, x_host, region="cn-north-4"):
    # Check for full endpoint override
    endpoint_override = os.environ.get("HUAWEI_ENDPOINT_OVERRIDE")
    if endpoint_override:
        endpoint = endpoint_override
    else:
        endpoint = x_host
        # Check for custom domain
        custom_domain = os.environ.get("HUAWEI_ENDPOINT_DOMAIN")
        if custom_domain and "myhuaweicloud.com" in endpoint:
            endpoint = endpoint.replace("myhuaweicloud.com", custom_domain)
        if endpoint.find("com") != -1 or endpoint.find(custom_domain or "") != -1:
            endpoint = f"https://{endpoint}"
        if endpoint.find("{region}") != -1:
            endpoint = endpoint.replace("{region}", region)
    # ...

In model.py, add endpoint_domain to MCPConfig:

@dataclass
class MCPConfig:
    port: int
    service_code: str
    transport: TransportType
    ak: Optional[str] = None
    sk: Optional[str] = None
    endpoint_domain: Optional[str] = None

Additional Context

  • The huaweicloudsdkcore SDK supports custom regions/endpoints via Region(id=region, endpoint=endpoint), so the SDK itself is compatible
  • SSL verification may need to be configurable for on-premise deployments with self-signed certificates (currently hardcoded to ignore_ssl_verification = True, which is fine)
  • This would also benefit users in restricted network environments or those using Huawei Cloud through proxies

Environment

  • huaweicloud-mcp-server v0.3.0
  • Python 3.10+
  • HCSO on-premise deployment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions