Skip to content

Commit 0ee97d3

Browse files
committed
fix(kosong): strip JSON Schema metadata from Google GenAI tool parameters
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 #734
1 parent fa3d95a commit 0ee97d3

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,21 @@ 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+
358+
# Strip JSON Schema metadata fields (google-genai SDK has extra='forbid')
359+
# Note: $defs/definitions are already removed by kosong's deref_json_schema()
360+
parameters = {
361+
k: v
362+
for k, v in tool.parameters.items()
363+
if k not in ("$schema", "$id", "$comment", "examples")
364+
}
365+
357366
return Tool(
358367
function_declarations=[
359368
FunctionDeclaration(
360369
name=tool.name,
361370
description=tool.description,
362-
parameters=tool.parameters, # type: ignore[arg-type] # GoogleGenAI accepts dict
371+
parameters=parameters, # type: ignore[arg-type] # GoogleGenAI accepts dict
363372
)
364373
]
365374
)

0 commit comments

Comments
 (0)