@@ -3907,7 +3907,7 @@ def _get_mcp_tool(self):
3907
3907
server_url = "https://gitmcp.io/Azure/azure-rest-api-specs" ,
3908
3908
allowed_tools = [], # Optional: specify allowed tools
3909
3909
)
3910
-
3910
+
3911
3911
@agentClientPreparer ()
3912
3912
@recorded_by_proxy
3913
3913
def test_mcp_tool (self , ** kwargs ):
@@ -3928,16 +3928,20 @@ def test_mcp_tool(self, **kwargs):
3928
3928
content = "Please summarize the Azure REST API specifications Readme" ,
3929
3929
)
3930
3930
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
+ )
3932
3934
was_approved = False
3933
3935
while run .status in [RunStatus .QUEUED , RunStatus .IN_PROGRESS , RunStatus .REQUIRES_ACTION ]:
3934
3936
time .sleep (self ._sleep_time ())
3935
3937
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
+ ):
3938
3942
tool_calls = run .required_action .submit_tool_approval .tool_calls
3939
3943
assert tool_calls , "No tool calls to approve."
3940
-
3944
+
3941
3945
tool_approvals = []
3942
3946
for tool_call in tool_calls :
3943
3947
if isinstance (tool_call , RequiredMcpToolCall ):
@@ -3948,15 +3952,15 @@ def test_mcp_tool(self, **kwargs):
3948
3952
headers = mcp_tool .headers ,
3949
3953
)
3950
3954
)
3951
-
3955
+
3952
3956
if tool_approvals :
3953
3957
was_approved = True
3954
3958
agents_client .runs .submit_tool_outputs (
3955
3959
thread_id = thread .id , run_id = run .id , tool_approvals = tool_approvals
3956
3960
)
3957
3961
assert was_approved , "The run was never approved."
3958
3962
assert run .status != RunStatus .FAILED , run .last_error
3959
-
3963
+
3960
3964
is_activity_step_found = False
3961
3965
is_tool_call_step_found = False
3962
3966
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):
3996
4000
mcp_tool .update_headers ("SuperSecret" , "123456" )
3997
4001
3998
4002
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 :
4000
4006
is_started = False
4001
4007
received_message = False
4002
4008
got_expected_delta = False
@@ -4005,29 +4011,29 @@ def test_mcp_tool_streaming(self, **kwargs):
4005
4011
found_activity_details = False
4006
4012
found_tool_call_step = False
4007
4013
for event_type , event_data , _ in stream :
4008
-
4014
+
4009
4015
if isinstance (event_data , MessageDeltaChunk ):
4010
4016
received_message = True
4011
-
4017
+
4012
4018
elif isinstance (event_data , RunStepDeltaChunk ):
4013
4019
tool_calls_details = getattr (event_data .delta .step_details , "tool_calls" )
4014
4020
if isinstance (tool_calls_details , list ):
4015
4021
for tool_call in tool_calls_details :
4016
4022
if isinstance (tool_call , RunStepDeltaMcpToolCall ):
4017
4023
got_expected_delta = True
4018
-
4024
+
4019
4025
elif isinstance (event_data , ThreadRun ):
4020
4026
if event_type == AgentStreamEvent .THREAD_RUN_CREATED :
4021
4027
is_started = True
4022
4028
if event_data .status == RunStatus .FAILED :
4023
4029
raise AssertionError (event_data .last_error )
4024
-
4030
+
4025
4031
if event_data .status == RunStatus .REQUIRES_ACTION and isinstance (
4026
4032
event_data .required_action , SubmitToolApprovalAction
4027
4033
):
4028
4034
tool_calls = event_data .required_action .submit_tool_approval .tool_calls
4029
4035
assert tool_calls , "No tool calls to approve."
4030
-
4036
+
4031
4037
tool_approvals = []
4032
4038
for tool_call in tool_calls :
4033
4039
if isinstance (tool_call , RequiredMcpToolCall ):
@@ -4038,7 +4044,7 @@ def test_mcp_tool_streaming(self, **kwargs):
4038
4044
headers = mcp_tool .headers ,
4039
4045
)
4040
4046
)
4041
-
4047
+
4042
4048
if tool_approvals :
4043
4049
# Once we receive 'requires_action' status, the next event will be DONE.
4044
4050
# Here we associate our existing event handler to the next stream.
@@ -4048,7 +4054,7 @@ def test_mcp_tool_streaming(self, **kwargs):
4048
4054
tool_approvals = tool_approvals ,
4049
4055
event_handler = stream ,
4050
4056
)
4051
-
4057
+
4052
4058
elif isinstance (event_data , RunStep ):
4053
4059
if event_type == AgentStreamEvent .THREAD_RUN_STEP_CREATED :
4054
4060
is_run_step_created = True
@@ -4059,11 +4065,10 @@ def test_mcp_tool_streaming(self, **kwargs):
4059
4065
for tool_call in step_details .tool_calls :
4060
4066
if isinstance (tool_call , RunStepMcpToolCall ):
4061
4067
found_tool_call_step = True
4062
-
4063
-
4068
+
4064
4069
elif event_type == AgentStreamEvent .ERROR :
4065
4070
raise AssertionError (event_data )
4066
-
4071
+
4067
4072
elif event_type == AgentStreamEvent .DONE :
4068
4073
is_completed = True
4069
4074
0 commit comments