Skip to content

fix(schema): strip contentEncoding from MCP tool schemas for Gemini (fixes #2200)#2790

Merged
code-yeongyu merged 1 commit intodevfrom
fix/2666-mcp-schema-sanitization
Mar 24, 2026
Merged

fix(schema): strip contentEncoding from MCP tool schemas for Gemini (fixes #2200)#2790
code-yeongyu merged 1 commit intodevfrom
fix/2666-mcp-schema-sanitization

Conversation

@code-yeongyu
Copy link
Copy Markdown
Owner

@code-yeongyu code-yeongyu commented Mar 24, 2026

PR #2666 only sanitized omo plugin tools but MCP tool schemas bypassed it entirely.

This adds sanitizeJsonSchema() and applies it to MCP tool inputSchema in formatMcpCapabilities, fixing Gemini 400 errors from contentEncoding in 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.

Written for commit 5e856b4. Summary will update on new commits.

…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
@code-yeongyu code-yeongyu merged commit 500784a into dev Mar 24, 2026
5 checks passed
@code-yeongyu code-yeongyu deleted the fix/2666-mcp-schema-sanitization branch March 24, 2026 07:25
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 2/5

  • High-risk issue: src/plugin/normalize-tool-arg-schemas.ts appears to mutate user-provided values in default, examples, enum, and const, 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.ts where property names under $defs and patternProperties are 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 $defs and patternProperties.
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)
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix with Cubic

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.

Junior Sisyphus fails with Gemini when MCP tools use contentEncoding in schemas

1 participant