mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-13 17:19:10 +02:00
Update for 'result' kwarg instead of 'value'
This commit is contained in:
parent
d8dc28b9b2
commit
ddb557ba30
2 changed files with 29 additions and 29 deletions
|
|
@ -355,7 +355,7 @@ class TestCallTools:
|
|||
result = await manager.call_tool("add", {"a": 1, "b": 2})
|
||||
|
||||
assert result.content[0].text == "3" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 3}
|
||||
assert result.structured_content == {"result": 3}
|
||||
|
||||
async def test_call_async_tool(self):
|
||||
async def double(n: int) -> int:
|
||||
|
|
@ -367,7 +367,7 @@ class TestCallTools:
|
|||
manager.add_tool(tool)
|
||||
result = await manager.call_tool("double", {"n": 5})
|
||||
assert result.content[0].text == "10" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 10}
|
||||
assert result.structured_content == {"result": 10}
|
||||
|
||||
async def test_call_tool_callable_object(self):
|
||||
class Adder:
|
||||
|
|
@ -382,7 +382,7 @@ class TestCallTools:
|
|||
manager.add_tool(tool)
|
||||
result = await manager.call_tool("Adder", {"x": 1, "y": 2})
|
||||
assert result.content[0].text == "3" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 3}
|
||||
assert result.structured_content == {"result": 3}
|
||||
|
||||
async def test_call_tool_callable_object_async(self):
|
||||
class Adder:
|
||||
|
|
@ -397,7 +397,7 @@ class TestCallTools:
|
|||
manager.add_tool(tool)
|
||||
result = await manager.call_tool("Adder", {"x": 1, "y": 2})
|
||||
assert result.content[0].text == "3" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 3}
|
||||
assert result.structured_content == {"result": 3}
|
||||
|
||||
async def test_call_tool_with_default_args(self):
|
||||
def add(a: int, b: int = 1) -> int:
|
||||
|
|
@ -410,7 +410,7 @@ class TestCallTools:
|
|||
result = await manager.call_tool("add", {"a": 1})
|
||||
|
||||
assert result.content[0].text == "2" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 2}
|
||||
assert result.structured_content == {"result": 2}
|
||||
|
||||
async def test_call_tool_with_missing_args(self):
|
||||
def add(a: int, b: int) -> int:
|
||||
|
|
@ -438,7 +438,7 @@ class TestCallTools:
|
|||
|
||||
result = await manager.call_tool("sum_vals", {"vals": [1, 2, 3]})
|
||||
assert result.content[0].text == "6" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 6}
|
||||
assert result.structured_content == {"result": 6}
|
||||
|
||||
async def test_call_tool_with_list_str_or_str_input(self):
|
||||
def concat_strs(vals: list[str] | str) -> str:
|
||||
|
|
@ -451,11 +451,11 @@ class TestCallTools:
|
|||
# Try both with plain python object and with JSON list
|
||||
result = await manager.call_tool("concat_strs", {"vals": ["a", "b", "c"]})
|
||||
assert result.content[0].text == "abc" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": "abc"}
|
||||
assert result.structured_content == {"result": "abc"}
|
||||
|
||||
result = await manager.call_tool("concat_strs", {"vals": "a"})
|
||||
assert result.content[0].text == "a" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": "a"}
|
||||
assert result.structured_content == {"result": "a"}
|
||||
|
||||
async def test_call_tool_with_complex_model(self):
|
||||
class MyShrimpTank(BaseModel):
|
||||
|
|
@ -487,7 +487,7 @@ class TestCallTools:
|
|||
)
|
||||
|
||||
assert result.content[0].text == '[\n "rex",\n "gertrude"\n]' # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": ["rex", "gertrude"]}
|
||||
assert result.structured_content == {"result": ["rex", "gertrude"]}
|
||||
|
||||
async def test_call_tool_with_custom_serializer(self):
|
||||
"""Test that a custom serializer provided to FastMCP is used by tools."""
|
||||
|
|
@ -533,7 +533,7 @@ class TestCallTools:
|
|||
== 'CUSTOM:[{"key": "value", "number": 123}, {"key": "value2", "number": 456}]' # type: ignore[attr-defined]
|
||||
)
|
||||
assert result.structured_content == {
|
||||
"value": [
|
||||
"result": [
|
||||
{"key": "value", "number": 123},
|
||||
{"key": "value2", "number": 456},
|
||||
]
|
||||
|
|
@ -559,7 +559,7 @@ class TestCallTools:
|
|||
result.content[0].text # type: ignore[attr-defined]
|
||||
== pydantic_core.to_json(uuid_result).decode()
|
||||
)
|
||||
assert result.structured_content == {"value": str(uuid_result)}
|
||||
assert result.structured_content == {"result": str(uuid_result)}
|
||||
|
||||
|
||||
class TestToolSchema:
|
||||
|
|
@ -630,7 +630,7 @@ class TestContextHandling:
|
|||
async with context:
|
||||
result = await manager.call_tool("tool_with_context", {"x": 42})
|
||||
assert result.content[0].text == "42" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": "42"}
|
||||
assert result.structured_content == {"result": "42"}
|
||||
|
||||
async def test_context_injection_async(self):
|
||||
"""Test that context is properly injected in async tools."""
|
||||
|
|
@ -649,7 +649,7 @@ class TestContextHandling:
|
|||
async with context:
|
||||
result = await manager.call_tool("async_tool", {"x": 42})
|
||||
assert result.content[0].text == "42" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": "42"}
|
||||
assert result.structured_content == {"result": "42"}
|
||||
|
||||
async def test_context_optional(self):
|
||||
"""Test that context is optional when calling tools."""
|
||||
|
|
@ -668,7 +668,7 @@ class TestContextHandling:
|
|||
async with context:
|
||||
result = await manager.call_tool("tool_with_context", {"x": 42})
|
||||
assert result.content[0].text == "42" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 42}
|
||||
assert result.structured_content == {"result": 42}
|
||||
|
||||
def test_parameterized_context_parameter_detection(self):
|
||||
"""Test that context parameters are properly detected in
|
||||
|
|
@ -777,7 +777,7 @@ class TestCustomToolNames:
|
|||
# Tool should be callable by its custom name
|
||||
result = await manager.call_tool("custom_multiply", {"a": 5, "b": 3})
|
||||
assert result.content[0].text == "15" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 15}
|
||||
assert result.structured_content == {"result": 15}
|
||||
|
||||
# Original name should not be registered
|
||||
with pytest.raises(NotFoundError, match="Tool 'multiply' not found"):
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ async def test_tool_defaults_are_maintained_on_unmapped_args(add_tool):
|
|||
)
|
||||
result = await new_tool.run(arguments={"new_x": 1})
|
||||
# The parent tool returns int which gets wrapped as structured output
|
||||
assert result.structured_content == {"value": 11}
|
||||
assert result.structured_content == {"result": 11}
|
||||
|
||||
|
||||
async def test_tool_defaults_are_maintained_on_mapped_args(add_tool):
|
||||
|
|
@ -62,7 +62,7 @@ async def test_tool_defaults_are_maintained_on_mapped_args(add_tool):
|
|||
)
|
||||
result = await new_tool.run(arguments={"old_x": 1})
|
||||
# The parent tool returns int which gets wrapped as structured output
|
||||
assert result.structured_content == {"value": 11}
|
||||
assert result.structured_content == {"result": 11}
|
||||
|
||||
|
||||
def test_tool_change_arg_name(add_tool):
|
||||
|
|
@ -89,7 +89,7 @@ async def test_tool_drop_arg(add_tool):
|
|||
)
|
||||
assert sorted(new_tool.parameters["properties"]) == ["old_x"]
|
||||
result = await new_tool.run(arguments={"old_x": 1})
|
||||
assert result.structured_content == {"value": 11}
|
||||
assert result.structured_content == {"result": 11}
|
||||
|
||||
|
||||
async def test_dropped_args_error_if_provided(add_tool):
|
||||
|
|
@ -111,7 +111,7 @@ async def test_hidden_arg_with_constant_default(add_tool):
|
|||
assert sorted(new_tool.parameters["properties"]) == ["old_x"]
|
||||
# Should pass old_x=5 and old_y=20 to parent
|
||||
result = await new_tool.run(arguments={"old_x": 5})
|
||||
assert result.structured_content == {"value": 25}
|
||||
assert result.structured_content == {"result": 25}
|
||||
|
||||
|
||||
async def test_hidden_arg_without_default_uses_parent_default(add_tool):
|
||||
|
|
@ -124,7 +124,7 @@ async def test_hidden_arg_without_default_uses_parent_default(add_tool):
|
|||
# Should pass old_x=3 and let parent use its default old_y=10
|
||||
result = await new_tool.run(arguments={"old_x": 3})
|
||||
assert result.content[0].text == "13" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 13}
|
||||
assert result.structured_content == {"result": 13}
|
||||
|
||||
|
||||
async def test_mixed_hidden_args_with_custom_function(add_tool):
|
||||
|
|
@ -150,7 +150,7 @@ async def test_mixed_hidden_args_with_custom_function(add_tool):
|
|||
# Should pass visible_x=7 as old_x=7 and old_y=25 to parent
|
||||
result = await new_tool.run(arguments={"visible_x": 7})
|
||||
assert result.content[0].text == "32" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 32}
|
||||
assert result.structured_content == {"result": 32}
|
||||
|
||||
|
||||
async def test_hide_required_param_without_default_raises_error():
|
||||
|
|
@ -188,7 +188,7 @@ async def test_hide_required_param_with_user_default_works():
|
|||
assert sorted(new_tool.parameters["properties"]) == ["optional_param"]
|
||||
# Should pass required_param=5 and optional_param=20 to parent
|
||||
result = await new_tool.run(arguments={"optional_param": 20})
|
||||
assert result.structured_content == {"value": 25}
|
||||
assert result.structured_content == {"result": 25}
|
||||
|
||||
|
||||
async def test_forward_with_argument_mapping(add_tool):
|
||||
|
|
@ -208,7 +208,7 @@ async def test_forward_with_argument_mapping(add_tool):
|
|||
|
||||
result = await new_tool.run(arguments={"new_x": 2, "new_y": 3})
|
||||
assert result.content[0].text == "5" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 5}
|
||||
assert result.structured_content == {"result": 5}
|
||||
|
||||
|
||||
async def test_forward_with_incorrect_args_raises_error(add_tool):
|
||||
|
|
@ -249,7 +249,7 @@ async def test_forward_raw_without_argument_mapping(add_tool):
|
|||
|
||||
result = await new_tool.run(arguments={"new_x": 2, "new_y": 3})
|
||||
assert result.content[0].text == "5" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 5}
|
||||
assert result.structured_content == {"result": 5}
|
||||
|
||||
|
||||
async def test_custom_fn_with_kwargs_and_no_transform_args(add_tool):
|
||||
|
|
@ -260,7 +260,7 @@ async def test_custom_fn_with_kwargs_and_no_transform_args(add_tool):
|
|||
new_tool = Tool.from_tool(add_tool, transform_fn=custom_fn)
|
||||
result = await new_tool.run(arguments={"extra": 1, "old_x": 2, "old_y": 3})
|
||||
assert result.content[0].text == "6" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 6}
|
||||
assert result.structured_content == {"result": 6}
|
||||
assert new_tool.parameters["required"] == IsList(
|
||||
"extra", "old_x", check_order=False
|
||||
)
|
||||
|
|
@ -278,7 +278,7 @@ async def test_fn_with_kwargs_passes_through_original_args(add_tool):
|
|||
new_tool = Tool.from_tool(add_tool, transform_fn=custom_fn)
|
||||
result = await new_tool.run(arguments={"new_y": 2, "old_y": 3})
|
||||
assert result.content[0].text == "5" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 5}
|
||||
assert result.structured_content == {"result": 5}
|
||||
|
||||
|
||||
async def test_fn_with_kwargs_receives_transformed_arg_names(add_tool):
|
||||
|
|
@ -297,7 +297,7 @@ async def test_fn_with_kwargs_receives_transformed_arg_names(add_tool):
|
|||
)
|
||||
result = await new_tool.run(arguments={"new_x": 2, "old_y": 3})
|
||||
assert result.content[0].text == "5" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 5}
|
||||
assert result.structured_content == {"result": 5}
|
||||
|
||||
|
||||
async def test_fn_with_kwargs_handles_partial_explicit_args(add_tool):
|
||||
|
|
@ -318,7 +318,7 @@ async def test_fn_with_kwargs_handles_partial_explicit_args(add_tool):
|
|||
arguments={"new_x": 3, "old_y": 7, "some_other_param": "test"}
|
||||
)
|
||||
assert result.content[0].text == "10" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 10}
|
||||
assert result.structured_content == {"result": 10}
|
||||
|
||||
|
||||
async def test_fn_with_kwargs_mixed_mapped_and_unmapped_args(add_tool):
|
||||
|
|
@ -337,7 +337,7 @@ async def test_fn_with_kwargs_mixed_mapped_and_unmapped_args(add_tool):
|
|||
) # only map 'a'
|
||||
result = await new_tool.run(arguments={"new_x": 1, "old_y": 5})
|
||||
assert result.content[0].text == "6" # type: ignore[attr-defined]
|
||||
assert result.structured_content == {"value": 6}
|
||||
assert result.structured_content == {"result": 6}
|
||||
|
||||
|
||||
async def test_fn_with_kwargs_dropped_args_not_in_kwargs(add_tool):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue