Skip to content

Commit 71f39c8

Browse files
fix: handle boolean MCP schema leaves
1 parent 2afdeff commit 71f39c8

2 files changed

Lines changed: 44 additions & 3 deletions

File tree

google/genai/_mcp_utils.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import google.auth
2525
from google.auth.transport.requests import Request
2626

27-
from . import _common
2827
from . import types
2928
from ._api_client import _MULTI_REGIONAL_LOCATIONS
3029

@@ -124,9 +123,12 @@ def set_mcp_usage_header(headers: dict[str, str]) -> None:
124123

125124

126125
def _filter_to_supported_schema(
127-
schema: _common.StringDict,
128-
) -> _common.StringDict:
126+
schema: Any,
127+
) -> Any:
129128
"""Filters the schema to only include fields that are supported by JSONSchema."""
129+
if not isinstance(schema, dict):
130+
return schema
131+
130132
supported_fields: set[str] = set(types.JSONSchema.model_fields.keys())
131133

132134
supported_fields.update([

google/genai/tests/mcp/test_mcp_to_gemini_tools.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,45 @@ def test_properties_conversion():
198198
]
199199

200200

201+
def test_additional_properties_boolean_conversion():
202+
"""Test conversion of MCP tools with boolean additionalProperties."""
203+
mcp_tools = [
204+
mcp_types.Tool(
205+
name='tool',
206+
description='tool-description',
207+
inputSchema={
208+
'type': 'object',
209+
'properties': {
210+
'key1': {
211+
'type': 'object',
212+
'additionalProperties': False,
213+
},
214+
},
215+
'additionalProperties': False,
216+
},
217+
),
218+
]
219+
220+
result = _mcp_utils.mcp_to_gemini_tools(mcp_tools)
221+
222+
assert result == [
223+
types.Tool(
224+
function_declarations=[
225+
types.FunctionDeclaration(
226+
name='tool',
227+
description='tool-description',
228+
parameters=types.Schema(
229+
type='OBJECT',
230+
properties={
231+
'key1': types.Schema(type='OBJECT'),
232+
},
233+
),
234+
),
235+
],
236+
),
237+
]
238+
239+
201240
def test_defs_conversion():
202241
"""Test conversion of MCP tools with shared definitions ($defs)."""
203242
mcp_tools = [

0 commit comments

Comments
 (0)