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
16 changes: 15 additions & 1 deletion src/a2a/client/client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _register_defaults(
if GrpcTransport is None:
raise ImportError(
'To use GrpcClient, its dependencies must be installed. '
'You can install them with \'pip install "a2a-sdk[grpc]"\''
'You can install them with \'pip install "a2a-sdk[grpc]"\'',
)
self.register(
TransportProtocol.grpc,
Expand Down Expand Up @@ -124,6 +124,20 @@ def create(
If there is no valid matching of the client configuration with the
server configuration, a `ValueError` is raised.
"""
valid_transports = {member.value for member in TransportProtocol}
configured_transports = set(self._config.supported_transports)

invalid_transports = configured_transports.difference(valid_transports)
if invalid_transports:
invalid_str = ', '.join(
sorted(f"'{t}'" for t in invalid_transports)
)
valid_str = ', '.join(sorted(valid_transports))
raise ValueError(
f'Unsupported transport type(s) in ClientConfig: {invalid_str}. '
f'Valid types are: {valid_str}'
)

server_preferred = card.preferred_transport or TransportProtocol.jsonrpc
server_set = {server_preferred: card.url}
if card.additional_interfaces:
Expand Down
29 changes: 29 additions & 0 deletions tests/client/test_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,32 @@ def test_client_factory_no_compatible_transport(base_agent_card: AgentCard):
factory = ClientFactory(config)
with pytest.raises(ValueError, match='no compatible transports found'):
factory.create(base_agent_card)


@pytest.mark.parametrize(
('invalid_transports', 'expected_match'),
[
(
['invalid-transport'],
"Unsupported transport type\\(s\\) in ClientConfig: 'invalid-transport'",
),
(
['invalid-1', 'another-bad-one'],
"Unsupported transport type\\(s\\) in ClientConfig: 'another-bad-one', 'invalid-1'",
),
],
)
def test_client_factory_invalid_transport_in_config(
base_agent_card: AgentCard, invalid_transports, expected_match
):
"""Verify that the factory raises an error for unknown transport types."""
config = ClientConfig(
httpx_client=httpx.AsyncClient(),
supported_transports=[
TransportProtocol.jsonrpc,
*invalid_transports,
],
)
factory = ClientFactory(config)
with pytest.raises(ValueError, match=expected_match):
factory.create(base_agent_card)
Loading