Skip to content

Commit 57c01c7

Browse files
committed
fix: strip unsupported JSON Schema fields for Google GenAI provider
When MCP tools provide standard JSON Schema parameters containing metadata fields like $schema, the google-genai SDK's Pydantic model rejects them with extra_forbidden validation errors. Strip unsupported JSON Schema metadata fields ($schema, $id, $ref, $comment, definitions, $defs) from tool parameters before passing them to the Google GenAI SDK. Fixes #734
1 parent 94212ea commit 57c01c7

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/kosong/src/kosong/contrib/chat_provider/google_genai.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,18 @@ def tool_to_google_genai(tool: KosongTool) -> Tool:
354354
"""Convert a Kosong tool to GoogleGenAI tool format."""
355355
# Kosong already validates parameters as JSON Schema format via jsonschema
356356
# The google-genai SDK accepts dict format and internally converts to Schema
357+
parameters = tool.parameters
358+
if isinstance(parameters, dict):
359+
# Strip JSON Schema metadata fields that the google-genai SDK's
360+
# Pydantic model rejects with extra_forbidden validation errors
361+
unsupported_keys = {"$schema", "$id", "$ref", "$comment", "definitions", "$defs"}
362+
parameters = {k: v for k, v in parameters.items() if k not in unsupported_keys}
357363
return Tool(
358364
function_declarations=[
359365
FunctionDeclaration(
360366
name=tool.name,
361367
description=tool.description,
362-
parameters=tool.parameters, # type: ignore[arg-type] # GoogleGenAI accepts dict
368+
parameters=parameters, # type: ignore[arg-type] # GoogleGenAI accepts dict
363369
)
364370
]
365371
)

0 commit comments

Comments
 (0)