diff --git a/google/genai/_mcp_utils.py b/google/genai/_mcp_utils.py index 6cd632252..59fc36310 100644 --- a/google/genai/_mcp_utils.py +++ b/google/genai/_mcp_utils.py @@ -42,11 +42,7 @@ def mcp_to_gemini_tool(tool: McpTool) -> types.Tool: function_declarations=[{ "name": tool.name, "description": tool.description, - "parameters": types.Schema.from_json_schema( - json_schema=types.JSONSchema( - **_filter_to_supported_schema(tool.inputSchema) - ) - ), + "parameters_json_schema": tool.inputSchema, }] ) diff --git a/google/genai/tests/live/test_live.py b/google/genai/tests/live/test_live.py index 9ffebb726..b9082144e 100644 --- a/google/genai/tests/live/test_live.py +++ b/google/genai/tests/live/test_live.py @@ -1141,11 +1141,11 @@ async def test_bidi_setup_to_api_with_config_mcp_tools( 'model': 'models/test_model', 'tools': [{ 'functionDeclarations': [{ - 'parameters': { - 'type': 'OBJECT', + 'parametersJsonSchema': { + 'type': 'object', 'properties': { 'location': { - 'type': 'STRING', + 'type': 'string', }, }, }, @@ -1167,11 +1167,11 @@ async def test_bidi_setup_to_api_with_config_mcp_tools( ), 'tools': [{ 'functionDeclarations': [{ - 'parameters': { - 'type': 'OBJECT', + 'parametersJsonSchema': { + 'type': 'object', 'properties': { 'location': { - 'type': 'STRING', + 'type': 'string', }, }, }, @@ -1197,6 +1197,10 @@ async def test_bidi_setup_to_api_with_config_mcp_tools( ], }, ) + + print(result, 'hello result!!') + print(expected_result_vertexai, 'hello expected_result_vertexai!!') + print(expected_result_googleai, 'hello expected_result_googleai!!') assert ( result == expected_result_vertexai @@ -1238,11 +1242,11 @@ async def list_tools(self): 'model': 'models/test_model', 'tools': [{ 'functionDeclarations': [{ - 'parameters': { - 'type': 'OBJECT', + 'parametersJsonSchema': { + 'type': 'object', 'properties': { 'location': { - 'type': 'STRING', + 'type': 'string', }, }, }, @@ -1264,11 +1268,11 @@ async def list_tools(self): ), 'tools': [{ 'functionDeclarations': [{ - 'parameters': { - 'type': 'OBJECT', + 'parametersJsonSchema': { + 'type': 'object', 'properties': { 'location': { - 'type': 'STRING', + 'type': 'string', }, }, }, diff --git a/google/genai/tests/mcp/test_mcp_to_gemini_tools.py b/google/genai/tests/mcp/test_mcp_to_gemini_tools.py index 62db7d89a..bf20f9aba 100644 --- a/google/genai/tests/mcp/test_mcp_to_gemini_tools.py +++ b/google/genai/tests/mcp/test_mcp_to_gemini_tools.py @@ -39,16 +39,17 @@ def test_empty_mcp_tools_list(): def test_unknown_field_conversion(): """Test conversion of MCP tools with unknown fields to Gemini tools.""" + inputSchema = { + 'type': 'object', + 'properties': {}, + 'unknown_field': 'unknownField', + 'unknown_object': {}, + } mcp_tools = [ mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'object', - 'properties': {}, - 'unknown_field': 'unknownField', - 'unknown_object': {}, - }, + inputSchema=inputSchema, ), ] result = _mcp_utils.mcp_to_gemini_tools(mcp_tools) @@ -58,10 +59,7 @@ def test_unknown_field_conversion(): types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='OBJECT', - properties={}, - ), + parameters_json_schema=inputSchema, ), ], ), @@ -70,24 +68,25 @@ def test_unknown_field_conversion(): def test_items_conversion(): """Test conversion of MCP tools with items to Gemini tools.""" + inputSchema = { + 'type': 'array', + 'items': { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'string', + }, + 'key2': { + 'type': 'number', + }, + }, + }, + } mcp_tools = [ mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'array', - 'items': { - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'string', - }, - 'key2': { - 'type': 'number', - }, - }, - }, - }, + inputSchema=inputSchema, ), ] result = _mcp_utils.mcp_to_gemini_tools(mcp_tools) @@ -97,16 +96,7 @@ def test_items_conversion(): types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='ARRAY', - items=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='STRING'), - 'key2': types.Schema(type='NUMBER'), - }, - ), - ), + parameters_json_schema=inputSchema, ), ], ), @@ -115,21 +105,24 @@ def test_items_conversion(): def test_any_of_conversion(): """Test conversion of MCP tools with any_of to Gemini tools.""" + + inputSchema = { + 'type': 'object', + 'any_of': [ + { + 'type': 'string', + }, + { + 'type': 'number', + }, + ], + } + mcp_tools = [ mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'object', - 'any_of': [ - { - 'type': 'string', - }, - { - 'type': 'number', - }, - ], - }, + inputSchema=inputSchema, ), ] result = _mcp_utils.mcp_to_gemini_tools(mcp_tools) @@ -139,13 +132,7 @@ def test_any_of_conversion(): types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='OBJECT', - any_of=[ - types.Schema(type='STRING'), - types.Schema(type='NUMBER'), - ], - ), + parameters_json_schema=inputSchema, ), ], ), @@ -154,21 +141,22 @@ def test_any_of_conversion(): def test_properties_conversion(): """Test conversion of MCP tools with properties to Gemini tools.""" + inputSchema = { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'string', + }, + 'key2': { + 'type': 'number', + }, + }, + } mcp_tools = [ mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'string', - }, - 'key2': { - 'type': 'number', - }, - }, - }, + inputSchema=inputSchema, ), ] result = _mcp_utils.mcp_to_gemini_tools(mcp_tools) @@ -178,13 +166,7 @@ def test_properties_conversion(): types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='STRING'), - 'key2': types.Schema(type='NUMBER'), - }, - ), + parameters_json_schema=inputSchema, ), ], ), diff --git a/google/genai/tests/transformers/test_t_tool.py b/google/genai/tests/transformers/test_t_tool.py index 32d86221b..d9a5fcd4f 100644 --- a/google/genai/tests/transformers/test_t_tool.py +++ b/google/genai/tests/transformers/test_t_tool.py @@ -105,33 +105,29 @@ def test_mcp_tool(client): if not _is_mcp_imported: return + inputSchema = { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'string', + }, + 'key2': { + 'type': 'number', + }, + }, + } + mcp_tool = mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'string', - }, - 'key2': { - 'type': 'number', - }, - }, - }, + inputSchema=inputSchema, ) assert t.t_tool(client, mcp_tool) == types.Tool( function_declarations=[ types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='STRING'), - 'key2': types.Schema(type='NUMBER'), - }, - ), + parameters_json_schema=inputSchema, ) ] ) diff --git a/google/genai/tests/transformers/test_t_tools.py b/google/genai/tests/transformers/test_t_tools.py index 05d8ce263..bcda36d01 100644 --- a/google/genai/tests/transformers/test_t_tools.py +++ b/google/genai/tests/transformers/test_t_tools.py @@ -104,20 +104,22 @@ def test_mcp_tool(client): if not _is_mcp_imported: return + inputSchema = { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'string', + }, + 'key2': { + 'type': 'number', + }, + }, + } + mcp_tool = mcp_types.Tool( name='tool', description='tool-description', - inputSchema={ - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'string', - }, - 'key2': { - 'type': 'number', - }, - }, - }, + inputSchema=inputSchema, ) assert t.t_tools(client, [mcp_tool]) == [ types.Tool( @@ -125,13 +127,7 @@ def test_mcp_tool(client): types.FunctionDeclaration( name='tool', description='tool-description', - parameters=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='STRING'), - 'key2': types.Schema(type='NUMBER'), - }, - ), + parameters_json_schema=inputSchema, ) ] ) @@ -143,29 +139,32 @@ def test_multiple_tools(client): if not _is_mcp_imported: return + inputSchema1 = { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'string', + }, + }, + } + inputSchema2 = { + 'type': 'object', + 'properties': { + 'key1': { + 'type': 'number', + }, + }, + } + mcp_tool1 = mcp_types.Tool( name='tool1', description='tool1-description', - inputSchema={ - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'string', - }, - }, - }, + inputSchema=inputSchema1, ) mcp_tool2 = mcp_types.Tool( name='tool2', description='tool2-description', - inputSchema={ - 'type': 'object', - 'properties': { - 'key1': { - 'type': 'number', - }, - }, - }, + inputSchema=inputSchema2, ) assert t.t_tools(client, [mcp_tool1, mcp_tool2]) == [ types.Tool( @@ -173,22 +172,12 @@ def test_multiple_tools(client): types.FunctionDeclaration( name='tool1', description='tool1-description', - parameters=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='STRING'), - }, - ), + parameters_json_schema=inputSchema1, ), types.FunctionDeclaration( name='tool2', description='tool2-description', - parameters=types.Schema( - type='OBJECT', - properties={ - 'key1': types.Schema(type='NUMBER'), - }, - ), + parameters_json_schema=inputSchema2, ), ] ),