From 73bd270948ee60ff6045757ebffc447ae569924d Mon Sep 17 00:00:00 2001 From: julien bonnier Date: Tue, 20 Jan 2026 16:18:25 -0500 Subject: [PATCH 1/4] Update invocation metadata from grpc.aio.ServicerContext to use the correct syntax --- src/a2a/server/request_handlers/grpc_handler.py | 6 ++---- tests/server/request_handlers/test_grpc_handler.py | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/a2a/server/request_handlers/grpc_handler.py b/src/a2a/server/request_handlers/grpc_handler.py index e2ec69a15..b3810cba9 100644 --- a/src/a2a/server/request_handlers/grpc_handler.py +++ b/src/a2a/server/request_handlers/grpc_handler.py @@ -53,13 +53,11 @@ def build(self, context: grpc.aio.ServicerContext) -> ServerCallContext: def _get_metadata_value( context: grpc.aio.ServicerContext, key: str ) -> list[str]: - md = context.invocation_metadata + md = context.invocation_metadata() raw_values: list[str | bytes] = [] if isinstance(md, Metadata): raw_values = md.get_all(key) - elif isinstance(md, Sequence): - lower_key = key.lower() - raw_values = [e for (k, e) in md if k.lower() == lower_key] + return [e if isinstance(e, str) else e.decode('utf-8') for e in raw_values] diff --git a/tests/server/request_handlers/test_grpc_handler.py b/tests/server/request_handlers/test_grpc_handler.py index 26f923c14..5c7e26ef1 100644 --- a/tests/server/request_handlers/test_grpc_handler.py +++ b/tests/server/request_handlers/test_grpc_handler.py @@ -321,7 +321,7 @@ async def test_send_message_with_extensions( mock_request_handler: AsyncMock, mock_grpc_context: AsyncMock, ) -> None: - mock_grpc_context.invocation_metadata = grpc.aio.Metadata( + mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata( (HTTP_EXTENSION_HEADER, 'foo'), (HTTP_EXTENSION_HEADER, 'bar'), ) @@ -361,7 +361,7 @@ async def test_send_message_with_comma_separated_extensions( mock_request_handler: AsyncMock, mock_grpc_context: AsyncMock, ) -> None: - mock_grpc_context.invocation_metadata = grpc.aio.Metadata( + mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata( (HTTP_EXTENSION_HEADER, 'foo ,, bar,'), (HTTP_EXTENSION_HEADER, 'baz , bar'), ) @@ -386,7 +386,7 @@ async def test_send_streaming_message_with_extensions( mock_request_handler: AsyncMock, mock_grpc_context: AsyncMock, ) -> None: - mock_grpc_context.invocation_metadata = grpc.aio.Metadata( + mock_grpc_context.invocation_metadata.return_value = grpc.aio.Metadata( (HTTP_EXTENSION_HEADER, 'foo'), (HTTP_EXTENSION_HEADER, 'bar'), ) From 674084a5ea6989b8ca6f31844bec6d406637eae2 Mon Sep 17 00:00:00 2001 From: jubonni <43730513+jubonni@users.noreply.github.com> Date: Tue, 20 Jan 2026 16:48:41 -0500 Subject: [PATCH 2/4] Update src/a2a/server/request_handlers/grpc_handler.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- src/a2a/server/request_handlers/grpc_handler.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/a2a/server/request_handlers/grpc_handler.py b/src/a2a/server/request_handlers/grpc_handler.py index b3810cba9..5b761db9d 100644 --- a/src/a2a/server/request_handlers/grpc_handler.py +++ b/src/a2a/server/request_handlers/grpc_handler.py @@ -54,9 +54,7 @@ def _get_metadata_value( context: grpc.aio.ServicerContext, key: str ) -> list[str]: md = context.invocation_metadata() - raw_values: list[str | bytes] = [] - if isinstance(md, Metadata): - raw_values = md.get_all(key) + raw_values: list[str | bytes] = md.get_all(key) if isinstance(md, Metadata) else [] return [e if isinstance(e, str) else e.decode('utf-8') for e in raw_values] From f1e5d0af4213ce80253689afbc7b38c7ee4a9f27 Mon Sep 17 00:00:00 2001 From: julien bonnier Date: Tue, 20 Jan 2026 16:51:40 -0500 Subject: [PATCH 3/4] Remove unused import --- src/a2a/server/request_handlers/grpc_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/a2a/server/request_handlers/grpc_handler.py b/src/a2a/server/request_handlers/grpc_handler.py index 5b761db9d..dedc57a28 100644 --- a/src/a2a/server/request_handlers/grpc_handler.py +++ b/src/a2a/server/request_handlers/grpc_handler.py @@ -3,7 +3,7 @@ import logging from abc import ABC, abstractmethod -from collections.abc import AsyncIterable, Sequence +from collections.abc import AsyncIterable try: From 13df32598aae0d142fcb6864cae016be99b497fe Mon Sep 17 00:00:00 2001 From: julien bonnier Date: Wed, 21 Jan 2026 08:54:07 -0500 Subject: [PATCH 4/4] Ran ruff --- src/a2a/server/request_handlers/grpc_handler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/a2a/server/request_handlers/grpc_handler.py b/src/a2a/server/request_handlers/grpc_handler.py index dedc57a28..20774001c 100644 --- a/src/a2a/server/request_handlers/grpc_handler.py +++ b/src/a2a/server/request_handlers/grpc_handler.py @@ -54,7 +54,9 @@ def _get_metadata_value( context: grpc.aio.ServicerContext, key: str ) -> list[str]: md = context.invocation_metadata() - raw_values: list[str | bytes] = md.get_all(key) if isinstance(md, Metadata) else [] + raw_values: list[str | bytes] = ( + md.get_all(key) if isinstance(md, Metadata) else [] + ) return [e if isinstance(e, str) else e.decode('utf-8') for e in raw_values]