Commit 6b60365
fix: handle Pydantic TextContent objects in MCP response parser (#14)
* fix: handle Pydantic TextContent objects in MCP response parser
The MCP SDK returns Pydantic TextContent objects, not plain dicts.
The response_parser.py was using .get() method which only works on dicts,
causing AttributeError: 'TextContent' object has no attribute 'get'.
This change adds a helper function that handles both dict and Pydantic
object access patterns, ensuring compatibility with both the MCP SDK's
actual return types and the test suite's mock dicts.
Tests added for:
- Pydantic TextContent objects
- Mixed dict and Pydantic content
- Empty Pydantic text content handling
Fixes regression introduced in v1.0.3 where parsing logic was added
that assumed dict objects.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* refactor: move MCP serialization to protocol boundary
This refactor addresses the architectural issue identified in code review:
the response parser was handling both parsing AND protocol translation,
violating single responsibility principle.
Changes:
1. Added _serialize_mcp_content() to MCPAdapter to convert Pydantic
objects to dicts at the protocol boundary
2. Simplified parse_mcp_content() to only handle plain dicts
3. Removed get_field() helper function (no longer needed)
4. Removed Pydantic mock tests from response_parser tests
5. Added serialization tests to protocol adapter tests
Benefits:
- Clean separation: adapters translate, parsers parse
- Simpler type signatures: list[dict[str, Any]] instead of | Any
- Tests use plain dicts (no MCP SDK dependency in parser tests)
- More obvious code (removed clever helper function)
- Follows adapter pattern correctly
The fix maintains backward compatibility while establishing proper
architectural boundaries for future MCP content types (images, resources).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix: remove unused type ignore comment
Mypy now correctly infers types after hasattr and callable checks,
making the type: ignore[attr-defined] comment unnecessary.
🤖 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 f665405 commit 6b60365
File tree
3 files changed
+99
-3
lines changed- src/adcp
- protocols
- utils
- tests
3 files changed
+99
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
189 | 223 | | |
190 | 224 | | |
191 | 225 | | |
| |||
205 | 239 | | |
206 | 240 | | |
207 | 241 | | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
208 | 245 | | |
209 | 246 | | |
210 | 247 | | |
211 | 248 | | |
212 | 249 | | |
213 | | - | |
| 250 | + | |
214 | 251 | | |
215 | 252 | | |
216 | 253 | | |
| |||
220 | 257 | | |
221 | 258 | | |
222 | 259 | | |
223 | | - | |
| 260 | + | |
224 | 261 | | |
225 | 262 | | |
226 | 263 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
26 | | - | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 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 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
0 commit comments