Skip to content

MCP tool validation fails with anyOf schemas — union types like list[str] | None cause false positive validation errors #2839

@igneo-user

Description

@igneo-user

What happened?

When calling MCP tools that have union type parameters (e.g., list[str] | None), Qwen Code rejects valid input with a contradictory error message:

params/urls must be array, params/urls must be null, params/urls must match a schema in anyOf

Steps to reproduce:

  1. Connect to an MCP server that uses union types in tool parameters (e.g., wet-mcp server)
  2. Call a tool with a parameter defined as urls: list[str] | None = None
  3. Pass a valid array value: extract(action="extract", urls=["https://example.com"])
  4. Validation fails

Example tool definition from wet-mcp:
async def extract(
action: str,
urls: list[str] | None = None, # ← union type
...
) -> str:

Actual error:
params/urls must be array, params/urls must be null, params/urls must match a schema in anyOf
This error is logically contradictory — the value ["https://example.com"] IS an array and SHOULD match the anyOf schema.

What did you expect to happen?

The value ["https://example.com"] should successfully validate against the JSON Schema anyOf construct:

{
"urls": {
"anyOf": [
{"type": "array", "items": {"type": "string"}},
{"type": "null"}
],
"default": null
}
}

According to JSON Schema specification, anyOf means the value must match at least one of the schemas. An array value should match the first schema and pass validation.
The tool call should execute successfully, as it does in other MCP clients (Gemini CLI, Cline, Claude Desktop).

Client information

Client Information

Login information

igneo-user

Anything else we need to know?

Impact:

This bug breaks compatibility with MCP servers that use Python union types (list[str] | None, int | None, etc.), which is a common pattern for optional parameters.

Comparison with other MCP clients:
Client: Status:

Gemini CLI ✅ Works
Cline (VS Code) ✅ Works
Claude desktop ✅ Works
Qwen Code ❌ Fails

Related issues (same root cause in other projects):

Suggested fix:

Update the JSON Schema validator to correctly handle anyOf constructs according to the JSON Schema specification:

  • When validating against anyOf, pass if the value matches at least one schema in the array
  • Consider using a standard validation library (jsonschema for Python, ajv for JavaScript) that correctly implements the specification

Workaround:
Currently, the only workaround is to use alternative MCP clients or avoid MCP servers that use union types in tool parameters.

Metadata

Metadata

Assignees

Labels

status/needs-triageIssue needs to be triaged and labeledtype/bugSomething isn't working as expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions