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
28 changes: 28 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 @@ -285,6 +285,34 @@ def test_update_endpoint_labels_conversion():
assert 'additionalProperties' in labels_schema


def test_mcp_boolean_additional_properties_conversion():
"""Test MCP schemas with boolean additionalProperties values."""
mcp_tools = [
mcp_types.Tool(
name='tool',
description='tool-description',
inputSchema={
'type': 'object',
'properties': {
'payload': {
'type': 'object',
'additionalProperties': False,
}
},
},
),
]

result = _mcp_utils.mcp_to_gemini_tools(mcp_tools)
payload_schema = (
result[0]
.function_declarations[0]
.parameters.properties['payload']
)

assert payload_schema.type == 'OBJECT'


def test_agent_platform_preserves_unknown_fields():
"""Test that Agent Platform translation passes all schema fields directly
to the backend.
Expand Down
Loading