From 2b790421740c24ba91f27a23d6127d421ee8215b Mon Sep 17 00:00:00 2001 From: Martim Santos Date: Sun, 6 Jul 2025 16:05:28 +0000 Subject: [PATCH 1/3] improve and simplify jsonrpc fastapi app --- src/a2a/server/apps/jsonrpc/fastapi_app.py | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/a2a/server/apps/jsonrpc/fastapi_app.py b/src/a2a/server/apps/jsonrpc/fastapi_app.py index 9e1e396d..049171bd 100644 --- a/src/a2a/server/apps/jsonrpc/fastapi_app.py +++ b/src/a2a/server/apps/jsonrpc/fastapi_app.py @@ -70,21 +70,13 @@ def add_routes_to_app( extended_agent_card_url: The URL for the authenticated extended agent card endpoint. """ - @app.post(rpc_url) - async def handle_a2a_request(request: Request) -> Response: - return await self._handle_requests(request) - - @app.get(agent_card_url) - async def get_agent_card(request: Request) -> Response: - return await self._handle_get_agent_card(request) - + app.get(agent_card_url)(self._handle_get_agent_card) + app.post(rpc_url)(self._handle_requests) + if self.agent_card.supportsAuthenticatedExtendedCard: - - @app.get(extended_agent_card_url) - async def get_extended_agent_card(request: Request) -> Response: - return await self._handle_get_authenticated_extended_agent_card( - request - ) + app.get(extended_agent_card_url)( + self._handle_get_authenticated_extended_agent_card + ) def build( self, From c4b6eea41b5bfea549e4d767c5268adfd3306225 Mon Sep 17 00:00:00 2001 From: Martim Santos Date: Sun, 6 Jul 2025 16:19:05 +0000 Subject: [PATCH 2/3] re-ordered routes --- src/a2a/server/apps/jsonrpc/fastapi_app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/a2a/server/apps/jsonrpc/fastapi_app.py b/src/a2a/server/apps/jsonrpc/fastapi_app.py index 049171bd..622e91c9 100644 --- a/src/a2a/server/apps/jsonrpc/fastapi_app.py +++ b/src/a2a/server/apps/jsonrpc/fastapi_app.py @@ -70,8 +70,8 @@ def add_routes_to_app( extended_agent_card_url: The URL for the authenticated extended agent card endpoint. """ - app.get(agent_card_url)(self._handle_get_agent_card) app.post(rpc_url)(self._handle_requests) + app.get(agent_card_url)(self._handle_get_agent_card) if self.agent_card.supportsAuthenticatedExtendedCard: app.get(extended_agent_card_url)( From c9a8d1d3af136e9762c8fc533eaf350dbef3f985 Mon Sep 17 00:00:00 2001 From: Martim Santos Date: Sun, 6 Jul 2025 18:03:58 +0000 Subject: [PATCH 3/3] linting --- src/a2a/server/apps/jsonrpc/fastapi_app.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/a2a/server/apps/jsonrpc/fastapi_app.py b/src/a2a/server/apps/jsonrpc/fastapi_app.py index 622e91c9..6dd15dcd 100644 --- a/src/a2a/server/apps/jsonrpc/fastapi_app.py +++ b/src/a2a/server/apps/jsonrpc/fastapi_app.py @@ -2,7 +2,7 @@ from typing import Any -from fastapi import FastAPI, Request, Response +from fastapi import FastAPI from a2a.server.apps.jsonrpc.jsonrpc_app import ( CallContextBuilder, @@ -69,10 +69,9 @@ def add_routes_to_app( rpc_url: The URL for the A2A JSON-RPC endpoint. extended_agent_card_url: The URL for the authenticated extended agent card endpoint. """ - app.post(rpc_url)(self._handle_requests) app.get(agent_card_url)(self._handle_get_agent_card) - + if self.agent_card.supportsAuthenticatedExtendedCard: app.get(extended_agent_card_url)( self._handle_get_authenticated_extended_agent_card