Skip to content

MCP server anyOf schemas rejected by DeepSeek - should strip at gateway level #83361

@wbrom42

Description

@wbrom42

Summary

MCP servers that expose tool schemas with anyOf/oneOf keywords (e.g. Unusual Whales) cause all LLM requests to fail with 400 Invalid schema when the provider is DeepSeek. The gateway registers tools natively without stripping anyOf, and DeepSeek rejects them.

Error

400 Invalid schema for function 'unusual-whales__get_balance_sheet_screener': "date" is not valid under any of the schemas listed in the 'anyOf' keyword

Full gateway log entry

{
  "error": "LLM request failed: provider rejected the request schema or tool payload.",
  "failoverReason": "format",
  "model": "deepseek-v4-pro",
  "provider": "deepseek",
  "rawErrorPreview": "400 Invalid schema for function 'unusual-whales__get_balance_sheet_screener': 'date' is not valid under any of the schemas listed in the 'anyOf' keyword",
  "providerRuntimeFailureKind": "schema"
}

Happens in any session/context that has UW MCP tools registered -- cron jobs, direct chat, sub-agent runs. 48/48 crons affected.

Root Cause

The Unusual Whales MCP server exposes optional fields as anyOf unions (e.g. "date": {"anyOf": [{"type": "string"}, {"type": "integer"}]}). This is valid JSON Schema and accepted by Anthropic/OpenAI, but DeepSeek's API rejects schemas with anyOf/oneOf at the tool schema level.

The userland workaround is a strip_nullable_unions() function that collapses anyOf: [T, "null"] to {type: T, nullable: true}, but this only works if it runs in the agent process before schemas reach the LLM. The gateway registers MCP tools natively and sends raw schemas to the provider.

Proposed Fix

Add a lightweight schema sanitization step when registering MCP tools at the gateway level:

  1. Walk all tool schemas for anyOf/oneOf keywords at registration time
  2. Collapse nullable unions (anyOf: [T, "null"] -> {type: T, nullable: true})
  3. For multi-branch anyOf (e.g. date as string|integer), collapse to first non-null variant
  4. This is safe because MCP tool handlers re-validate arguments server-side

Environment

  • OpenClaw 2026.5.12-beta.6 (c4292e0)
  • DeepSeek v4 Flash + Pro providers
  • Node v22.22.2
  • Linux arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions