@@ -640,3 +640,74 @@ def test_init_validation(self):
640640
641641 with pytest .raises (TypeError ):
642642 MCPTool (mcp_tool = self .mock_mcp_tool ) # Missing session manager
643+
644+ @pytest .mark .asyncio
645+ async def test_run_async_impl_with_header_provider_no_auth (self ):
646+ """Test running tool with header_provider but no auth."""
647+ expected_headers = {"X-Tenant-ID" : "test-tenant" }
648+ header_provider = Mock (return_value = expected_headers )
649+ tool = MCPTool (
650+ mcp_tool = self .mock_mcp_tool ,
651+ mcp_session_manager = self .mock_session_manager ,
652+ header_provider = header_provider ,
653+ )
654+
655+ expected_response = {"result" : "success" }
656+ self .mock_session .call_tool = AsyncMock (return_value = expected_response )
657+
658+ tool_context = Mock (spec = ToolContext )
659+ tool_context ._invocation_context = Mock ()
660+ args = {"param1" : "test_value" }
661+
662+ result = await tool ._run_async_impl (
663+ args = args , tool_context = tool_context , credential = None
664+ )
665+
666+ assert result == expected_response
667+ header_provider .assert_called_once ()
668+ self .mock_session_manager .create_session .assert_called_once_with (
669+ headers = expected_headers
670+ )
671+ self .mock_session .call_tool .assert_called_once_with (
672+ "test_tool" , arguments = args
673+ )
674+
675+ @pytest .mark .asyncio
676+ async def test_run_async_impl_with_header_provider_and_oauth2 (self ):
677+ """Test running tool with header_provider and OAuth2 auth."""
678+ dynamic_headers = {"X-Tenant-ID" : "test-tenant" }
679+ header_provider = Mock (return_value = dynamic_headers )
680+ tool = MCPTool (
681+ mcp_tool = self .mock_mcp_tool ,
682+ mcp_session_manager = self .mock_session_manager ,
683+ header_provider = header_provider ,
684+ )
685+
686+ oauth2_auth = OAuth2Auth (access_token = "test_access_token" )
687+ credential = AuthCredential (
688+ auth_type = AuthCredentialTypes .OAUTH2 , oauth2 = oauth2_auth
689+ )
690+
691+ expected_response = {"result" : "success" }
692+ self .mock_session .call_tool = AsyncMock (return_value = expected_response )
693+
694+ tool_context = Mock (spec = ToolContext )
695+ tool_context ._invocation_context = Mock ()
696+ args = {"param1" : "test_value" }
697+
698+ result = await tool ._run_async_impl (
699+ args = args , tool_context = tool_context , credential = credential
700+ )
701+
702+ assert result == expected_response
703+ header_provider .assert_called_once ()
704+ self .mock_session_manager .create_session .assert_called_once ()
705+ call_args = self .mock_session_manager .create_session .call_args
706+ headers = call_args [1 ]["headers" ]
707+ assert headers == {
708+ "Authorization" : "Bearer test_access_token" ,
709+ "X-Tenant-ID" : "test-tenant" ,
710+ }
711+ self .mock_session .call_tool .assert_called_once_with (
712+ "test_tool" , arguments = args
713+ )
0 commit comments