Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/adcp/server/a2a_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 8 additions & 5 deletions src/adcp/server/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
16 changes: 16 additions & 0 deletions tests/test_a2a_structured_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/test_mcp_structured_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
Loading