Repository navigation
fix(ai): keep tool schemas within Meta's limits - #51040
rekram1-node wants to merge 1 commit into
Conversation
Meta rejects tool schemas nested more than 10 levels deep and any recursive $ref. Add a meta sanitizer that sends schemas within those limits unchanged and otherwise inlines references, cuts recursive ones, and leaves structure past the limit unconstrained. Meta routes apply it to every model, and Muse Spark models get it by name on other hosts.
|
Verification on v2.0.26: the native-tool path still reproduces, and the Minimal repro:
{
"mcp": {
"servers": {
"deepschema": { "type": "local", "command": ["node", "deep-mcp.mjs"], "codemode": false }
}
}
}With Code Mode left at its default the same server passes unchanged, because the deep schema never reaches Meta. Worth knowing when retesting: without Note: the branch currently conflicts with |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
V2 fix for #50297, #45800, and #48151.
Problem
Meta's API rejects the whole request when any tool schema:
JSON schema exceeds the maximum nesting depth of 10 levels(Console Go (Meta Muse Spark): MCP tool schemas deeper than 10 levels are rejected, no Meta/Muse sanitizer #50297, for example Vercel MCP'screate_flag,update_flag,create_flag_segment, andupdate_flag_segment), or$ref:Recursive JSON schemas are not currently supported(Recursive $ref in postgres tool schemas breaks Meta Muse Spark ("Recursive JSON schemas are not currently supported") #45800 Postgres tools, Console Go -> Meta: sanitize recursive $ref tool schemas (Codex Desktop codex_app tools hit it too) #48151codex_apptools).This hits Muse Spark on Meta's API and through Go, Zen, and gateways that forward to Meta.
Changes
protocols/utils/meta-json-schema.ts(MetaJsonSchema.normalize), selected withsanitizer: "meta".propertiesoritemskey holding an object anywhere in the schema, including property names and values such asdefault. It follows$refand ignores unreferenced$defs.$refs are inlined and a recursive$refbecomes{}with its sibling keywords. At level 10,propertiesanditemsare removed (along withadditionalProperties,patternProperties, andunevaluated*), so that part accepts any object or array.const,default,enum, andexamplesvalues that would exceed the limit are dropped.$refsiblings merge into the target unless they overlap one of its constraints, in which case both go underallOf.muse-sparkselects it, likegeminiandkimi. The match is not justmusebecause Muse Glimmer 30B is an open-weight model on Fireworks, Together, DeepInfra, and NVIDIA, which don't run Meta's validator.sanitizer: "meta"for every model, since the limits come from Meta's API."meta"toLanguageModelSanitizerCompatibility.Verification
bun testinpackages/ai: 1512 pass.bun run check: 35/35.$refleft.create_flagare accepted on Meta Chat, on Meta Messages, and on Go withmuse-spark-1.3-contributor, which gets the sanitizer by name.sanitizer: "none", the same two are rejected with Meta's recursion and depth errors.create_flagcalls frommuse-spark-1.3using the trimmed schema both validate against the original, untrimmed schema.References that aren't plain local JSON pointers (percent-encoded names,
$anchor) are not inlined, the same as before this change.