Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 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,14 @@ 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}
for transport in self._config.supported_transports:
if transport not in valid_transports:
raise ValueError(
f"Unsupported transport type in ClientConfig: '{transport}'. "
f'Valid types are: {", ".join(sorted(valid_transports))}',
)
Comment thread
pankaj-bind marked this conversation as resolved.
Outdated

server_preferred = card.preferred_transport or TransportProtocol.jsonrpc
server_set = {server_preferred: card.url}
if card.additional_interfaces:
Expand Down
16 changes: 16 additions & 0 deletions tests/client/test_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,19 @@ 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)


def test_client_factory_invalid_transport_in_config(base_agent_card: AgentCard):
"""Verify that the factory raises an error for an unknown transport type."""
config = ClientConfig(
httpx_client=httpx.AsyncClient(),
supported_transports=[
TransportProtocol.jsonrpc,
'invalid-transport-protocol',
],
)
factory = ClientFactory(config)
with pytest.raises(
ValueError, match='Unsupported transport type in ClientConfig'
):
factory.create(base_agent_card)
Comment thread
pankaj-bind marked this conversation as resolved.
Outdated
Loading