You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Instructions/03c-use-agent-tools-with-mcp.md
+15-24Lines changed: 15 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,7 +123,7 @@ In this task, you'll connect to a remote MCP server, prepare the AI agent, and r
123
123
# Add references
124
124
from azure.identity import DefaultAzureCredential
125
125
from azure.ai.agents import AgentsClient
126
-
from azure.ai.agents.models import McpTool
126
+
from azure.ai.agents.models import McpTool, ToolSet
127
127
```
128
128
129
129
1. Find the comment **Connect to the agents client** and add the following code to connect to the Azure AI project using the current Azure credentials.
@@ -144,25 +144,29 @@ In this task, you'll connect to a remote MCP server, prepare the AI agent, and r
144
144
```python
145
145
# Initialize agent MCP tool
146
146
mcp_tool = McpTool(
147
-
server_label=mcp_server_label,
148
-
server_url=mcp_server_url,
147
+
server_label=mcp_server_label,
148
+
server_url=mcp_server_url,
149
149
)
150
+
151
+
mcp_tool.set_approval_mode("never")
152
+
153
+
toolset = ToolSet()
154
+
toolset.add(mcp_tool)
150
155
```
151
156
152
157
This code will connect to the Microsft Learn Docs remote MCP server. This is a cloud-hosted service that enables clients to access trusted and up-to-date information directly from Microsoft's official documentation.
153
158
154
-
1. Under the comment **Create a new agent with the mcp tool definitions** and add the following code:
159
+
1. Under the comment **Create a new agent** and add the following code:
155
160
156
161
```python
157
-
# Create a new agent with the mcp tool definitions
162
+
# Create a new agent
158
163
agent = agents_client.create_agent(
159
164
model=model_deployment,
160
165
name="my-mcp-agent",
161
166
instructions="""
162
167
You have access to an MCP server called `microsoft.docs.mcp` - this tool allows you to
163
168
search through Microsoft's latest official documentation. Use the available MCP tools
164
-
to answer questions and perform tasks.""",
165
-
tools=mcp_tool.definitions,
169
+
to answer questions and perform tasks."""
166
170
)
167
171
```
168
172
@@ -188,25 +192,11 @@ In this task, you'll connect to a remote MCP server, prepare the AI agent, and r
188
192
print(f"Created message, ID: {message.id}")
189
193
```
190
194
191
-
1. Under the comment **Update mcp tool headers**, add the following code:
192
-
193
-
```python
194
-
# Update mcp tool headers
195
-
mcp_tool.update_headers("SuperSecret", "123456")
196
-
```
197
-
198
-
1. Locate the comment **Set approval mode** and add the following code:
199
-
200
-
```python
201
-
# Set approval mode
202
-
mcp_tool.set_approval_mode("never")
203
-
```
204
-
205
-
1. Locate the comment **Create and process agent run in thread with MCP tools** and add the following code:
195
+
1. Find the comment **Create and process agent run in thread with MCP tools** and add the following code:
206
196
207
197
```python
208
198
# Create and process agent run in thread with MCP tools
209
-
run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, tool_resources=mcp_tool.resources)
199
+
run = agents_client.runs.create_and_process(thread_id=thread.id, agent_id=agent.id, toolset=toolset)
210
200
print(f"Created run, ID: {run.id}")
211
201
```
212
202
@@ -259,8 +249,9 @@ In this task, you'll connect to a remote MCP server, prepare the AI agent, and r
259
249
---
260
250
261
251
### **1. Create a Resource Group**
262
-
azurecli
252
+
'''azurecli
263
253
az group create --name myResourceGroup --location eastus
0 commit comments