@@ -3907,7 +3907,7 @@ def _get_mcp_tool(self):
39073907 server_url = "https://gitmcp.io/Azure/azure-rest-api-specs" ,
39083908 allowed_tools = [], # Optional: specify allowed tools
39093909 )
3910-
3910+
39113911 @agentClientPreparer ()
39123912 @recorded_by_proxy
39133913 def test_mcp_tool (self , ** kwargs ):
@@ -3928,16 +3928,20 @@ def test_mcp_tool(self, **kwargs):
39283928 content = "Please summarize the Azure REST API specifications Readme" ,
39293929 )
39303930 mcp_tool .update_headers ("SuperSecret" , "123456" )
3931- run = agents_client .runs .create (thread_id = thread .id , agent_id = agent .id , tool_resources = mcp_tool .resources )
3931+ run = agents_client .runs .create (
3932+ thread_id = thread .id , agent_id = agent .id , tool_resources = mcp_tool .resources
3933+ )
39323934 was_approved = False
39333935 while run .status in [RunStatus .QUEUED , RunStatus .IN_PROGRESS , RunStatus .REQUIRES_ACTION ]:
39343936 time .sleep (self ._sleep_time ())
39353937 run = agents_client .runs .get (thread_id = thread .id , run_id = run .id )
3936-
3937- if run .status == RunStatus .REQUIRES_ACTION and isinstance (run .required_action , SubmitToolApprovalAction ):
3938+
3939+ if run .status == RunStatus .REQUIRES_ACTION and isinstance (
3940+ run .required_action , SubmitToolApprovalAction
3941+ ):
39383942 tool_calls = run .required_action .submit_tool_approval .tool_calls
39393943 assert tool_calls , "No tool calls to approve."
3940-
3944+
39413945 tool_approvals = []
39423946 for tool_call in tool_calls :
39433947 if isinstance (tool_call , RequiredMcpToolCall ):
@@ -3948,15 +3952,15 @@ def test_mcp_tool(self, **kwargs):
39483952 headers = mcp_tool .headers ,
39493953 )
39503954 )
3951-
3955+
39523956 if tool_approvals :
39533957 was_approved = True
39543958 agents_client .runs .submit_tool_outputs (
39553959 thread_id = thread .id , run_id = run .id , tool_approvals = tool_approvals
39563960 )
39573961 assert was_approved , "The run was never approved."
39583962 assert run .status != RunStatus .FAILED , run .last_error
3959-
3963+
39603964 is_activity_step_found = False
39613965 is_tool_call_step_found = False
39623966 for run_step in agents_client .run_steps .list (thread_id = thread .id , run_id = run .id ):
@@ -3996,7 +4000,9 @@ def test_mcp_tool_streaming(self, **kwargs):
39964000 mcp_tool .update_headers ("SuperSecret" , "123456" )
39974001
39984002 try :
3999- with agents_client .runs .stream (thread_id = thread .id , agent_id = agent .id , tool_resources = mcp_tool .resources ) as stream :
4003+ with agents_client .runs .stream (
4004+ thread_id = thread .id , agent_id = agent .id , tool_resources = mcp_tool .resources
4005+ ) as stream :
40004006 is_started = False
40014007 received_message = False
40024008 got_expected_delta = False
@@ -4005,29 +4011,29 @@ def test_mcp_tool_streaming(self, **kwargs):
40054011 found_activity_details = False
40064012 found_tool_call_step = False
40074013 for event_type , event_data , _ in stream :
4008-
4014+
40094015 if isinstance (event_data , MessageDeltaChunk ):
40104016 received_message = True
4011-
4017+
40124018 elif isinstance (event_data , RunStepDeltaChunk ):
40134019 tool_calls_details = getattr (event_data .delta .step_details , "tool_calls" )
40144020 if isinstance (tool_calls_details , list ):
40154021 for tool_call in tool_calls_details :
40164022 if isinstance (tool_call , RunStepDeltaMcpToolCall ):
40174023 got_expected_delta = True
4018-
4024+
40194025 elif isinstance (event_data , ThreadRun ):
40204026 if event_type == AgentStreamEvent .THREAD_RUN_CREATED :
40214027 is_started = True
40224028 if event_data .status == RunStatus .FAILED :
40234029 raise AssertionError (event_data .last_error )
4024-
4030+
40254031 if event_data .status == RunStatus .REQUIRES_ACTION and isinstance (
40264032 event_data .required_action , SubmitToolApprovalAction
40274033 ):
40284034 tool_calls = event_data .required_action .submit_tool_approval .tool_calls
40294035 assert tool_calls , "No tool calls to approve."
4030-
4036+
40314037 tool_approvals = []
40324038 for tool_call in tool_calls :
40334039 if isinstance (tool_call , RequiredMcpToolCall ):
@@ -4038,7 +4044,7 @@ def test_mcp_tool_streaming(self, **kwargs):
40384044 headers = mcp_tool .headers ,
40394045 )
40404046 )
4041-
4047+
40424048 if tool_approvals :
40434049 # Once we receive 'requires_action' status, the next event will be DONE.
40444050 # Here we associate our existing event handler to the next stream.
@@ -4048,7 +4054,7 @@ def test_mcp_tool_streaming(self, **kwargs):
40484054 tool_approvals = tool_approvals ,
40494055 event_handler = stream ,
40504056 )
4051-
4057+
40524058 elif isinstance (event_data , RunStep ):
40534059 if event_type == AgentStreamEvent .THREAD_RUN_STEP_CREATED :
40544060 is_run_step_created = True
@@ -4059,11 +4065,10 @@ def test_mcp_tool_streaming(self, **kwargs):
40594065 for tool_call in step_details .tool_calls :
40604066 if isinstance (tool_call , RunStepMcpToolCall ):
40614067 found_tool_call_step = True
4062-
4063-
4068+
40644069 elif event_type == AgentStreamEvent .ERROR :
40654070 raise AssertionError (event_data )
4066-
4071+
40674072 elif event_type == AgentStreamEvent .DONE :
40684073 is_completed = True
40694074
0 commit comments