Fix: Add JSON string deserialization support for metadata parameter#85
Open
MyWWWChat wants to merge 2 commits intoqdrant:masterfrom
Open
Fix: Add JSON string deserialization support for metadata parameter#85MyWWWChat wants to merge 2 commits intoqdrant:masterfrom
MyWWWChat wants to merge 2 commits intoqdrant:masterfrom
Conversation
- Support metadata as JSON string, dict, or None - Add automatic deserialization of JSON strings with proper error handling - Handle edge cases (null, none, empty strings, whitespace) - Add comprehensive test suite with 13 test cases covering all scenarios - Maintain backward compatibility with existing dict/None metadata - Fix MCP interface issue where Claude serializes parameters to strings Resolves metadata validation error: 'Input validation error: ... is not valid under any of the given schemas' Technical changes: - Updated Union type annotation to include str in metadata parameter - Added JSON deserialization logic in store() function - Added validation for non-dict types after deserialization - Added comprehensive test coverage for all edge cases - All existing tests (37 total) continue to pass
- Add fallback to 'text' field when 'document' is not present - Ensures compatibility with different payload structures - Prevents KeyError when retrieving search results
|
This PR fixes a critical schema-implementation mismatch that currently breaks the The Problem: The MCP server's metadata parameter schema doesn't match its implementation. The schema only accepts object | null, but the implementation actually supports dict | str | None (JSON strings). This causes validation errors when Claude sends metadata as JSON strings: Input validation error: '{"code": "..."}' is not valid under any of the given schemas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The MCP server's metadata parameter schema doesn't match its implementation, causing validation errors when Claude (and other MCP clients) send metadata as JSON strings.
Current Issue:
object | nullfor metadatadict | str | None(can parse JSON strings)Input validation error: '{"code": "..."}' is not valid under any of the given schemasSolution
This PR fixes the schema-implementation mismatch by:
Metadata | NonetoUnion[Metadata, str, None]Technical Changes
src/mcp_server_qdrant/mcp_server.py
strtype"null","none", empty strings, whitespacesrc/mcp_server_qdrant/qdrant.py
'text'field when'document'is missing in search resultstests/test_metadata_deserialization.py
Testing
All tests pass:
Impact
This fix resolves the metadata validation error that prevents Claude and other MCP clients from using the metadata parameter as documented. The change is backward compatible - existing code using dict or None continues to work.
Related Issues
Fixes the error:
Input validation error: '{"code": "def test(): pass"}' is not valid under any of the given schemasThis enables proper usage as described in TOOL_STORE_DESCRIPTION: