-
Notifications
You must be signed in to change notification settings - Fork 1.5k
tests: Add unit tests for mcp_tool #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
683e86d
add unit_test for mcptool and mcptoolset
pkduongsu 8faa342
split mcp_tool and mcp_toolset tests
pkduongsu a6b0ad1
add conversion utils tests
pkduongsu 88a8f51
Merge branch 'main' into mcp-unit-tests
pkduongsu c4a23d9
fix import
pkduongsu e035f22
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu df1658b
merge branch 'mcp-unit-tests'
pkduongsu cec6595
Delete uv.lock
pkduongsu b5adaf8
Merge branch 'main' of https://github.com/pkduongsu/adk-python into m…
pkduongsu d144074
Merge branch 'main' into mcp-unit-tests
pkduongsu f2e0dd4
Merge branch 'main' into mcp-unit-tests
pkduongsu b60a979
Delete src/google/adk/models/gemini_llm_connection.py
pkduongsu a43efc8
Delete src/google/adk/sessions/in_memory_session_service.py
pkduongsu e0896c4
Delete src/google/adk/tools/mcp_tool/mcp_toolset.py
pkduongsu cb7ac8e
Delete tests/unittests/cli/utils/test_cli_tools_click.py
pkduongsu 12c77c2
put files under mcp_tool folder
pkduongsu f9165b9
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu 752bbc1
add tests for mcp toolset and mcp tool
pkduongsu 5504b79
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu fdbf7fe
put files under mcp_tool folder
pkduongsu 05cea2b
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu 42fc674
add tests for mcp_tool, mcp_toolset, conversion_utils
pkduongsu 17874f9
Merge pull request #1 from pkduongsu/recovery-branch
pkduongsu 8a673f9
update
pkduongsu 8ca465a
update branch
pkduongsu 60a976a
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu a50d9e5
remove duplicate file
pkduongsu c86c0ad
Merge branch 'google:main' into mcp-unit-tests
pkduongsu 5089008
Merge branch 'google:main' into mcp-unit-tests
pkduongsu 19bfb19
improve test_coverage, fix test_mcp_toolset to match new refactored ver
pkduongsu 8c76197
"revert changes for mcp_session_manager"
pkduongsu f80ccf7
Merge branch 'google:main' into mcp-unit-tests
pkduongsu 9695052
Merge branch 'google:main' into mcp-unit-tests
pkduongsu e5d18b5
Merge branch 'main' into mcp-unit-tests
pkduongsu a49237a
Merge branch 'main' into mcp-unit-tests
pkduongsu d6a26bd
Merge branch 'main' into mcp-unit-tests
hangfei 4f61621
Merge branch 'main' into mcp-unit-tests
hangfei c0e1368
Merge branch 'google:main' into mcp-unit-tests
pkduongsu 71bf490
remove python 3.9 test
pkduongsu 0a5321a
Merge branch 'main' into mcp-unit-tests
pkduongsu e5372c6
Remove old test_mcp_tool
pkduongsu 68dd494
'remove old tests'
pkduongsu 842c8a0
Merge branch 'mcp-unit-tests' of https://github.com/pkduongsu/adk-pyt…
pkduongsu 891afb4
Merge branch 'main' into mcp-unit-tests
hangfei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add conversion utils tests
- Loading branch information
commit a6b0ad13c2eb300794869f4fea5a255f33446fe4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
from typing import Any, Dict | ||
from unittest.mock import MagicMock | ||
|
||
import pytest | ||
from google.genai.types import Schema, Type | ||
|
||
from src.google.adk.tools.mcp_tool.conversion_utils import ( | ||
adk_to_mcp_tool_type, | ||
gemini_to_json_schema, | ||
) | ||
from src.google.adk.tools.base_tool import BaseTool | ||
import mcp.types as mcp_types | ||
|
||
|
||
def test_adk_to_mcp_tool_type(): | ||
"""Test adk_to_mcp_tool_type with a mock BaseTool.""" | ||
mock_tool = MagicMock(spec=BaseTool) | ||
mock_tool.name = "test_tool" | ||
mock_tool.description = "test_description" | ||
mock_tool._get_declaration.return_value = None | ||
|
||
mcp_tool = adk_to_mcp_tool_type(mock_tool) | ||
|
||
assert isinstance(mcp_tool, mcp_types.Tool) | ||
assert mcp_tool.name == "test_tool" | ||
assert mcp_tool.description == "test_description" | ||
assert mcp_tool.inputSchema == {} | ||
|
||
mock_declaration = MagicMock() | ||
mock_declaration.parameters = Schema(type=Type.STRING) | ||
mock_tool._get_declaration.return_value = mock_declaration | ||
mcp_tool = adk_to_mcp_tool_type(mock_tool) | ||
assert mcp_tool.inputSchema == {"type": "string"} | ||
|
||
|
||
def test_gemini_to_json_schema_string(): | ||
"""Test gemini_to_json_schema with a STRING schema.""" | ||
gemini_schema = Schema(type=Type.STRING, title="test_string", description="test string description", default="test", enum=["a", "b"], format="test_format", example="example", pattern="test_pattern", min_length=1, max_length=10) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == { | ||
"type": "string", | ||
"title": "test_string", | ||
"description": "test string description", | ||
"default": "test", | ||
"enum": ["a", "b"], | ||
"format": "test_format", | ||
"example": "example", | ||
"pattern": "test_pattern", | ||
"minLength": 1, | ||
"maxLength": 10, | ||
} | ||
|
||
|
||
def test_gemini_to_json_schema_number(): | ||
"""Test gemini_to_json_schema with a NUMBER schema.""" | ||
gemini_schema = Schema(type=Type.NUMBER, minimum=1.0, maximum=10.0) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "number", "minimum": 1.0, "maximum": 10.0} | ||
|
||
|
||
def test_gemini_to_json_schema_integer(): | ||
"""Test gemini_to_json_schema with an INTEGER schema.""" | ||
gemini_schema = Schema(type=Type.INTEGER, minimum=1, maximum=10) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "integer", "minimum": 1, "maximum": 10} | ||
|
||
|
||
def test_gemini_to_json_schema_array(): | ||
"""Test gemini_to_json_schema with an ARRAY schema.""" | ||
gemini_schema = Schema(type=Type.ARRAY, items=Schema(type=Type.STRING), min_items=1, max_items=10) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 10} | ||
|
||
|
||
def test_gemini_to_json_schema_object(): | ||
"""Test gemini_to_json_schema with an OBJECT schema.""" | ||
gemini_schema = Schema(type=Type.OBJECT, properties={"prop1": Schema(type=Type.STRING)}, required=["prop1"], min_properties=1, max_properties=10) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "object", "properties": {"prop1": {"type": "string"}}, "required": ["prop1"], "minProperties": 1, "maxProperties": 10} | ||
|
||
|
||
def test_gemini_to_json_schema_nullable(): | ||
"""Test gemini_to_json_schema with a nullable schema.""" | ||
gemini_schema = Schema(type=Type.STRING, nullable=True) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "string", "nullable": True} | ||
|
||
|
||
def test_gemini_to_json_schema_any_of(): | ||
"""Test gemini_to_json_schema with an anyOf schema.""" | ||
gemini_schema = Schema(type=Type.OBJECT, any_of=[Schema(type=Type.STRING), Schema(type=Type.INTEGER)]) | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "object", "anyOf": [{"type": "string"}, {"type": "integer"}]} | ||
|
||
|
||
def test_gemini_to_json_schema_type_error(): | ||
"""Test gemini_to_json_schema raises TypeError when input is not a Schema.""" | ||
with pytest.raises(TypeError): | ||
gemini_to_json_schema("not a schema") | ||
|
||
|
||
def test_gemini_to_json_schema_unspecified_type(): | ||
"""Test gemini_to_json_schema with an unspecified type.""" | ||
gemini_schema = Schema() | ||
json_schema = gemini_to_json_schema(gemini_schema) | ||
assert json_schema == {"type": "null"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.