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
fix: add boolean field validator for force parameter in StartPreIngestionRequest
- Added field_validator with mode='before' to handle string-to-boolean conversion
- Accepts 'true', '1', 'yes', 'on' as truthy values (case-insensitive)
- Follows validate_include_unchanged pattern for consistency
- Fixes MCP client compatibility issue where boolean values sent as strings
- Updated all living memory documentation files with solution details
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
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:
"""Validate and coerce include_unchanged to boolean."""
3166
+
ifisinstance(v, bool):
3167
+
return v
3168
+
ifisinstance(v, str):
3169
+
return v.lower() in ("true", "1", "yes", "on")
3170
+
returnbool(v)
3171
+
```
3172
+
3173
+
**Truthy String Values**
3174
+
-`'true'` - Standard boolean string representation
3175
+
-`'1'` - Numeric boolean representation
3176
+
-`'yes'` - Human-readable affirmative
3177
+
-`'on'` - Toggle-style representation
3178
+
3179
+
**Key Design Principles**
3180
+
-**MCP Client Compatibility**: Handles string inputs from MCP clients that may serialize booleans as strings
3181
+
-**Case Insensitive**: Uses `.lower()` for consistent string comparison
3182
+
-**Fallback Behavior**: Uses Python's `bool()` for non-string, non-boolean inputs
3183
+
-**Consistency**: Follows the same pattern as `validate_include_unchanged` implementation for uniform behavior
3184
+
3185
+
**Architecture Integration**
3186
+
-**mode='before'**: Validates and coerces input before Pydantic's built-in type validation
3187
+
-**Type Safety**: Ensures boolean type consistency after validation
3188
+
-**Schema Compatibility**: Works with `anyOf` patterns in MCP manifest for dual boolean/string acceptance
3189
+
-**Error Handling**: Invalid string values result in `False` through `bool(v)` fallback (for permissive validation) or explicit ValueError (for strict validation)
3190
+
3146
3191
### MCP Manifest Schema Patterns
3147
3192
3148
3193
The MCP manifest schema uses consistent `anyOf` patterns for flexible parameter acceptance across all type-flexible parameters. This architectural decision ensures uniform handling of MCP client serialization variations:
"solution": "All numeric and boolean parameters must support string-to-type conversion for MCP clients using coercion functions with mode='before' validators. Handle None values first, then check existing type, then attempt string conversion with try/catch",
Copy file name to clipboardExpand all lines: src/docsrs_mcp/README.md
+10-2Lines changed: 10 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,17 +6,25 @@ A high-performance MCP server for querying Rust crate documentation with memory-
6
6
7
7
This module provides a Model Context Protocol (MCP) server that enables efficient ingestion and querying of Rust crate documentation. The server features memory-optimized streaming processing, adaptive batch sizing, and comprehensive memory monitoring to handle large-scale documentation processing.
8
8
9
+
## Recent Updates
10
+
11
+
-**Parameter Validation Enhancement**: Fixed force parameter validation in start_pre_ingestion tool to accept string boolean values
12
+
-**Field Validator Implementation**: All MCP tool boolean parameters now use standardized field validators for string conversion
13
+
-**Enhanced MCP Client Compatibility**: Improved support for diverse MCP client implementations with flexible parameter handling
14
+
9
15
## MCP Compatibility
10
16
11
17
This server provides enhanced MCP (Model Context Protocol) compatibility with flexible parameter type handling:
12
18
13
19
### Boolean Parameter Support
14
20
-**Flexible Type Input**: Boolean parameters (`has_examples`, `deprecated`) accept both native boolean values and string representations
21
+
-**Field Validator Implementation**: All boolean parameters use Pydantic field validators for robust string-to-boolean conversion
15
22
-**Automatic Type Conversion**: String values are automatically converted to booleans using the following mappings:
16
-
-`"true"`, `"1"`, `"yes"` → `true`
17
-
-`"false"`, `"0"`, `"no"` → `false`
23
+
-`"true"`, `"1"`, `"yes"`, `"on"` → `true`
24
+
-`"false"`, `"0"`, `"no"`, `"off"` → `false`
18
25
-**Client Compatibility**: MCP clients can send boolean values in their preferred format without worrying about type mismatches
19
26
-**Backward Compatibility**: Maintains full compatibility with existing MCP clients that send native boolean values
27
+
-**Standard Pattern**: This field validator pattern ensures compatibility with various MCP client implementations
20
28
21
29
### Parameter Flexibility
22
30
-**Numeric Parameters**: Parameters like `k` and `min_doc_length` support both integer and string input with automatic conversion
0 commit comments