diff --git a/src/adcp/server/a2a_server.py b/src/adcp/server/a2a_server.py index 4b837d6907..a6d42afc5e 100644 --- a/src/adcp/server/a2a_server.py +++ b/src/adcp/server/a2a_server.py @@ -839,7 +839,9 @@ async def _send_adcp_error( if details: adcp_error["details"] = dict(details) - data: dict[str, Any] = {"adcp_error": adcp_error} + # A fatal failure populates both layers (L3 error handling): the payload + # carries the protocol-neutral ``errors[]`` and the envelope ``adcp_error``. + data: dict[str, Any] = {"adcp_error": adcp_error, "errors": [dict(adcp_error)]} if params is not None: inject_context(params, data) diff --git a/src/adcp/server/translate.py b/src/adcp/server/translate.py index a48029497b..e18b30cc7e 100644 --- a/src/adcp/server/translate.py +++ b/src/adcp/server/translate.py @@ -204,10 +204,11 @@ def build_mcp_error_result( The framework dispatcher returns this when a platform method raises a structured AdCP error. The result has ``isError=True`` AND - ``structuredContent={"adcp_error": {...}}`` on the same envelope — - matching the spec's transport-errors.mdx §MCP Binding shape that the - storyboard runner's ``/adcp_error/code`` JSON-pointer assertion - expects. + ``structuredContent={"adcp_error": {...}, "errors": [{...}]}`` on the + same envelope — the transport-errors.mdx §MCP Binding ``adcp_error`` + plus the payload ``errors[]`` that L3 error handling says a fatal + failure SHOULD also carry (storyboards read both ``/adcp_error/code`` + and ``errors[0].field``). The text fallback in ``content[]`` preserves human-readable display for clients that do not consume ``structuredContent`` (LLM tool-use @@ -260,7 +261,9 @@ def build_mcp_error_result( if suggestion: text += f"\nSuggestion: {suggestion}" - structured: dict[str, Any] = {"adcp_error": adcp_error} + # A fatal failure populates both layers (L3 error handling): the payload + # carries the protocol-neutral ``errors[]`` and the envelope ``adcp_error``. + structured: dict[str, Any] = {"adcp_error": adcp_error, "errors": [dict(adcp_error)]} if params is not None: inject_context(params, structured) diff --git a/tests/test_a2a_structured_error.py b/tests/test_a2a_structured_error.py index 4aefd05bea..7044566bf0 100644 --- a/tests/test_a2a_structured_error.py +++ b/tests/test_a2a_structured_error.py @@ -416,6 +416,22 @@ async def test_request_context_echoes_into_error_envelope() -> None: assert payload.get("context") == request_context +@pytest.mark.asyncio +async def test_error_payload_mirrors_adcp_error_into_errors_array() -> None: + """A2A fills both layers like MCP: payload ``errors[]`` and ``adcp_error`` (#1558).""" + handler = _DecisioningRaiser( + lambda: DecisioningAdcpError("INVALID_REQUEST", message="bad", field="packages[0]") + ) + executor = _executor(handler) + queue = EventQueue() + + await executor.execute(_request_context("get_products", {}), queue) + + payload = _adcp_error_full_payload(await queue.dequeue_event()) + assert payload["errors"] == [payload["adcp_error"]] + assert payload["errors"][0]["field"] == "packages[0]" + + @pytest.mark.asyncio async def test_no_request_context_omits_context_from_error_envelope() -> None: """When the request carries no ``context`` field, the error DataPart diff --git a/tests/test_mcp_structured_error.py b/tests/test_mcp_structured_error.py index 726328b304..edb0783de5 100644 --- a/tests/test_mcp_structured_error.py +++ b/tests/test_mcp_structured_error.py @@ -67,6 +67,24 @@ def test_text_fallback_present_in_content(self): assert "no such buy" in result.content[0].text +class TestBuildMcpErrorResultErrorsArray: + """A fatal failure fills payload ``errors[]`` and envelope ``adcp_error`` (#1558).""" + + def test_errors_array_mirrors_adcp_error(self): + exc = DecisioningAdcpError( + "INVALID_REQUEST", message="unknown signal", field="packages[0].targeting_overlay" + ) + structured = build_mcp_error_result(exc).structured_content + assert structured["errors"] == [structured["adcp_error"]] + assert structured["errors"][0]["field"] == "packages[0].targeting_overlay" + + def test_errors_array_is_not_the_same_object_as_adcp_error(self): + structured = build_mcp_error_result( + DecisioningAdcpError("INTERNAL_ERROR") + ).structured_content + assert structured["errors"][0] is not structured["adcp_error"] + + class TestBuildMcpErrorResultOptionalFields: """Optional fields populate when present, omit when absent."""