Skip to content

Commit fd786c2

Browse files
authored
[AI Agents] add MCPTool class and sample (#41886)
* [AI Agents] initial code gen * update patch files, add sample * remove call debug output from sample * set default require_approval to "always" * update aio patch with tool_approvals * review, build feedback * more review feedback * review feedback * update changelog * review feedback
1 parent 03f80bd commit fd786c2

File tree

12 files changed

+788
-40
lines changed

12 files changed

+788
-40
lines changed

sdk/ai/azure-ai-agents/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
# Release History
44

5+
## 1.1.0b4 (Unreleased)
6+
7+
### Features Added
8+
9+
- Added support for MCP tool. For more information, see https://learn.microsoft.com/azure/ai-foundry/agents/how-to/tools/model-context-protocol
10+
11+
### Sample updates
12+
13+
- Added sample showing usage of MCP tool.
14+
515
## 1.1.0b3 (2025-06-30)
616

717
### Features Added

sdk/ai/azure-ai-agents/apiview-properties.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"azure.ai.agents.models.FunctionName": "Azure.AI.Agents.FunctionName",
4242
"azure.ai.agents.models.FunctionToolDefinition": "Azure.AI.Agents.FunctionToolDefinition",
4343
"azure.ai.agents.models.IncompleteRunDetails": "Azure.AI.Agents.IncompleteRunDetails",
44+
"azure.ai.agents.models.MCPToolDefinition": "Azure.AI.Agents.MCPToolDefinition",
45+
"azure.ai.agents.models.MCPToolResource": "Azure.AI.Agents.MCPToolResource",
4446
"azure.ai.agents.models.MessageAttachment": "Azure.AI.Agents.MessageAttachment",
4547
"azure.ai.agents.models.MessageContent": "Azure.AI.Agents.MessageContent",
4648
"azure.ai.agents.models.MessageDelta": "Azure.AI.Agents.MessageDelta",
@@ -88,6 +90,7 @@
8890
"azure.ai.agents.models.RequiredToolCall": "Azure.AI.Agents.RequiredToolCall",
8991
"azure.ai.agents.models.RequiredFunctionToolCall": "Azure.AI.Agents.RequiredFunctionToolCall",
9092
"azure.ai.agents.models.RequiredFunctionToolCallDetails": "Azure.AI.Agents.RequiredFunctionToolCallDetails",
93+
"azure.ai.agents.models.RequiredMcpToolCall": "Azure.AI.Agents.RequiredMcpToolCall",
9194
"azure.ai.agents.models.ResponseFormatJsonSchema": "Azure.AI.Agents.ResponseFormatJsonSchema",
9295
"azure.ai.agents.models.ResponseFormatJsonSchemaType": "Azure.AI.Agents.ResponseFormatJsonSchemaType",
9396
"azure.ai.agents.models.RunCompletionUsage": "Azure.AI.Agents.RunCompletionUsage",
@@ -129,6 +132,7 @@
129132
"azure.ai.agents.models.RunStepFileSearchToolCallResults": "Azure.AI.Agents.RunStepFileSearchToolCallResults",
130133
"azure.ai.agents.models.RunStepFunctionToolCall": "Azure.AI.Agents.RunStepFunctionToolCall",
131134
"azure.ai.agents.models.RunStepFunctionToolCallDetails": "Azure.AI.Agents.RunStepFunctionToolCallDetails",
135+
"azure.ai.agents.models.RunStepMcpToolCall": "Azure.AI.Agents.RunStepMcpToolCall",
132136
"azure.ai.agents.models.RunStepMessageCreationDetails": "Azure.AI.Agents.RunStepMessageCreationDetails",
133137
"azure.ai.agents.models.RunStepMessageCreationReference": "Azure.AI.Agents.RunStepMessageCreationReference",
134138
"azure.ai.agents.models.RunStepMicrosoftFabricToolCall": "Azure.AI.Agents.RunStepMicrosoftFabricToolCall",
@@ -137,11 +141,14 @@
137141
"azure.ai.agents.models.RunStepToolCallDetails": "Azure.AI.Agents.RunStepToolCallDetails",
138142
"azure.ai.agents.models.SharepointGroundingToolParameters": "Azure.AI.Agents.SharepointGroundingToolParameters",
139143
"azure.ai.agents.models.SharepointToolDefinition": "Azure.AI.Agents.SharepointToolDefinition",
144+
"azure.ai.agents.models.SubmitToolApprovalAction": "Azure.AI.Agents.SubmitToolApprovalAction",
145+
"azure.ai.agents.models.SubmitToolApprovalDetails": "Azure.AI.Agents.SubmitToolApprovalDetails",
140146
"azure.ai.agents.models.SubmitToolOutputsAction": "Azure.AI.Agents.SubmitToolOutputsAction",
141147
"azure.ai.agents.models.SubmitToolOutputsDetails": "Azure.AI.Agents.SubmitToolOutputsDetails",
142148
"azure.ai.agents.models.ThreadMessage": "Azure.AI.Agents.ThreadMessage",
143149
"azure.ai.agents.models.ThreadMessageOptions": "Azure.AI.Agents.ThreadMessageOptions",
144150
"azure.ai.agents.models.ThreadRun": "Azure.AI.Agents.ThreadRun",
151+
"azure.ai.agents.models.ToolApproval": "Azure.AI.Agents.ToolApproval",
145152
"azure.ai.agents.models.ToolConnection": "Azure.AI.Agents.ToolConnection",
146153
"azure.ai.agents.models.ToolOutput": "Azure.AI.Agents.ToolOutput",
147154
"azure.ai.agents.models.ToolResources": "Azure.AI.Agents.ToolResources",

sdk/ai/azure-ai-agents/azure/ai/agents/aio/operations/_operations.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ async def create(
11821182
additional_instructions: Optional[str] = None,
11831183
additional_messages: Optional[List[_models.ThreadMessageOptions]] = None,
11841184
tools: Optional[List[_models.ToolDefinition]] = None,
1185+
tool_resources: Optional[_models.ToolResources] = None,
11851186
stream_parameter: Optional[bool] = None,
11861187
temperature: Optional[float] = None,
11871188
top_p: Optional[float] = None,
@@ -1224,6 +1225,9 @@ async def create(
12241225
:keyword tools: The overridden list of enabled tools that the agent should use to run the
12251226
thread. Default value is None.
12261227
:paramtype tools: list[~azure.ai.agents.models.ToolDefinition]
1228+
:keyword tool_resources: The overridden enabled tool resources that the agent should use to run
1229+
the thread. Default value is None.
1230+
:paramtype tool_resources: ~azure.ai.agents.models.ToolResources
12271231
:keyword stream_parameter: If ``true``, returns a stream of events that happen during the Run
12281232
as server-sent events,
12291233
terminating when the Run enters a terminal state with a ``data: [DONE]`` message. Default
@@ -1353,6 +1357,7 @@ async def create(
13531357
additional_instructions: Optional[str] = None,
13541358
additional_messages: Optional[List[_models.ThreadMessageOptions]] = None,
13551359
tools: Optional[List[_models.ToolDefinition]] = None,
1360+
tool_resources: Optional[_models.ToolResources] = None,
13561361
stream_parameter: Optional[bool] = None,
13571362
temperature: Optional[float] = None,
13581363
top_p: Optional[float] = None,
@@ -1394,6 +1399,9 @@ async def create(
13941399
:keyword tools: The overridden list of enabled tools that the agent should use to run the
13951400
thread. Default value is None.
13961401
:paramtype tools: list[~azure.ai.agents.models.ToolDefinition]
1402+
:keyword tool_resources: The overridden enabled tool resources that the agent should use to run
1403+
the thread. Default value is None.
1404+
:paramtype tool_resources: ~azure.ai.agents.models.ToolResources
13971405
:keyword stream_parameter: If ``true``, returns a stream of events that happen during the Run
13981406
as server-sent events,
13991407
terminating when the Run enters a terminal state with a ``data: [DONE]`` message. Default
@@ -1482,6 +1490,7 @@ async def create(
14821490
"stream": stream_parameter,
14831491
"temperature": temperature,
14841492
"tool_choice": tool_choice,
1493+
"tool_resources": tool_resources,
14851494
"tools": tools,
14861495
"top_p": top_p,
14871496
"truncation_strategy": truncation_strategy,
@@ -1851,8 +1860,9 @@ async def submit_tool_outputs(
18511860
thread_id: str,
18521861
run_id: str,
18531862
*,
1854-
tool_outputs: List[_models.ToolOutput],
18551863
content_type: str = "application/json",
1864+
tool_outputs: Optional[List[_models.ToolOutput]] = None,
1865+
tool_approvals: Optional[List[_models.ToolApproval]] = None,
18561866
stream_parameter: Optional[bool] = None,
18571867
**kwargs: Any
18581868
) -> _models.ThreadRun:
@@ -1862,11 +1872,15 @@ async def submit_tool_outputs(
18621872
:type thread_id: str
18631873
:param run_id: Identifier of the run. Required.
18641874
:type run_id: str
1865-
:keyword tool_outputs: A list of tools for which the outputs are being submitted. Required.
1866-
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
18671875
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
18681876
Default value is "application/json".
18691877
:paramtype content_type: str
1878+
:keyword tool_outputs: A list of tools for which the outputs are being submitted. Default value
1879+
is None.
1880+
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1881+
:keyword tool_approvals: A list of tool approvals allowing data to be sent to tools. Default
1882+
value is None.
1883+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
18701884
:keyword stream_parameter: If true, returns a stream of events that happen during the Run as
18711885
SSE, terminating at ``[DONE]``. Default value is None.
18721886
:paramtype stream_parameter: bool
@@ -1922,7 +1936,8 @@ async def submit_tool_outputs(
19221936
run_id: str,
19231937
body: Union[JSON, IO[bytes]] = _Unset,
19241938
*,
1925-
tool_outputs: List[_models.ToolOutput] = _Unset,
1939+
tool_outputs: Optional[List[_models.ToolOutput]] = None,
1940+
tool_approvals: Optional[List[_models.ToolApproval]] = None,
19261941
stream_parameter: Optional[bool] = None,
19271942
**kwargs: Any
19281943
) -> _models.ThreadRun:
@@ -1934,8 +1949,12 @@ async def submit_tool_outputs(
19341949
:type run_id: str
19351950
:param body: Is either a JSON type or a IO[bytes] type. Required.
19361951
:type body: JSON or IO[bytes]
1937-
:keyword tool_outputs: A list of tools for which the outputs are being submitted. Required.
1952+
:keyword tool_outputs: A list of tools for which the outputs are being submitted. Default value
1953+
is None.
19381954
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1955+
:keyword tool_approvals: A list of tool approvals allowing data to be sent to tools. Default
1956+
value is None.
1957+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
19391958
:keyword stream_parameter: If true, returns a stream of events that happen during the Run as
19401959
SSE, terminating at ``[DONE]``. Default value is None.
19411960
:paramtype stream_parameter: bool
@@ -1958,9 +1977,7 @@ async def submit_tool_outputs(
19581977
cls: ClsType[_models.ThreadRun] = kwargs.pop("cls", None)
19591978

19601979
if body is _Unset:
1961-
if tool_outputs is _Unset:
1962-
raise TypeError("missing required argument: tool_outputs")
1963-
body = {"stream": stream_parameter, "tool_outputs": tool_outputs}
1980+
body = {"stream": stream_parameter, "tool_approvals": tool_approvals, "tool_outputs": tool_outputs}
19641981
body = {k: v for k, v in body.items() if v is not None}
19651982
content_type = content_type or "application/json"
19661983
_content = None

sdk/ai/azure-ai-agents/azure/ai/agents/aio/operations/_patch.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,8 @@ async def submit_tool_outputs( # pylint: disable=arguments-differ
10301030
thread_id: str,
10311031
run_id: str,
10321032
*,
1033-
tool_outputs: List[_models.ToolOutput],
1033+
tool_outputs: Optional[List[_models.ToolOutput]] = None,
1034+
tool_approvals: Optional[List[_models.ToolApproval]] = None,
10341035
content_type: str = "application/json",
10351036
**kwargs: Any,
10361037
) -> _models.ThreadRun:
@@ -1042,8 +1043,8 @@ async def submit_tool_outputs( # pylint: disable=arguments-differ
10421043
:type thread_id: str
10431044
:param run_id: Required.
10441045
:type run_id: str
1045-
:keyword tool_outputs: Required.
10461046
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1047+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
10471048
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
10481049
Default value is "application/json".
10491050
:paramtype content_type: str
@@ -1103,7 +1104,8 @@ async def submit_tool_outputs(
11031104
run_id: str,
11041105
body: Union[JSON, IO[bytes]] = _Unset,
11051106
*,
1106-
tool_outputs: List[_models.ToolOutput] = _Unset,
1107+
tool_outputs: Optional[List[_models.ToolOutput]] = _Unset,
1108+
tool_approvals: Optional[List[_models.ToolApproval]] = _Unset,
11071109
**kwargs: Any,
11081110
) -> _models.ThreadRun:
11091111
"""Submits outputs from tools as requested by tool calls in a run. Runs that need submitted tool
@@ -1116,8 +1118,8 @@ async def submit_tool_outputs(
11161118
:type run_id: str
11171119
:param body: Is either a JSON type or a IO[bytes] type. Required.
11181120
:type body: JSON or IO[bytes]
1119-
:keyword tool_outputs: Required.
11201121
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1122+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
11211123
:return: ThreadRun. The ThreadRun is compatible with MutableMapping
11221124
:rtype: ~azure.ai.agents.models.ThreadRun
11231125
:raises ~azure.core.exceptions.HttpResponseError:
@@ -1132,6 +1134,11 @@ async def submit_tool_outputs(
11321134
thread_id, run_id, tool_outputs=tool_outputs, stream_parameter=False, stream=False, **kwargs
11331135
)
11341136

1137+
elif tool_approvals is not _Unset:
1138+
response = super().submit_tool_outputs(
1139+
thread_id, run_id, tool_approvals=tool_approvals, stream_parameter=False, stream=False, **kwargs
1140+
)
1141+
11351142
elif isinstance(body, io.IOBase):
11361143
content_type = kwargs.get("content_type", "application/json")
11371144
response = super().submit_tool_outputs(thread_id, run_id, body, content_type=content_type, **kwargs)
@@ -1177,7 +1184,8 @@ async def submit_tool_outputs_stream(
11771184
thread_id: str,
11781185
run_id: str,
11791186
*,
1180-
tool_outputs: List[_models.ToolOutput],
1187+
tool_outputs: Optional[List[_models.ToolOutput]] = None,
1188+
tool_approvals: Optional[List[_models.ToolApproval]] = None,
11811189
content_type: str = "application/json",
11821190
event_handler: _models.BaseAsyncAgentEventHandler,
11831191
**kwargs: Any,
@@ -1190,8 +1198,8 @@ async def submit_tool_outputs_stream(
11901198
:type thread_id: str
11911199
:param run_id: Required.
11921200
:type run_id: str
1193-
:keyword tool_outputs: Required.
11941201
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1202+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
11951203
:keyword content_type: Body Parameter content-type. Content type parameter for JSON body.
11961204
Default value is "application/json".
11971205
:paramtype content_type: str
@@ -1207,7 +1215,8 @@ async def submit_tool_outputs_stream( # pyright: ignore[reportInconsistentOverl
12071215
run_id: str,
12081216
body: Union[JSON, IO[bytes]] = _Unset,
12091217
*,
1210-
tool_outputs: List[_models.ToolOutput] = _Unset,
1218+
tool_outputs: Optional[List[_models.ToolOutput]] = _Unset,
1219+
tool_approvals: Optional[List[_models.ToolApproval]] = _Unset,
12111220
event_handler: _models.BaseAsyncAgentEventHandler,
12121221
**kwargs: Any,
12131222
) -> None:
@@ -1221,8 +1230,8 @@ async def submit_tool_outputs_stream( # pyright: ignore[reportInconsistentOverl
12211230
:type run_id: str
12221231
:param body: Is either a JSON type or a IO[bytes] type. Required.
12231232
:type body: JSON or IO[bytes]
1224-
:keyword tool_outputs: Required.
12251233
:paramtype tool_outputs: list[~azure.ai.agents.models.ToolOutput]
1234+
:paramtype tool_approvals: list[~azure.ai.agents.models.ToolApproval]
12261235
:keyword event_handler: The event handler to use for processing events during the run.
12271236
:paramtype event_handler: ~azure.ai.agents.models.AsyncAgentEventHandler
12281237
:raises ~azure.core.exceptions.HttpResponseError:
@@ -1237,6 +1246,11 @@ async def submit_tool_outputs_stream( # pyright: ignore[reportInconsistentOverl
12371246
thread_id, run_id, tool_outputs=tool_outputs, stream_parameter=True, stream=True, **kwargs
12381247
)
12391248

1249+
elif tool_approvals is not _Unset:
1250+
response = super().submit_tool_outputs(
1251+
thread_id, run_id, tool_approvals=tool_approvals, stream_parameter=True, stream=True, **kwargs
1252+
)
1253+
12401254
elif isinstance(body, io.IOBase):
12411255
content_type = kwargs.get("content_type", "application/json")
12421256
response = super().submit_tool_outputs(thread_id, run_id, body, content_type=content_type, **kwargs)

sdk/ai/azure-ai-agents/azure/ai/agents/models/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
FunctionName,
5454
FunctionToolDefinition,
5555
IncompleteRunDetails,
56+
MCPToolDefinition,
57+
MCPToolResource,
5658
MessageAttachment,
5759
MessageContent,
5860
MessageDelta,
@@ -99,6 +101,7 @@
99101
RequiredAction,
100102
RequiredFunctionToolCall,
101103
RequiredFunctionToolCallDetails,
104+
RequiredMcpToolCall,
102105
RequiredToolCall,
103106
ResponseFormatJsonSchema,
104107
ResponseFormatJsonSchemaType,
@@ -140,6 +143,7 @@
140143
RunStepFileSearchToolCallResults,
141144
RunStepFunctionToolCall,
142145
RunStepFunctionToolCallDetails,
146+
RunStepMcpToolCall,
143147
RunStepMessageCreationDetails,
144148
RunStepMessageCreationReference,
145149
RunStepMicrosoftFabricToolCall,
@@ -149,11 +153,14 @@
149153
RunStepToolCallDetails,
150154
SharepointGroundingToolParameters,
151155
SharepointToolDefinition,
156+
SubmitToolApprovalAction,
157+
SubmitToolApprovalDetails,
152158
SubmitToolOutputsAction,
153159
SubmitToolOutputsDetails,
154160
ThreadMessage,
155161
ThreadMessageOptions,
156162
ThreadRun,
163+
ToolApproval,
157164
ToolConnection,
158165
ToolDefinition,
159166
ToolOutput,
@@ -260,6 +267,8 @@
260267
"FunctionName",
261268
"FunctionToolDefinition",
262269
"IncompleteRunDetails",
270+
"MCPToolDefinition",
271+
"MCPToolResource",
263272
"MessageAttachment",
264273
"MessageContent",
265274
"MessageDelta",
@@ -306,6 +315,7 @@
306315
"RequiredAction",
307316
"RequiredFunctionToolCall",
308317
"RequiredFunctionToolCallDetails",
318+
"RequiredMcpToolCall",
309319
"RequiredToolCall",
310320
"ResponseFormatJsonSchema",
311321
"ResponseFormatJsonSchemaType",
@@ -347,6 +357,7 @@
347357
"RunStepFileSearchToolCallResults",
348358
"RunStepFunctionToolCall",
349359
"RunStepFunctionToolCallDetails",
360+
"RunStepMcpToolCall",
350361
"RunStepMessageCreationDetails",
351362
"RunStepMessageCreationReference",
352363
"RunStepMicrosoftFabricToolCall",
@@ -356,11 +367,14 @@
356367
"RunStepToolCallDetails",
357368
"SharepointGroundingToolParameters",
358369
"SharepointToolDefinition",
370+
"SubmitToolApprovalAction",
371+
"SubmitToolApprovalDetails",
359372
"SubmitToolOutputsAction",
360373
"SubmitToolOutputsDetails",
361374
"ThreadMessage",
362375
"ThreadMessageOptions",
363376
"ThreadRun",
377+
"ToolApproval",
364378
"ToolConnection",
365379
"ToolDefinition",
366380
"ToolOutput",

sdk/ai/azure-ai-agents/azure/ai/agents/models/_enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class AgentsNamedToolChoiceType(str, Enum, metaclass=CaseInsensitiveEnumMeta):
3333
"""Tool type ``connected_agent``"""
3434
DEEP_RESEARCH = "deep_research"
3535
"""Tool type ``deep_research``"""
36+
MCP = "mcp"
37+
"""Tool type ``mcp``"""
3638

3739

3840
class AgentsResponseFormatMode(str, Enum, metaclass=CaseInsensitiveEnumMeta):

0 commit comments

Comments
 (0)