@@ -581,3 +581,84 @@ async def empty_tags():
581581 exclude_tags_mcp = FastApiMCP (app , exclude_tags = ["items" ])
582582 assert len (exclude_tags_mcp .tools ) == 1
583583 assert {tool .name for tool in exclude_tags_mcp .tools } == {"empty_tags" }
584+
585+
586+ def test_include_response_info_default_behavior (simple_fastapi_app : FastAPI ):
587+ """Test the default behavior of include_response_info parameter."""
588+ mcp_server = FastApiMCP (simple_fastapi_app )
589+
590+ # Check default value
591+ assert mcp_server ._include_response_info is True
592+
593+ # Check that response information is included by default
594+ for tool in mcp_server .tools :
595+ assert tool .description is not None
596+ if tool .name == "raise_error" :
597+ pass
598+ elif tool .name != "delete_item" :
599+ assert "### Responses:" in tool .description , "Response section should be present"
600+ assert "**200**" in tool .description , "200 status code should be present"
601+ assert "**Example Response:**" in tool .description , "Example response should be present"
602+ else :
603+ # The delete endpoint returns 204 with no response body
604+ assert "### Responses:" in tool .description , "Response section should be present"
605+ assert "**204**" in tool .description , "204 status code should be present"
606+
607+
608+ def test_include_response_info_false_simple_app (simple_fastapi_app : FastAPI ):
609+ """Test include_response_info=False with the simple app."""
610+ mcp_server = FastApiMCP (simple_fastapi_app , include_response_info = False )
611+
612+ # Check that response information is excluded
613+ for tool in mcp_server .tools :
614+ assert tool .description is not None
615+ assert "### Responses:" not in tool .description , "Response section should not be present"
616+ assert "**200**" not in tool .description , "200 status code should not be present"
617+ assert "**204**" not in tool .description , "204 status code should not be present"
618+ assert "**Example Response:**" not in tool .description , "Example response should not be present"
619+ assert "**Output Schema:**" not in tool .description , "Output schema should not be present"
620+
621+ # Basic tool information should still be present
622+ if tool .name == "list_items" :
623+ assert "List all items" in tool .description
624+ elif tool .name == "get_item" :
625+ assert "Get a specific item" in tool .description
626+ elif tool .name == "create_item" :
627+ assert "Create a new item" in tool .description
628+
629+
630+ def test_include_response_info_combined_with_other_options (simple_fastapi_app : FastAPI ):
631+ """Test include_response_info combined with other response-related options."""
632+ # Test with include_response_info=False and describe_all_responses=True
633+ mcp_server = FastApiMCP (
634+ simple_fastapi_app ,
635+ include_response_info = False ,
636+ describe_all_responses = True ,
637+ describe_full_response_schema = True ,
638+ )
639+
640+ # Even with describe_all_responses=True and describe_full_response_schema=True,
641+ # response information should be excluded when include_response_info=False
642+ for tool in mcp_server .tools :
643+ assert tool .description is not None
644+ assert "### Responses:" not in tool .description , "Response section should not be present"
645+ assert "**Example Response:**" not in tool .description , "Example response should not be present"
646+ assert "**Output Schema:**" not in tool .description , "Output schema should not be present"
647+
648+
649+ def test_include_response_info_true_explicit (simple_fastapi_app : FastAPI ):
650+ """Test include_response_info=True explicitly."""
651+ mcp_server = FastApiMCP (simple_fastapi_app , include_response_info = True )
652+
653+ # Check that response information is included
654+ for tool in mcp_server .tools :
655+ assert tool .description is not None
656+ if tool .name == "raise_error" :
657+ pass
658+ elif tool .name != "delete_item" :
659+ assert "### Responses:" in tool .description , "Response section should be present"
660+ assert "**200**" in tool .description , "200 status code should be present"
661+ assert "**Example Response:**" in tool .description , "Example response should be present"
662+ else :
663+ assert "### Responses:" in tool .description , "Response section should be present"
664+ assert "**204**" in tool .description , "204 status code should be present"
0 commit comments