Skip to content

Conversation

@xiaoju111a
Copy link
Contributor

@xiaoju111a xiaoju111a commented Jan 28, 2026

Related Issue

Resolves #734

Description

This PR fixes a compatibility issue between Google GenAI provider and MCP tools that include standard JSON Schema metadata fields.

Problem

When using MCP tools (like Exa MCP) with Google GenAI provider, the following validation error occurs:

1 validation error for FunctionDeclaration
parameters.$schema
  Extra inputs are not permitted [type=extra_forbidden, input_value='http://json-schema.org/draft-07/schema#', input_type=str]

Root cause:

  • MCP tools' inputSchema includes standard JSON Schema metadata fields
  • Google GenAI SDK's Pydantic model has extra='forbid', which rejects these additional fields
  • Kimi CLI was passing the complete schema without filtering metadata

Solution

Strip JSON Schema metadata fields in tool_to_google_genai() function before passing to Google GenAI SDK. We filter 4 fields that are rejected by the SDK:

  • $schema, $id, $comment - JSON Schema metadata
  • examples - Example values (not part of validation schema)

Note: $defs and definitions are already removed by kosong's deref_json_schema() function, so we don't need to filter them here.

def tool_to_google_genai(tool: KosongTool) -> Tool:
    # Strip JSON Schema metadata fields (google-genai SDK has extra='forbid')
    # Note: $defs/definitions are already removed by kosong's deref_json_schema()
    parameters = {
        k: v
        for k, v in tool.parameters.items()
        if k not in ("$schema", "$id", "$comment", "examples")
    }
    
    return Tool(
        function_declarations=[
            FunctionDeclaration(
                name=tool.name,
                description=tool.description,
                parameters=parameters,
            )
        ]
    )

Impact

  • ✅ Only affects Google GenAI provider
  • ✅ Backward compatible (tools without metadata work as before)
  • ✅ No performance impact (simple dict filtering)
  • ✅ Follows JSON Schema best practices (metadata fields are not parameter definitions)

Testing

Manually verified the 4 rejected fields with Google GenAI SDK:

# Tested fields that cause ValidationError:
# ❌ $schema, $id, $comment, examples

# After fix: ✅ All metadata stripped automatically
# Tools work correctly with Google GenAI provider

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

…ters

Google GenAI SDK's Pydantic model has extra='forbid', which rejects
JSON Schema metadata fields like $schema, $id, and $comment.

This causes validation errors when using MCP tools that include
standard JSON Schema metadata in their inputSchema.

Fixes MoonshotAI#734
Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional flags.

Open in Devin Review

@xxchan xxchan requested a review from pvzheroes125 January 28, 2026 05:10
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.

[Bug]: Google GenAI provider fails with extra_forbidden for tool parameters containing $schema

1 participant