Skip to content

fix(provider): ensure required array is present in object schemas#35634

Open
ViNull008 wants to merge 1 commit into
anomalyco:devfrom
ViNull008:fix/tool-schema-required-array
Open

fix(provider): ensure required array is present in object schemas#35634
ViNull008 wants to merge 1 commit into
anomalyco:devfrom
ViNull008:fix/tool-schema-required-array

Conversation

@ViNull008

@ViNull008 ViNull008 commented Jul 7, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #35528

Type of change

  • Bug fix

What does this PR do?

Tool schemas with additionalProperties: false but no required field fail strict JSON Schema validators. When serialized and sent to the model, the missing required becomes null, which validators like ajv (used by some OpenAI-compatible API gateways) reject with null is not of type "array".

This hits list_mcp_resources, list_mcp_resource_templates, skill_get_gold_advice, and any other tool with the same pattern. The bug has been around since at least v0.1.109 (#250, Context7 MCP via OpenAI) and was reported again in #13618.

The fix normalizes all object schemas in ProviderTransform.schema() to include an explicit required array (empty if no fields are required) when properties is present. This function is the common path for all tool schemas, so one change covers every affected tool.

required: [] means no fields are required, semantically identical to omitting required. Lenient validators ignore it. Strict validators now see a valid array instead of null. No behavior change for existing providers.

Also added required: [] directly to list_mcp_resources and list_mcp_resource_templates in session/tools.ts as a defensive measure, though the transform.ts fix alone covers all cases.

How did you verify your code works?

Built from dev branch with the patch applied. On 1.17.13 with default config (oh-my-opencode-slim plugin + minimax-coding-plan-mcp connected):

  • Before fix: opencode run -m <provider>/deepseek-v4-flash "say hi" produces AI_APICallError: Invalid schema for function 'list_mcp_resource_templates': null is not of type "array".
  • After fix: same command returns a normal model response.

Tested four configurations: only the strict-validator + MCP-with-resources combination was broken before, and it works after the fix.

Screenshots / recordings

N/A (no UI change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Strict JSON Schema validators (e.g. ajv in strict mode, used by some
OpenAI-compatible API gateways/proxies) reject tool schemas where
additionalProperties: false is set but required is missing or null.

Several built-in tools (list_mcp_resources, list_mcp_resource_templates,
and others) define inputSchema with additionalProperties: false but
without a required field. When serialized and sent to the model, the
missing required becomes null, which strict validators reject with:
  Invalid schema for function 'X': null is not of type "array"

Fix: normalize all object schemas in ProviderTransform.schema() to
include an explicit (possibly empty) required array when properties
is present. Also add required: [] directly to the two MCP resource
tools as a defensive measure.

required: [] means no fields are required, semantically identical to
omitting required. Lenient validators (OpenAI, Anthropic, official
DeepSeek API) ignore it; strict validators now see a valid array.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jul 7, 2026
@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

Tool schemas with additionalProperties:false missing "required" cause "null is not of type array" on strict validators

1 participant