Skip to content

Conversation

@bokelley
Copy link
Contributor

Problem

AdCP client schema validation was rejecting the list_authorized_properties response because optional fields were being set to null instead of being completely omitted from the JSON.

Error messages:

  • primary_channels: Expected array, received null
  • primary_countries: Expected array, received null
  • portfolio_description: Expected string, received null
  • advertising_policies: Expected string, received null
  • last_updated: Expected string, received null
  • errors: Expected array, received null

The AdCP JSON schema expects optional fields to be either:

  1. Present with the correct type (array/string)
  2. Completely omitted from the JSON

It does NOT accept null values for these fields.

Root Cause

When FastMCP serializes Pydantic models, it may use Python's built-in dict() function which calls __iter__ instead of the model's model_dump() method. This resulted in all fields (including those with None values) being included in the response.

Solution

  1. Override __iter__() in ListAuthorizedPropertiesResponse to only yield non-None fields
  2. Override dict() method to use model_dump() with exclude_none=True
  3. Only pass non-None values when constructing the response object

These changes ensure optional fields are completely omitted from the JSON response rather than being present with null values, matching AdCP spec requirements.

Testing

  • ✅ Unit tests pass (837 passed)
  • ✅ Manual serialization testing confirms None values are excluded
  • ✅ Both dict(response) and response.model_dump() now exclude None fields

Files Changed

  • src/core/schema_adapters.py: Added __iter__ and dict method overrides
  • src/core/tools/properties.py: Only pass non-None values to response constructor

Problem:
- AdCP client validation rejected null values for optional fields
- Schema validation expected fields to be omitted, not set to null
- FastMCP was including None-valued fields in JSON response

Solution:
1. Override __iter__() in ListAuthorizedPropertiesResponse to exclude None values
2. Override dict() method to use model_dump() with exclude_none=True
3. Only pass non-None values when constructing response object

This ensures optional fields are completely omitted from the JSON response
rather than being present with null values, matching AdCP spec requirements.
@bokelley bokelley force-pushed the bokelley/fix-auth-props-schema branch from 663dc89 to 509dea5 Compare October 28, 2025 00:10
@bokelley bokelley merged commit 5afb6b5 into main Oct 28, 2025
9 checks passed
danf-newton pushed a commit to Newton-Research-Inc/salesagent that referenced this pull request Nov 24, 2025
…contextprotocol#647)

Problem:
- AdCP client validation rejected null values for optional fields
- Schema validation expected fields to be omitted, not set to null
- FastMCP was including None-valued fields in JSON response

Solution:
1. Override __iter__() in ListAuthorizedPropertiesResponse to exclude None values
2. Override dict() method to use model_dump() with exclude_none=True
3. Only pass non-None values when constructing response object

This ensures optional fields are completely omitted from the JSON response
rather than being present with null values, matching AdCP spec requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants