Skip to content

fix: accept metadata sent as a JSON string of an object - #219

Merged
chadha-sridi merged 2 commits into
masterfrom
fix/metadata-json-string
Dec 3, 2026
Merged

chadha-sridi merged 2 commits into
masterfrom
fix/metadata-json-string

Conversation

@chadha-sridi

Copy link
Copy Markdown
Contributor

Accept metadata sent as a JSON string

Closes #85.

Problem

Some MCP clients, including Claude Code and Cursor, sometimes send an object argument as a JSON string: "metadata": "{\"lang\": \"python\"}" instead of "metadata": {"lang": "python"}. These are known client bugs that are still open. qdrant-store then fails with Input should be a valid dictionary, and the information isn't stored.

Fix

metadata gets a pydantic BeforeValidator. If the value is a string that parses as a JSON object, it is replaced by that object before validation. Every other value passes through unchanged, so:

  • objects and null behave as before;
  • plain text, lists, numbers, the string "null" and invalid JSON are still rejected with the same error;
  • the tool schema clients see is unchanged (object or null), so well-behaved clients keep sending objects.

Difference from #85

#85 changes the parameter type so that it also accepts strings. That would change the schema and tell clients a string is valid. This PR keeps the schema strict and only tolerates the string form at validation time.

Tests

tests/test_metadata_argument.py:

  • the schema is still object | null;
  • an object and its JSON string store the same metadata;
  • leaving out metadata still works;
  • values that aren't objects are still rejected.

Full suite: 164 passed.

Thanks to @MyWWWChat for reporting this and proposing the first fix in #85.

🤖 Generated with Claude Code

Closes #85

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@AstraBert AstraBert left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a nit :)

Comment thread src/mcp_server_qdrant/mcp_server.py Resolved
It stops at 200 levels of nesting and rejects NaN and Infinity.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chadha-sridi
chadha-sridi merged commit f161fe0 into master Dec 3, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants