Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions google/genai/_mcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import google.auth
from google.auth.transport.requests import Request

from . import _common
from . import types
from ._api_client import _MULTI_REGIONAL_LOCATIONS

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


def _filter_to_supported_schema(
schema: _common.StringDict,
) -> _common.StringDict:
schema: Any,
) -> Any:
"""Filters the schema to only include fields that are supported by JSONSchema."""
if not isinstance(schema, dict):
return schema

supported_fields: set[str] = set(types.JSONSchema.model_fields.keys())

supported_fields.update([
Expand Down
39 changes: 39 additions & 0 deletions google/genai/tests/mcp/test_mcp_to_gemini_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,45 @@ def test_properties_conversion():
]


def test_additional_properties_boolean_conversion():
"""Test conversion of MCP tools with boolean additionalProperties."""
mcp_tools = [
mcp_types.Tool(
name='tool',
description='tool-description',
inputSchema={
'type': 'object',
'properties': {
'key1': {
'type': 'object',
'additionalProperties': False,
},
},
'additionalProperties': False,
},
),
]

result = _mcp_utils.mcp_to_gemini_tools(mcp_tools)

assert result == [
types.Tool(
function_declarations=[
types.FunctionDeclaration(
name='tool',
description='tool-description',
parameters=types.Schema(
type='OBJECT',
properties={
'key1': types.Schema(type='OBJECT'),
},
),
),
],
),
]


def test_defs_conversion():
"""Test conversion of MCP tools with shared definitions ($defs)."""
mcp_tools = [
Expand Down
Loading