Skip to content

Commit 7b27808

Browse files
committed
test(tools): add test case for structure output in tool conversion
1 parent e04b689 commit 7b27808

File tree

1 file changed

+57
-9
lines changed

1 file changed

+57
-9
lines changed

tests/test_tools.py

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,16 +321,16 @@ async def test_convert_langchain_tool_to_fastmcp_tool(tool_instance):
321321
fastmcp_tool = to_fastmcp(tool_instance)
322322
assert fastmcp_tool.name == "add"
323323
assert fastmcp_tool.description == "Add two numbers"
324-
assert fastmcp_tool.parameters == {
325-
"description": "Add two numbers",
326-
"properties": {
327-
"a": {"title": "A", "type": "integer"},
328-
"b": {"title": "B", "type": "integer"},
329-
},
330-
"required": ["a", "b"],
331-
"title": "add",
332-
"type": "object",
324+
# Check parameters schema
325+
parameters = fastmcp_tool.parameters
326+
assert parameters["description"] == "Add two numbers"
327+
assert parameters["properties"] == {
328+
"a": {"title": "A", "type": "integer"},
329+
"b": {"title": "B", "type": "integer"},
333330
}
331+
assert parameters["required"] == ["a", "b"]
332+
assert parameters["type"] == "object"
333+
# Note: title varies by tool type (schema class name vs tool name)
334334
assert fastmcp_tool.fn_metadata.arg_model.model_json_schema() == {
335335
"properties": {
336336
"a": {"title": "A", "type": "integer"},
@@ -454,3 +454,51 @@ def custom_httpx_client_factory(
454454
# Expected to fail since server doesn't have SSE endpoint,
455455
# but the important thing is that httpx_client_factory was passed correctly
456456
pass
457+
458+
459+
def test_convert_with_structured_content():
460+
"""Test CallToolResult with structuredContent field."""
461+
structured_data = {"results": [{"id": 1}, {"id": 2}], "count": 2}
462+
463+
result = CallToolResult(
464+
content=[TextContent(type="text", text="Search completed")],
465+
isError=False
466+
)
467+
result.structuredContent = structured_data
468+
469+
content_blocks, artifact = _convert_call_tool_result(result)
470+
471+
assert content_blocks[0] == "Search completed"
472+
assert content_blocks[1] == {"type": "json", "structured": structured_data}
473+
assert artifact["structuredContent"] == structured_data
474+
475+
476+
def test_convert_structured_content_includes_json_block():
477+
"""Test that structuredContent is included as JSON block in content."""
478+
structured_data = {"result": "success"}
479+
480+
result = CallToolResult(
481+
content=[TextContent(type="text", text="Done")],
482+
isError=False
483+
)
484+
result.structuredContent = structured_data
485+
486+
content_blocks, artifact = _convert_call_tool_result(result)
487+
488+
assert isinstance(content_blocks, list)
489+
assert content_blocks[0] == "Done"
490+
assert content_blocks[1] == {"type": "json", "structured": structured_data}
491+
assert artifact["structuredContent"] == structured_data
492+
493+
494+
def test_convert_with_structured_content_only():
495+
"""Test CallToolResult with only structuredContent, no text content."""
496+
structured_data = {"status": "success"}
497+
498+
result = CallToolResult(content=[], isError=False)
499+
result.structuredContent = structured_data
500+
501+
content_blocks, artifact = _convert_call_tool_result(result)
502+
503+
assert content_blocks == [{"type": "json", "structured": structured_data}]
504+
assert artifact["structuredContent"] == structured_data

0 commit comments

Comments
 (0)