diff --git a/docs/cn/sdk_user_guide/mcp_gateway_user_guide.md b/docs/cn/sdk_user_guide/mcp_gateway_user_guide.md index 429c6d4..a8208bb 100644 --- a/docs/cn/sdk_user_guide/mcp_gateway_user_guide.md +++ b/docs/cn/sdk_user_guide/mcp_gateway_user_guide.md @@ -90,19 +90,17 @@ if list_result.success: #### 初始化 ```python -MCPGatewayClient(config: Optional[RequestConfig] = None) +MCPGatewayClient(verify_ssl: bool = True) ``` **参数说明**: | 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| -| config | RequestConfig | 否 | None | 请求配置对象 | +| verify_ssl | bool | 否 | True | 是否验证 SSL 证书 | **默认行为**: -- 如果未提供 `config`,将创建默认的 `RequestConfig` -- 如果未设置 `base_url`,客户端将使用控制平面端点 -- 默认禁用 SSL 验证 +- 默认启用 SSL 验证(verify_ssl=True) ### 网关管理方法 @@ -148,7 +146,6 @@ create_mcp_gateway( update_mcp_gateway( gateway_id: str, description: Optional[str] = None, - authorizer_configuration: Optional[Dict[str, Any]] = None, log_delivery_configuration: Optional[Dict[str, Any]] = None ) -> RequestResult ``` @@ -159,7 +156,6 @@ update_mcp_gateway( |------|------|------|--------|------| | gateway_id | str | 是 | - | 网关 ID | | description | str | 否 | None | 网关描述 | -| authorizer_configuration | Dict | 否 | None | 授权器配置 | | log_delivery_configuration | Dict | 否 | None | 日志投递配置 | **返回值**:`RequestResult` 对象 @@ -419,7 +415,7 @@ except Exception as e: **原因**:未提供任何更新参数。 **解决方案**: -确保至少提供一个更新参数(description、authorizer_configuration 等)。 +确保至少提供一个更新参数(description等)。 ### Q3: 如何选择授权器类型? diff --git a/src/agentarts/sdk/mcpgateway/mcp_gateway_client.py b/src/agentarts/sdk/mcpgateway/mcp_gateway_client.py index 84473ea..962d134 100644 --- a/src/agentarts/sdk/mcpgateway/mcp_gateway_client.py +++ b/src/agentarts/sdk/mcpgateway/mcp_gateway_client.py @@ -20,12 +20,11 @@ class MCPGatewayClient(BaseHTTPClient): Inherits from BaseHTTPClient to provide service-specific API methods. """ - def __init__(self, config: RequestConfig | None = None): - if config is None or (config.base_url is None or config.base_url == ""): - from agentarts.sdk.service.http_client import RequestConfig - if config is None: - config = RequestConfig() - config.base_url = f"{get_control_plane_endpoint()}/v1/core" + def __init__(self, verify_ssl: bool = True): + config = RequestConfig() + config.base_url = f"{get_control_plane_endpoint()}/v1/core" + config.verify_ssl = verify_ssl + self.verify_ssl = verify_ssl super().__init__(config, open_ak_sk=True) def create_mcp_gateway( @@ -65,7 +64,7 @@ def create_mcp_gateway( # Handle agency_name if not provided if agency_name is None: # Create IAM client - iam_client = IAMClient() + iam_client = IAMClient(verify_ssl=self.verify_ssl) # Agency configuration agency_name = "AgentArtsCoreGateway" @@ -135,7 +134,6 @@ def update_mcp_gateway( self, gateway_id: str, description: str | None = None, - authorizer_configuration: dict[str, Any] | None = None, log_delivery_configuration: dict[str, Any] | None = None ) -> RequestResult: """ @@ -144,7 +142,6 @@ def update_mcp_gateway( Args: gateway_id: Gateway ID description: Gateway description - authorizer_configuration: Authorizer configuration log_delivery_configuration: Log delivery configuration Returns: @@ -157,12 +154,10 @@ def update_mcp_gateway( # Validate that not all optional parameters are None if all(param is None for param in [ description, - authorizer_configuration, log_delivery_configuration ]): updateable_fields = [ "description", - "authorizer_configuration", "log_delivery_configuration" ] msg = f"At least one parameter must be provided for update. Available fields: {', '.join(updateable_fields)}" @@ -170,7 +165,6 @@ def update_mcp_gateway( payload = { "description": description, - "authorizer_configuration": authorizer_configuration, "log_delivery_configuration": log_delivery_configuration } diff --git a/src/agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py b/src/agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py index 8fe5f23..ad87ed5 100644 --- a/src/agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py +++ b/src/agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py @@ -25,11 +25,11 @@ def _parse_json(s: str | None) -> dict[str, Any] | None: raise ValueError(msg) -def _get_mcp_gateway_client(): +def _get_mcp_gateway_client(verify_ssl: bool = True): """Get MCP Gateway client""" from agentarts.sdk.mcpgateway import MCPGatewayClient - return MCPGatewayClient() + return MCPGatewayClient(verify_ssl=verify_ssl) def _format_output(data) -> str: @@ -61,6 +61,7 @@ def create_mcp_gateway( authorizer_configuration: Annotated[str | None, typer.Option("--authorizer-configuration", help="Authorizer configuration (JSON format)")] = None, log_delivery_configuration: Annotated[str | None, typer.Option("--log-delivery-configuration", help="Log delivery configuration (JSON format)")] = None, outbound_network_configuration: Annotated[str | None, typer.Option("--outbound-network-configuration", help="Outbound network configuration (JSON format)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Create a new MCP gateway @@ -73,7 +74,7 @@ def create_mcp_gateway( log_delivery_config = _parse_json(log_delivery_configuration) outbound_network_config = _parse_json(outbound_network_configuration) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.create_mcp_gateway( name=name, description=description, @@ -82,7 +83,7 @@ def create_mcp_gateway( agency_name=agency_name, authorizer_configuration=authorizer_config, log_delivery_configuration=log_delivery_config, - outbound_network_configuration=outbound_network_config, + outbound_network_configuration=outbound_network_config ) if result.success: @@ -100,8 +101,8 @@ def create_mcp_gateway( def update_mcp_gateway( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], description: Annotated[str | None, typer.Option("--description", "-d", help="Gateway description")] = None, - authorizer_configuration: Annotated[str | None, typer.Option("--authorizer-configuration", help="Authorizer configuration (JSON format)")] = None, log_delivery_configuration: Annotated[str | None, typer.Option("--log-delivery-configuration", help="Log delivery configuration (JSON format)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Update an existing MCP gateway @@ -110,14 +111,12 @@ def update_mcp_gateway( agentarts mcp-gateway update-mcp-gateway 123 --description "Updated description" """ try: - authorizer_config = _parse_json(authorizer_configuration) log_delivery_config = _parse_json(log_delivery_configuration) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.update_mcp_gateway( gateway_id=gateway_id, description=description, - authorizer_configuration=authorizer_config, log_delivery_configuration=log_delivery_config, ) @@ -135,6 +134,7 @@ def update_mcp_gateway( @mcp_gateway.command("delete-mcp-gateway") def delete_mcp_gateway( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Delete an MCP gateway @@ -148,7 +148,7 @@ def delete_mcp_gateway( echo_success("Deletion cancelled") return - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.delete_mcp_gateway(gateway_id=gateway_id) if result.success: @@ -162,6 +162,7 @@ def delete_mcp_gateway( @mcp_gateway.command("get-mcp-gateway") def get_mcp_gateway( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Get details of an MCP gateway @@ -170,7 +171,7 @@ def get_mcp_gateway( agentarts mcp-gateway get-mcp-gateway 123 """ try: - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.get_mcp_gateway(gateway_id=gateway_id) if result.success: @@ -189,6 +190,7 @@ def list_mcp_gateways( gateway_id: Annotated[str | None, typer.Option("--gateway-id", help="Gateway ID")] = None, limit: Annotated[int | None, typer.Option("--limit", help="Limit for pagination (default: 50, min: 1, max: 50)")] = None, offset: Annotated[int | None, typer.Option("--offset", help="Offset for pagination (default: 0, min: 0, max: 1000000)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ List MCP gateways @@ -215,7 +217,7 @@ def list_mcp_gateways( msg = "Limit must be less than or equal to 50" raise ValueError(msg) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.list_mcp_gateways( name=name, status=status, @@ -238,10 +240,11 @@ def list_mcp_gateways( @mcp_gateway.command("create-mcp-gateway-target") def create_mcp_gateway_target( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], + target_configuration: Annotated[str, typer.Option("--target-configuration", help="Target configuration (JSON format)")], name: Annotated[str | None, typer.Option("--name", "-n", help="Target name")] = None, description: Annotated[str | None, typer.Option("--description", "-d", help="Target description")] = None, - target_configuration: Annotated[str | None, typer.Option("--target-configuration", help="Target configuration (JSON format)")] = None, credential_provider_configuration: Annotated[str | None, typer.Option("--credential-provider-configuration", help="Credential provider configuration (JSON format)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Create a new MCP gateway target @@ -253,7 +256,7 @@ def create_mcp_gateway_target( target_config = _parse_json(target_configuration) credential_config = _parse_json(credential_provider_configuration) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.create_mcp_gateway_target( gateway_id=gateway_id, name=name, @@ -281,6 +284,7 @@ def update_mcp_gateway_target( description: Annotated[str | None, typer.Option("--description", "-d", help="Target description")] = None, target_configuration: Annotated[str | None, typer.Option("--target-configuration", help="Target configuration (JSON format)")] = None, credential_provider_configuration: Annotated[str | None, typer.Option("--credential-provider-configuration", help="Credential provider configuration (JSON format)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Update an existing MCP gateway target @@ -292,7 +296,7 @@ def update_mcp_gateway_target( target_config = _parse_json(target_configuration) credential_config = _parse_json(credential_provider_configuration) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.update_mcp_gateway_target( gateway_id=gateway_id, target_id=target_id, @@ -317,6 +321,7 @@ def update_mcp_gateway_target( def delete_mcp_gateway_target( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], target_id: Annotated[str, typer.Argument(help="Target ID")], + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Delete an MCP gateway target @@ -330,7 +335,7 @@ def delete_mcp_gateway_target( echo_success("Deletion cancelled") return - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.delete_mcp_gateway_target( gateway_id=gateway_id, target_id=target_id, @@ -348,6 +353,7 @@ def delete_mcp_gateway_target( def get_mcp_gateway_target( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], target_id: Annotated[str, typer.Argument(help="Target ID")], + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ Get details of an MCP gateway target @@ -356,7 +362,7 @@ def get_mcp_gateway_target( agentarts mcp-gateway get-mcp-gateway-target 123 456 """ try: - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.get_mcp_gateway_target( gateway_id=gateway_id, target_id=target_id, @@ -376,6 +382,7 @@ def list_mcp_gateway_targets( gateway_id: Annotated[str, typer.Argument(help="Gateway ID")], limit: Annotated[int | None, typer.Option("--limit", help="Limit for pagination (default: 50, min: 1, max: 50)")] = None, offset: Annotated[int | None, typer.Option("--offset", help="Offset for pagination (default: 0, min: 0, max: 1000000)")] = None, + skip_ssl_verification: Annotated[bool, typer.Option("--skip-ssl-verification", "-k", help="Skip SSL certificate verification")] = False, ): """ List MCP gateway targets @@ -402,7 +409,7 @@ def list_mcp_gateway_targets( msg = "Limit must be less than or equal to 50" raise ValueError(msg) - client = _get_mcp_gateway_client() + client = _get_mcp_gateway_client(verify_ssl=not skip_ssl_verification) result = client.list_mcp_gateway_targets( gateway_id=gateway_id, limit=limit, diff --git a/tests/unit/sdk/mcpgateway/test_mcp_gateway_http.py b/tests/unit/sdk/mcpgateway/test_mcp_gateway_http.py index 97be9cd..3a2c4f6 100644 --- a/tests/unit/sdk/mcpgateway/test_mcp_gateway_http.py +++ b/tests/unit/sdk/mcpgateway/test_mcp_gateway_http.py @@ -7,7 +7,7 @@ import pytest from agentarts.sdk.mcpgateway.mcp_gateway_client import MCPGatewayClient -from agentarts.sdk.service.http_client import RequestConfig, RequestResult +from agentarts.sdk.service.http_client import RequestResult class TestMCPGatewayClient: @@ -15,7 +15,7 @@ class TestMCPGatewayClient: def setup_method(self): """Setup test method""" - self.client = MCPGatewayClient(RequestConfig(base_url="http://test.example.com")) + self.client = MCPGatewayClient(verify_ssl=True) @patch("agentarts.sdk.mcpgateway.mcp_gateway_client.MCPGatewayClient.post") def test_create_mcp_gateway(self, mock_post): @@ -59,16 +59,15 @@ def test_update_mcp_gateway(self, mock_put): assert result.success mock_put.assert_called_once() - @pytest.mark.parametrize(("description", "authorizer_config", "log_config"), [ - (None, None, None), + @pytest.mark.parametrize(("description", "log_config"), [ + (None, None), ]) - def test_update_mcp_gateway_no_params(self, description, authorizer_config, log_config): + def test_update_mcp_gateway_no_params(self, description, log_config): """Test update_mcp_gateway with no parameters""" with pytest.raises(ValueError): self.client.update_mcp_gateway( gateway_id="123", description=description, - authorizer_configuration=authorizer_config, log_delivery_configuration=log_config ) diff --git a/tests/unit/sdk/mcpgateway/test_mcp_target_http.py b/tests/unit/sdk/mcpgateway/test_mcp_target_http.py index 51f1f4d..444c1f0 100644 --- a/tests/unit/sdk/mcpgateway/test_mcp_target_http.py +++ b/tests/unit/sdk/mcpgateway/test_mcp_target_http.py @@ -7,7 +7,7 @@ import pytest from agentarts.sdk.mcpgateway.mcp_gateway_client import MCPGatewayClient -from agentarts.sdk.service.http_client import RequestConfig, RequestResult +from agentarts.sdk.service.http_client import RequestResult class TestMCPGatewayClient: @@ -15,7 +15,7 @@ class TestMCPGatewayClient: def setup_method(self): """Setup test method""" - self.client = MCPGatewayClient(RequestConfig(base_url="http://test.example.com")) + self.client = MCPGatewayClient(verify_ssl=True) @patch("agentarts.sdk.mcpgateway.mcp_gateway_client.MCPGatewayClient.post") def test_create_mcp_gateway_target(self, mock_post):