Skip to content

Commit da0766d

Browse files
committed
fix: handle boolean MCP schema leaves
1 parent 7c331c6 commit da0766d

2 files changed

Lines changed: 33 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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,34 @@ def test_update_endpoint_labels_conversion():
285285
assert 'additionalProperties' in labels_schema
286286

287287

288+
def test_mcp_boolean_additional_properties_conversion():
289+
"""Test MCP schemas with boolean additionalProperties values."""
290+
mcp_tools = [
291+
mcp_types.Tool(
292+
name='tool',
293+
description='tool-description',
294+
inputSchema={
295+
'type': 'object',
296+
'properties': {
297+
'payload': {
298+
'type': 'object',
299+
'additionalProperties': False,
300+
}
301+
},
302+
},
303+
),
304+
]
305+
306+
result = _mcp_utils.mcp_to_gemini_tools(mcp_tools)
307+
payload_schema = (
308+
result[0]
309+
.function_declarations[0]
310+
.parameters.properties['payload']
311+
)
312+
313+
assert payload_schema.type == 'OBJECT'
314+
315+
288316
def test_agent_platform_preserves_unknown_fields():
289317
"""Test that Agent Platform translation passes all schema fields directly
290318
to the backend.

0 commit comments

Comments
 (0)