fix(webhooks): promote McpWebhookPayload.token from extras shim to typed field#835
Merged
Merged
Conversation
…ped field Upstream adcontextprotocol/adcp#4339 added token as a typed field in mcp-webhook-payload.json. The generated type already has the field; remove the additionalProperties round-trip shim from create_mcp_webhook_payload and wire token directly like any other typed kwarg. Wire shape is unchanged — adopters reading to_wire_dict() output see no difference. Adopters using payload.token now get typed attribute access instead of model_extra["token"]. Closes #638
This was referenced May 23, 2026
There was a problem hiding this comment.
LGTM. Follow-ups noted below. The extras→typed promotion is the right shape: wire output is byte-identical for valid inputs, and the construction-time tightening just enforces what push-notification-config.json already required at registration.
Things I checked
- Wire parity:
to_wire_dictusesmodel_dump(mode="json", exclude_none=True)(src/adcp/webhooks.py:1884), sotoken=Nonestill drops out of the wire dict and a supplied token serializes at the same JSON path it did under the old extras path. The newtest_token_is_typed_field_not_model_extraasserts hand-built vs typed-kwarg parity attests/test_webhooks_to_wire_dict.py:268-277. - Generated field matches upstream:
token: Annotated[str | None, Field(max_length=4096, min_length=16)] = Noneatsrc/adcp/types/generated_poc/core/mcp_webhook_payload.py:84-91. Bounds mirror the sender-sidepush_notification_config.tokenatpush_notification_config.py:52-57— spec text explicitly says "Length bounds mirror the config-side field," so SDK-side enforcement is the publisher obligation the schema describes. extra='allow'is still set on the model (mcp_webhook_payload.py:19), so other unknown adopter-side keys continue to round-trip — this isn't a wholesale lockdown, just promoting one field.- No other call sites in
src/adcp/readmodel_extra["token"]onMcpWebhookPayload.src/adcp/webhook_sender.py:590-602already passestokenas a typed kwarg. - Receiver side is unaffected:
verify_webhook_signature/verify_webhook_hmacoperate on raw bytes, not the parsed model, so the typed-vs-extras distinction is invisible to verification. - Layering check: tests file imports
McpWebhookPayloadfromadcp.types.generated_poc.core.mcp_webhook_payload— pre-existing and the layering test (tests/test_import_layering.py) scopesSRC_ROOT.rglobonly, so test imports are out of scope. Not introduced here. - Asymmetry with the legacy
_inject_push_tokenpath atwebhooks.py:1941-1965is intentional — that path covers non-MCP generic webhook bodies which remain free-form.
Follow-ups (non-blocking — file as issues)
- No test asserts a sub-16-char token raises
ValidationErrorat construction. Themin_length=16enforcement is the one new runtime behavior; worth a one-line regression guard. PR body already flagged this. create_mcp_webhook_payloaddocstring (src/adcp/webhooks.py:170-171) doesn't surface the 16-char minimum — callers would have to dive into the generated model to find it.ad-tech-protocol-expertraised the open question of whether the JS SDK applies the sameminLength: 16at construction post-#4339, or only at the receiver. Asymmetric enforcement across SDKs would create an interop trap. Worth confirming before adopters cross-wire.
LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #638
Upstream
adcontextprotocol/adcp#4339promotedtokenfrom an undocumentedadditionalPropertiesround-trip to a typed field inmcp-webhook-payload.json. The generated type already hastoken: Annotated[str | None, Field(max_length=4096, min_length=16)] = None(regenerated 2026-05-22). This PR removes the extras shim fromcreate_mcp_webhook_payloadand wirestokendirectly as a typed kwarg.Wire shape is unchanged — adopters reading
to_wire_dict()output see no difference. Adopters usingpayload.tokennow get typed attribute access instead ofmodel_extra["token"], andMcpWebhookPayload.model_fieldsnow includestoken.Note:
min_length=16is now enforced at construction time on the typed field. Under the old extras-bag path no length validation ran, butpush-notification-config.jsonalready enforcesminLength: 16on the buyer side — any token shorter than 16 chars was already schema-invalid at registration. This is a correct tightening, not a latent break.What changed
src/adcp/webhooks.py: removed theextras: dict[str, Any]shim block;"token": tokenis now passed directly in themodel_validatecall like every other typed field.tests/test_webhooks_to_wire_dict.py: addedtest_token_is_typed_field_not_model_extra(checksmodel_fields, attribute access, wire parity) andtest_token_none_omitted_from_wire.What was tested
pytest tests/test_webhooks_to_wire_dict.py— 13/13 passed (2 new)pytest tests/test_webhook_handling.py tests/test_webhooks_deliver.py— 140 passed, 15 skippedruff check src/adcp/webhooks.py tests/test_webhooks_to_wire_dict.py— all checks passedmypy src/adcp/webhooks.py— no issues foundNits (not fixed, noted for reviewer):
create_mcp_webhook_payloaddocstring for thetokenkwarg could mentionpayload.tokennow provides direct typed attribute access (dx-expert nit).test_webhooks_to_wire_dict.pyalready importsMcpWebhookPayloadfrom the internal generated path (adcp.types.generated_poc…) rather thanadcp.types— pre-existing, not introduced here; layering test still passes.min_length=16rejection path for token; follow-on candidate.Pre-PR review
Session: https://claude.ai/code/session_013qBwgszbHTYiy5PZdgCAQm