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
6 changes: 1 addition & 5 deletions google/genai/_mcp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}]
)

Expand Down
28 changes: 16 additions & 12 deletions google/genai/tests/live/test_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
},
Expand All @@ -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',
},
},
},
Expand All @@ -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
Expand Down Expand Up @@ -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',
},
},
},
Expand All @@ -1264,11 +1268,11 @@ async def list_tools(self):
),
'tools': [{
'functionDeclarations': [{
'parameters': {
'type': 'OBJECT',
'parametersJsonSchema': {
'type': 'object',
'properties': {
'location': {
'type': 'STRING',
'type': 'string',
},
},
},
Expand Down
122 changes: 52 additions & 70 deletions google/genai/tests/mcp/test_mcp_to_gemini_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
),
],
),
Expand All @@ -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)
Expand All @@ -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,
),
],
),
Expand All @@ -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)
Expand All @@ -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,
),
],
),
Expand All @@ -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)
Expand All @@ -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,
),
],
),
Expand Down
32 changes: 14 additions & 18 deletions google/genai/tests/transformers/test_t_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
]
)
Expand Down
Loading