You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add missing fields to response models to match service layer output:
- Add is_latest field to VersionInfo model
- Add latest field to ListVersionsResponse model
The service layer was returning these fields but strict validation
(extra='forbid') was rejecting them, causing 100% failure for
version listing functionality.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: Architecture.md
+38Lines changed: 38 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -519,6 +519,7 @@ The models package implements a **modular, function-based split** that maintains
519
519
- Response formatting with consistent field naming
520
520
- Integration with FastAPI automatic documentation
521
521
-**Phase 2 Enhancement**: `SearchResult` and `GetItemDocResponse` now include `is_stdlib: bool` and `is_dependency: bool` fields for enhanced filtering and context
522
+
-**Version Response Models**: `VersionInfo` includes `is_latest: bool` field, `ListVersionsResponse` includes `latest: str | None` field for version metadata
522
523
523
524
**models/version_diff.py (~245 LOC)**
524
525
- Version comparison and change tracking models
@@ -3974,6 +3975,38 @@ PATH_ALIASES = {
3974
3975
-**Performance**: O(1) alias lookup before O(n) fuzzy matching
3975
3976
-**Extensible**: Alias dictionary can be expanded based on usage patterns
3976
3977
3978
+
### Pydantic Validation Error Fix in list_versions
3979
+
3980
+
**Location**: `models/responses.py` - VersionInfo and ListVersionsResponse models
3981
+
3982
+
**Issue Description**:
3983
+
The list_versions service endpoint was failing with Pydantic validation errors due to field mismatch between service layer responses and response model definitions.
3984
+
3985
+
**Root Cause Analysis**:
3986
+
- Service layer was returning "is_latest" and "latest" fields in version data
3987
+
- Response models (VersionInfo and ListVersionsResponse) didn't declare these fields
3988
+
- Pydantic's strict validation rejected the extra fields, causing endpoint failures
3989
+
3990
+
**Fix Implementation**:
3991
+
```python
3992
+
# Fixed VersionInfo model
3993
+
classVersionInfo(BaseModel):
3994
+
version: str
3995
+
yanked: bool|None=None
3996
+
is_latest: bool= Field(False, description="Whether this is the latest version of the crate")
3997
+
3998
+
# Fixed ListVersionsResponse model
3999
+
classListVersionsResponse(BaseModel):
4000
+
versions: list[VersionInfo]
4001
+
latest: str|None= Field(None, description="Latest version string")
4002
+
```
4003
+
4004
+
**Impact Assessment**:
4005
+
-**Pre-Fix**: Complete failure of list_versions endpoint due to validation errors
4006
+
-**Post-Fix**: Successful version listing with proper latest version metadata
4007
+
-**Architectural Benefit**: Ensures service layer and response model field alignment
4008
+
-**Data Integrity**: Maintains type safety while supporting version metadata requirements
4009
+
3977
4010
### Known Architectural Issues Requiring Defensive Programming
3978
4011
3979
4012
The following section documents architectural issues identified in four key features that require defensive programming improvements to prevent runtime failures.
@@ -9188,6 +9221,11 @@ class MCPTool(BaseModel):
9188
9221
)
9189
9222
```
9190
9223
9224
+
**Service Layer Model Alignment**:
9225
+
-**Critical Requirement**: Service layer response data must exactly match response model field definitions
9226
+
-**Validation Enforcement**: Pydantic models validate that service layer returns only declared fields to prevent validation errors
9227
+
-**Field Consistency**: Any new fields returned by services (like `is_latest`, `latest`) must be added to corresponding response models before implementation
9228
+
9191
9229
### Tutorial Content Embedding
9192
9230
9193
9231
Tutorial content is embedded directly in the `get_mcp_manifest()` function rather than loaded from external files, following the same pattern established by the `start_pre_ingestion` tool:
Copy file name to clipboardExpand all lines: UsefulInformation.json
+14Lines changed: 14 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2619,6 +2619,20 @@
2619
2619
"defaultImplementation": "Default CLI flag changed from 'fastmcp' to 'sdk' for new users"
2620
2620
},
2621
2621
"architecturalBenefits": "Official SDK's @server.tool() decorator pattern is cleaner and more maintainable than FastMCP conversion patterns"
2622
+
},
2623
+
{
2624
+
"error": "Extra inputs are not permitted - list_versions Pydantic validation failure",
2625
+
"rootCause": "Service layer returned 'is_latest' field in VersionInfo and 'latest' field in root response, but Pydantic models used strict validation with extra='forbid' and these fields were missing from model definitions",
2626
+
"solution": "Added missing fields to Pydantic response models: 'is_latest: bool = Field(False, description=\"Whether this is the latest version of the crate\")' to VersionInfo model and 'latest: str | None = Field(None, description=\"Latest version string\")' to ListVersionsResponse model",
2627
+
"context": "list_versions API endpoint failing due to mismatch between service layer output and response model definition when using strict Pydantic validation",
2628
+
"problem": "Service layer included additional fields not defined in Pydantic models, causing validation errors when models used ConfigDict(extra='forbid') for security",
2629
+
"prevention": "Always ensure service layer output matches response model fields exactly when using strict validation. Keep service layer and response models in sync during development",
2630
+
"pattern": "When using extra='forbid' in Pydantic models, all service layer output fields must be explicitly defined in the model schema",
"codeExample": "# Added to VersionInfo model:\nis_latest: bool = Field(False, description=\"Whether this is the latest version of the crate\")\n\n# Added to ListVersionsResponse model:\nlatest: str | None = Field(None, description=\"Latest version string\")\n\n# Root cause - service returned extra fields:\nresponse_data = {\n 'versions': [...],\n 'latest': '1.2.3', # This field was missing from model\n # ... other fields\n}\n\n# Each VersionInfo contained:\n{\n 'version': '1.0.0',\n 'is_latest': False, # This field was missing from model\n # ... other fields\n}",
2634
+
"debuggingTechnique": "Check service layer output fields against Pydantic model definitions when using strict validation to identify missing fields",
2635
+
"impact": "Fixed list_versions endpoint validation errors and ensured proper response structure for version listing functionality"
0 commit comments