fix(provider): ensure required array is present in object schemas#35634
Open
ViNull008 wants to merge 1 commit into
Open
fix(provider): ensure required array is present in object schemas#35634ViNull008 wants to merge 1 commit into
ViNull008 wants to merge 1 commit into
Conversation
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.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #35528
Type of change
What does this PR do?
Tool schemas with
additionalProperties: falsebut norequiredfield fail strict JSON Schema validators. When serialized and sent to the model, the missingrequiredbecomesnull, which validators like ajv (used by some OpenAI-compatible API gateways) reject withnull 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 explicitrequiredarray (empty if no fields are required) whenpropertiesis 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 omittingrequired. Lenient validators ignore it. Strict validators now see a valid array instead ofnull. No behavior change for existing providers.Also added
required: []directly tolist_mcp_resourcesandlist_mcp_resource_templatesinsession/tools.tsas a defensive measure, though thetransform.tsfix 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):
opencode run -m <provider>/deepseek-v4-flash "say hi"producesAI_APICallError: Invalid schema for function 'list_mcp_resource_templates': null is not of type "array".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