Skip to content

Commit 4e68072

Browse files
committed
return a 404 instead of public card from extended card EP
1 parent 5750f5d commit 4e68072

File tree

2 files changed

+27
-58
lines changed

2 files changed

+27
-58
lines changed

src/a2a/server/apps/starlette_app.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,17 @@
1212
from starlette.responses import JSONResponse, Response
1313
from starlette.routing import Route
1414

15+
from a2a.server.context import ServerCallContext
1516
from a2a.server.request_handlers.jsonrpc_handler import JSONRPCHandler
1617
from a2a.server.request_handlers.request_handler import RequestHandler
17-
from a2a.server.context import ServerCallContext
18-
from a2a.types import (
19-
A2AError,
20-
A2ARequest,
21-
AgentCard,
22-
CancelTaskRequest,
23-
GetTaskPushNotificationConfigRequest,
24-
GetTaskRequest,
25-
InternalError,
26-
InvalidRequestError,
27-
JSONParseError,
28-
JSONRPCError,
29-
JSONRPCErrorResponse,
30-
JSONRPCResponse,
31-
SendMessageRequest,
32-
SendStreamingMessageRequest,
33-
SendStreamingMessageResponse,
34-
SetTaskPushNotificationConfigRequest,
35-
TaskResubscriptionRequest,
36-
UnsupportedOperationError,
37-
)
18+
from a2a.types import (A2AError, A2ARequest, AgentCard, CancelTaskRequest,
19+
GetTaskPushNotificationConfigRequest, GetTaskRequest,
20+
InternalError, InvalidRequestError, JSONParseError,
21+
JSONRPCError, JSONRPCErrorResponse, JSONRPCResponse,
22+
SendMessageRequest, SendStreamingMessageRequest,
23+
SendStreamingMessageResponse,
24+
SetTaskPushNotificationConfigRequest,
25+
TaskResubscriptionRequest, UnsupportedOperationError)
3826
from a2a.utils.errors import MethodNotImplementedError
3927

4028
logger = logging.getLogger(__name__)
@@ -80,6 +68,13 @@ def __init__(
8068
self.handler = JSONRPCHandler(
8169
agent_card=agent_card, request_handler=http_handler
8270
)
71+
if (
72+
self.agent_card.supportsAuthenticatedExtendedCard
73+
and self.extended_agent_card is None
74+
):
75+
logger.error(
76+
'AgentCard.supportsAuthenticatedExtendedCard is True, but no extended_agent_card was provided. The /agent/authenticatedExtendedCard endpoint will return 404.'
77+
)
8378
self._context_builder = context_builder
8479

8580
def _generate_error_response(
@@ -345,10 +340,12 @@ async def _handle_get_authenticated_extended_agent_card(
345340
mode='json', exclude_none=True
346341
)
347342
)
348-
# Otherwise, if supportsAuthenticatedExtendedCard is true but no specific
349-
# extended card is set, serve the main agent_card.
343+
# If supportsAuthenticatedExtendedCard is true, but no specific
344+
# extended_agent_card was provided during server initialization,
345+
# return a 404
350346
return JSONResponse(
351-
self.agent_card.model_dump(mode='json', exclude_none=True)
347+
{'error': 'Authenticated extended agent card is supported but not configured on the server.'},
348+
status_code=404,
352349
)
353350

354351
def routes(

tests/server/test_integration.py

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,14 @@
88
from starlette.testclient import TestClient
99

1010
from a2a.server.apps.starlette_app import A2AStarletteApplication
11-
from a2a.types import (
12-
AgentCapabilities,
13-
AgentCard,
14-
Artifact,
15-
DataPart,
16-
InternalError,
17-
InvalidRequestError,
18-
JSONParseError,
19-
Part,
20-
PushNotificationConfig,
21-
Task,
22-
TaskArtifactUpdateEvent,
23-
TaskPushNotificationConfig,
24-
TaskState,
25-
TaskStatus,
26-
TextPart,
27-
UnsupportedOperationError,
28-
)
11+
from a2a.types import (AgentCapabilities, AgentCard, Artifact, DataPart,
12+
InternalError, InvalidRequestError, JSONParseError,
13+
Part, PushNotificationConfig, Task,
14+
TaskArtifactUpdateEvent, TaskPushNotificationConfig,
15+
TaskState, TaskStatus, TextPart,
16+
UnsupportedOperationError)
2917
from a2a.utils.errors import MethodNotImplementedError
3018

31-
3219
# === TEST SETUP ===
3320

3421
MINIMAL_AGENT_SKILL: dict[str, Any] = {
@@ -151,21 +138,6 @@ def test_authenticated_extended_agent_card_endpoint_not_supported(
151138
assert response.status_code == 404 # Starlette's default for no route
152139

153140

154-
def test_authenticated_extended_agent_card_endpoint_supported_no_specific_extended_card(
155-
agent_card: AgentCard, handler: mock.AsyncMock
156-
):
157-
"""Test extended card endpoint returns main card if supported but no specific extended card is set."""
158-
agent_card.supportsAuthenticatedExtendedCard = True
159-
app_instance = A2AStarletteApplication(agent_card, handler)
160-
client = TestClient(app_instance.build())
161-
162-
response = client.get('/agent/authenticatedExtendedCard')
163-
assert response.status_code == 200
164-
data = response.json()
165-
assert data['name'] == agent_card.name # Should be the main agent card
166-
assert data['version'] == agent_card.version
167-
168-
169141
def test_authenticated_extended_agent_card_endpoint_supported_with_specific_extended_card(
170142
agent_card: AgentCard,
171143
extended_agent_card_fixture: AgentCard,

0 commit comments

Comments
 (0)