Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions docs/cn/sdk_user_guide/mcp_gateway_user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

### 网关管理方法

Expand Down Expand Up @@ -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
```
Expand All @@ -159,7 +156,6 @@ update_mcp_gateway(
|------|------|------|--------|------|
| gateway_id | str | 是 | - | 网关 ID |
| description | str | 否 | None | 网关描述 |
| authorizer_configuration | Dict | 否 | None | 授权器配置 |
| log_delivery_configuration | Dict | 否 | None | 日志投递配置 |

**返回值**:`RequestResult` 对象
Expand Down Expand Up @@ -419,7 +415,7 @@ except Exception as e:
**原因**:未提供任何更新参数。

**解决方案**:
确保至少提供一个更新参数(description、authorizer_configuration 等)。
确保至少提供一个更新参数(description等)。

### Q3: 如何选择授权器类型?

Expand Down
18 changes: 6 additions & 12 deletions src/agentarts/sdk/mcpgateway/mcp_gateway_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
"""
Expand All @@ -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:
Expand All @@ -157,20 +154,17 @@ 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)}"
raise ValueError(msg)

payload = {
"description": description,
"authorizer_configuration": authorizer_configuration,
"log_delivery_configuration": log_delivery_configuration
}

Expand Down
41 changes: 24 additions & 17 deletions src/agentarts/toolkit/cli/mcp_gateway/mcp_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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,
)

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down
11 changes: 5 additions & 6 deletions tests/unit/sdk/mcpgateway/test_mcp_gateway_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
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:
"""Test MCP Gateway HTTP client"""

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):
Expand Down Expand Up @@ -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
)

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/sdk/mcpgateway/test_mcp_target_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
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:
"""Test MCP Gateway client"""

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):
Expand Down
Loading