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
All boolean fields in MCP request models require `field_validator(mode='before')` to handle string inputs from MCP clients. The system implements a standardized boolean validation pattern that ensures consistent handling across all boolean parameters:
5681
+
All boolean fields in MCP request models require `field_validator(mode='before')` to handle string inputs from MCP clients. The system implements standardized validation patterns for different data types:
5682
+
5683
+
**Boolean Validation Pattern**: Ensures consistent handling across all boolean parameters
5684
+
**Enum Validation Pattern**: Converts string inputs to enum values with alias support (e.g., CompareVersionsRequest.categories)
5685
+
**String-to-Type Coercion**: Handles various input formats for universal MCP client compatibility
@@ -6280,6 +6334,20 @@ The docsrs-mcp server implements a dual-mode architecture that allows the same F
6280
6334
6281
6335
### Recent Architectural Decisions
6282
6336
6337
+
**CompareVersionsRequest Categories Field Validator Enhancement (2025-08-25)**
6338
+
-**Issue Fixed**: Duplicate string-to-enum parsing logic between CompareVersionsRequest model and mcp_sdk_server.py causing maintenance overhead and inconsistent validation
6339
+
-**Root Cause**: Manual string parsing in MCP handler duplicated validation logic already needed in the Pydantic model
6340
+
-**Solution Implemented**:
6341
+
1.**Added field_validator**: `CompareVersionsRequest.validate_categories()` with `mode='before'` pattern following established codebase conventions
Copy file name to clipboardExpand all lines: UsefulInformation.json
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,19 @@
6
6
"errorSolutions": {
7
7
"description": "Solutions to specific errors encountered during development",
8
8
"entries": [
9
+
{
10
+
"error": "Categories Parameter Validation Error in compare_versions - 1 validation error for CompareVersionsRequest categories - Input should be a valid list",
11
+
"rootCause": "CompareVersionsRequest.categories field expected list[ChangeCategory] but received string inputs from MCP clients without proper field validation. MCP clients often send enum values as strings or None values instead of proper lists.",
12
+
"solution": "Added @field_validator('categories', mode='before') to CompareVersionsRequest model with comprehensive string-to-enum conversion handling None inputs as default all categories, string inputs as comma-separated parsing, List[str] inputs as individual string-to-enum conversion, and List[ChangeCategory] inputs as pass-through for backward compatibility.",
13
+
"context": "100% failure when calling compare_versions without categories parameter or with string category values from MCP clients",
14
+
"lesson": "Enum list parameters in MCP models require robust field validators to handle diverse input formats from different MCP clients",
15
+
"pattern": "Use @field_validator with mode='before' for enum list parameters to support None, string, and list inputs with case-insensitive category mapping",
"codeExample": "@field_validator(\"categories\", mode=\"before\")\n@classmethod\ndef validate_categories(cls, v: Any) -> list[ChangeCategory]:\n if v is None:\n return list(ChangeCategory) # Default all categories\n if isinstance(v, str):\n # Handle comma-separated string\n category_strings = [s.strip() for s in v.split(',')]\n return [cls._string_to_category(s) for s in category_strings if s]\n if isinstance(v, list):\n if not v:\n return list(ChangeCategory)\n if all(isinstance(item, ChangeCategory) for item in v):\n return v # Already proper enums\n if all(isinstance(item, str) for item in v):\n return [cls._string_to_category(s) for s in v]\n return list(ChangeCategory)\n\n@classmethod\ndef _string_to_category(cls, value: str) -> ChangeCategory:\n # Case-insensitive with aliases\n aliases = {'break': 'breaking', 'new': 'added'}\n normalized = aliases.get(value.lower(), value.lower())\n for category in ChangeCategory:\n if category.value.lower() == normalized:\n return category\n raise ValueError(f\"Invalid category: {value}\")",
19
+
"debuggingTechnique": "Test with various input formats: None, 'breaking', 'breaking,added', ['major', 'minor'] to ensure comprehensive input handling",
20
+
"additionalBugFixed": "VersionDiffResponse field name bug: Changed 'items' to 'changes' in crate_service.py return dict to match VersionDiffResponse model schema"
21
+
},
9
22
{
10
23
"error": "compareVersions Schema Reference Error - PointerToNowhere for '/components/schemas/ItemChange'",
11
24
"rootCause": "MCP manifest uses $ref to ChangeCategory enum that doesn't exist in the schema structure. The schema references undefined components.",
0 commit comments