fix(schema): strip contentEncoding from MCP tool schemas for Gemini (fixes #2200)#2790
Merged
code-yeongyu merged 1 commit intodevfrom Mar 24, 2026
Merged
Conversation
…ompatibility The existing normalizeToolArgSchemas only applies to omo plugin tools (via tool-registry.ts), but MCP server tool schemas bypass this sanitization entirely. MCP schemas with contentEncoding/contentMediaType cause Gemini 400 errors. Add sanitizeJsonSchema() to strip unsupported keywords from MCP tool inputSchema before serialization in formatMcpCapabilities. Fixes #2200 Supersedes #2666
There was a problem hiding this comment.
1 issue found across 2 files
Confidence score: 2/5
- High-risk issue:
src/plugin/normalize-tool-arg-schemas.tsappears to mutate user-provided values indefault,examples,enum, andconst, which can change runtime behavior and produce incorrect tool argument schemas. - The issue is both severe and high-confidence (8/10, 10/10), so this is more than a minor edge case and is likely to cause user-facing regressions if merged as-is.
- There is also a standards-coverage gap in
src/plugin/normalize-tool-arg-schemas.tswhere property names under$defsandpatternPropertiesare not handled, increasing the chance of inconsistent schema normalization. - Pay close attention to
src/plugin/normalize-tool-arg-schemas.ts- avoid corrupting literal keyword values and ensure keyword/property traversal includes$defsandpatternProperties.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/plugin/normalize-tool-arg-schemas.ts">
<violation number="1" location="src/plugin/normalize-tool-arg-schemas.ts:71">
P1: The schema sanitizer corrupts arbitrary user data inside `default`, `examples`, `enum`, and `const` keywords. It also misses property names defined in other standard keywords like `$defs` and `patternProperties`.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Comment on lines
+71
to
+72
| const childIsPropertyName = key === "properties" && !isPropertyName | ||
| sanitized[key] = sanitizeJsonSchema(nestedValue, depth + 1, childIsPropertyName) |
There was a problem hiding this comment.
P1: The schema sanitizer corrupts arbitrary user data inside default, examples, enum, and const keywords. It also misses property names defined in other standard keywords like $defs and patternProperties.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/plugin/normalize-tool-arg-schemas.ts, line 71:
<comment>The schema sanitizer corrupts arbitrary user data inside `default`, `examples`, `enum`, and `const` keywords. It also misses property names defined in other standard keywords like `$defs` and `patternProperties`.</comment>
<file context>
@@ -40,3 +40,37 @@ export function normalizeToolArgSchemas<TDefinition extends Pick<ToolDefinition,
+ continue
+ }
+
+ const childIsPropertyName = key === "properties" && !isPropertyName
+ sanitized[key] = sanitizeJsonSchema(nestedValue, depth + 1, childIsPropertyName)
+ }
</file context>
Suggested change
| const childIsPropertyName = key === "properties" && !isPropertyName | |
| sanitized[key] = sanitizeJsonSchema(nestedValue, depth + 1, childIsPropertyName) | |
| if (!isPropertyName && ["default", "examples", "enum", "const"].includes(key)) { | |
| sanitized[key] = nestedValue | |
| continue | |
| } | |
| const childIsPropertyName = ["properties", "patternProperties", "$defs", "definitions", "dependentSchemas", "dependencies"].includes(key) && !isPropertyName | |
| sanitized[key] = sanitizeJsonSchema(nestedValue, depth + 1, childIsPropertyName) |
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.
PR #2666 only sanitized omo plugin tools but MCP tool schemas bypassed it entirely.
This adds
sanitizeJsonSchema()and applies it to MCP toolinputSchemainformatMcpCapabilities, fixing Gemini 400 errors fromcontentEncodingin MCP server schemas.Supersedes #2666.
Summary by cubic
Sanitizes MCP tool input schemas to remove unsupported JSON Schema fields before sending to Gemini, preventing 400 errors. Applies the same cleanup to MCP tools that we already use for plugin tools.
sanitizeJsonSchemato stripcontentEncoding,contentMediaType, and root$schema.inputSchemainformatMcpCapabilities.Written for commit 5e856b4. Summary will update on new commits.