Commit 15b5395
fix: parse list_creative_formats response into structured type (#12)
* fix: parse list_creative_formats response into structured type
Problem: Creative agent returns text content instead of structured data
- Current: TextContent(text='Found 42 creative formats')
- Expected: ListCreativeFormatsResponse(formats=[Format(...), ...])
- Cause: Adapters return raw content without type parsing
Solution:
- Add response_parser.py with parse_mcp_content() and parse_json_or_text()
- Update list_creative_formats() to parse adapter responses
- Handle both MCP (content array) and A2A (dict) response formats
- Return properly typed ListCreativeFormatsResponse objects
- Gracefully handle invalid responses with clear error messages
Testing:
- Added 12 unit tests for response parser functions
- Added 3 integration tests for list_creative_formats parsing
- All 83 tests pass
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: define FormatId as proper object type per ADCP spec
Problem: FormatId was incorrectly defined as a string type alias,
but the ADCP spec requires it to be a structured object with
agent_url and id fields.
Root Cause: The format-id.json schema was missing from the downloaded
schemas, causing the type generator to create a placeholder string type.
Solution:
- Downloaded format-id.json schema from adcontextprotocol.org
- Defined FormatId as proper Pydantic model with agent_url and id fields
- Updated tests to use correct FormatId structure: {agent_url, id}
This ensures all format references use the structured format ID objects
as required by the ADCP specification, enabling proper format resolution
across different creative agents.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: move response parsing to adapter layer
Problem: Response parsing was only implemented for list_creative_formats,
leaving all other methods returning unparsed raw data.
Solution: Move parsing logic to adapter base class so ALL methods benefit:
1. Added _parse_response() helper in ProtocolAdapter base class
- Handles MCP content arrays and A2A dict responses
- Validates against expected Pydantic types
- Returns properly typed TaskResult
2. Added specific ADCP method declarations in base adapter
- get_products, list_creative_formats, sync_creatives, etc.
- Default implementations delegate to call_tool()
- Keeps adapters simple while enabling type-safe interface
3. Updated client to use specific adapter methods
- Calls adapter.list_creative_formats() instead of adapter.call_tool()
- Delegates parsing to adapter._parse_response()
- Removes duplicate parsing logic from client layer
Benefits:
- ALL ADCP methods now return properly typed responses
- Single parsing implementation shared across all methods
- Adapters handle protocol differences (MCP vs A2A)
- Client layer stays focused on business logic
- Type-safe interface prevents tool name typos
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* remove: delete call_tool generic fallback method
Remove the generic call_tool() method from adapters and client.
No fallbacks - every ADCP method must be explicitly implemented.
Changes:
- Removed call_tool() from ProtocolAdapter base class
- Renamed internal helpers: call_tool → _call_a2a_tool / _call_mcp_tool
- Removed call_tool() from ADCPClient
- Updated all tests to mock specific methods instead of call_tool
Benefits:
- Forces explicit implementation of every ADCP protocol method
- No magic "it might work" fallbacks that hide bugs
- Clear contract: adapters MUST implement all 9 ADCP methods
- Type-safe: impossible to typo a tool name
- Better tooling: IDE autocomplete knows all methods
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: address critical code review issues
Fixed 3 critical issues identified in code review:
1. FormatId Validation (CRITICAL)
- Added field_validator to enforce regex pattern ^[a-zA-Z0-9_-]+$
- Pattern parameter alone doesn't enforce validation in Pydantic v2
- Added 9 comprehensive validation tests
- Prevents invalid format IDs with spaces, special chars, unicode
2. Inconsistent Response Parsing (MAJOR BUG)
- Applied _parse_response() to ALL 9 client methods, not just one
- Methods now return properly typed TaskResult[SpecificResponse]
- Ensures MCP content arrays are parsed into structured objects
- Consistent behavior across all ADCP protocol methods
3. Test Data Validation
- Updated test_get_products to mock parsing separately
- Verifies parsing is called with correct response types
- All 92 tests pass (83 original + 9 new validation tests)
Impact:
- Type safety actually enforced, not just declared
- All responses properly parsed regardless of protocol (MCP/A2A)
- Invalid data caught at validation layer
- Consistent client behavior across all methods
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: auto-generate FormatId with validation in schema generation
Problem: CI failed because generated.py was manually edited but marked
as auto-generated. Schema validation check detected drift.
Root Cause:
- format-id.json schema was downloaded but not included in generation
- Generator hardcoded FormatId = str as fallback
- Manual edits violated "DO NOT EDIT" contract
Solution:
1. Add format-id.json to core_types list in generator
2. Remove hardcoded FormatId = str fallback
3. Add add_format_id_validation() post-processor
4. Auto-inject field_validator for pattern enforcement
5. Import re and field_validator in generated code
Result:
- generated.py now properly auto-generated with validation
- CI schema validation will pass
- FormatId validation maintained
- No manual edits required
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: normalize format-id.json formatting for CI
CI schema validation expects specific JSON formatting:
- Multiline "required" array
- Trailing newline at end of file
Ran scripts/fix_schema_refs.py to normalize formatting.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: remove unused imports to pass linter
CI linter detected unused imports:
- TaskStatus in src/adcp/client.py (leftover from refactoring)
- parse_mcp_content in src/adcp/protocols/mcp.py (unused after moving parsing to base)
Removed both unused imports. All tests still pass (92/92).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: apply linting and type checking fixes after local validation
- Auto-fix import ordering and remove unused imports
- Fix unused type:ignore comment in base.py
- Replace removed call_tool method in CLI with explicit dispatch
- Add _dispatch_tool helper with if/elif chain for mypy compatibility
- Fix line length issues (E501) in __main__.py
This commit demonstrates the lesson learned from the debugger analysis:
always run full validation (format + lint + typecheck + test) before
pushing to avoid sequential fix commits.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: restore inline Field formatting in generated.py for CI
The CI check-schema-drift target regenerates models without running
black formatter, so generated.py should remain in the inline format
that the generator outputs. Running `make format` reformats Field
definitions to multiline, causing CI drift detection to fail.
This commit reverts the black formatting of generated.py to match
what `make regenerate-schemas` produces.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: exclude generated.py from black formatting to prevent CI drift
Critical fix addressing code review feedback:
1. Add extend-exclude pattern to [tool.black] in pyproject.toml
- Prevents black from reformatting generated.py
- Uses regex pattern: /(generated|tasks)\.py$
2. Update Makefile format target documentation
- Clarifies that generated files are excluded
3. Format __main__.py (black auto-fix)
This prevents the schema drift CI failures that occur when:
- Developer runs `make format` (includes black)
- Black reformats generated.py Field definitions (multiline)
- CI runs `make check-schema-drift` (regenerates without formatting)
- Generator outputs inline format
- CI detects drift and fails
With this fix, black will skip generated.py entirely, keeping it
in the inline format that the generator produces.
Resolves: Code Review Critical Issue #2
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: implement code review suggestions for maintainability
Addresses remaining code review feedback from the reviewer agent:
1. CLI Dispatch Refactor (Suggestion #3)
- Replace if/elif chain with dict-based TOOL_DISPATCH mapping
- Single source of truth for available tools
- Lazy initialization of request types to avoid circular imports
- Easier to maintain and extend
2. Pydantic Validation Error Handling (Edge Case #6)
- Catch ValidationError in _dispatch_tool()
- Return user-friendly error messages showing field-level issues
- Format: "Invalid request payload for {tool}:\n - field: message"
3. Response Parser Error Context (Suggestion #4)
- Add content preview to parse_mcp_content() error messages
- Include first 2 items, max 500 chars for debugging
- Helps diagnose real-world parsing failures
4. Adapter Response Parsing Edge Case (Edge Case #7)
- Fix _parse_response() to explicitly construct TaskResult[T]
- Handle success=False or data=None without type: ignore
- Provide clear error message when data is missing
Benefits:
- Maintainability: CLI tool list in one place, easier to add new ADCP methods
- User Experience: Clear validation errors instead of Python tracebacks
- Debuggability: Content preview helps diagnose parsing issues
- Type Safety: Proper typed TaskResult construction without suppressions
All tests pass (92/92), linting and type checking clean.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat: implement high-priority protocol expert recommendations
Addresses protocol expert feedback for production readiness:
1. **Webhook Response Typing** (High Priority #1)
- handle_webhook() now returns TaskResult[Any] instead of None
- Added _parse_webhook_result() helper method
- Maps webhook task_type to response types for type-safe parsing
- Validates WebhookPayload schema with Pydantic
- Example usage:
```python
result = await client.handle_webhook(payload, signature)
if result.success and isinstance(result.data, GetProductsResponse):
print(f"Found {len(result.data.products)} products")
```
2. **ProtocolEnvelope Type** (High Priority #2)
- Already auto-generated from schema (protocol-envelope.json)
- Includes: context_id, task_id, status, message, timestamp, payload
- Used for async operation responses
- No code changes needed - type already exists
3. **Format Caching Documentation** (High Priority #3)
- Added comprehensive caching guidance to CLAUDE.md
- Documented TTL-based and LRU cache strategies
- Explained cache invalidation options
- Provided code examples for production implementations
Benefits:
- Type-safe webhook handling enables better error detection
- Structured webhook responses integrate with existing TaskResult pattern
- Production developers have clear caching guidance
- All async workflows now properly typed
All tests pass (92/92), linting and type checking clean.
Resolves: Protocol Expert High Priority Issues #1, #2, #3
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent a75d9f9 commit 15b5395
File tree
20 files changed
+1505
-277
lines changed- schemas/cache/1.0.0
- scripts
- src/adcp
- protocols
- types
- utils
- tests
20 files changed
+1505
-277
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
98 | 142 | | |
99 | 143 | | |
100 | 144 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | | - | |
| 22 | + | |
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
41 | 45 | | |
42 | | - | |
43 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
226 | 290 | | |
227 | 291 | | |
228 | 292 | | |
| |||
233 | 297 | | |
234 | 298 | | |
235 | 299 | | |
| 300 | + | |
236 | 301 | | |
237 | 302 | | |
238 | 303 | | |
| |||
294 | 359 | | |
295 | 360 | | |
296 | 361 | | |
| 362 | + | |
297 | 363 | | |
298 | 364 | | |
299 | | - | |
| 365 | + | |
300 | 366 | | |
301 | 367 | | |
302 | 368 | | |
| |||
305 | 371 | | |
306 | 372 | | |
307 | 373 | | |
308 | | - | |
309 | 374 | | |
310 | 375 | | |
311 | 376 | | |
| |||
353 | 418 | | |
354 | 419 | | |
355 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
356 | 424 | | |
357 | 425 | | |
358 | 426 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | | - | |
| 78 | + | |
| 79 | + | |
77 | 80 | | |
78 | 81 | | |
79 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
80 | 179 | | |
81 | 180 | | |
82 | 181 | | |
| |||
0 commit comments