Skip to content

Commit d29c020

Browse files
Merge pull request #6113 from MicrosoftDocs/main
Auto Publish – main to live - 2025-07-17 22:05 UTC
2 parents 4f99432 + e4c77ee commit d29c020

40 files changed

+1369
-415
lines changed

.github/policies/disallow-edits.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ configuration:
2828
matchAny: true
2929
pattern: articles/ai-foundry/responsible-ai/*
3030
- not:
31-
activitySenderHasAssociation:
32-
association: Member
31+
or:
32+
- activitySenderHasAssociation:
33+
association: Member
34+
- isActivitySender:
35+
user: learn-build-service-prod[bot]
3336
then:
3437
- addReply:
3538
reply: >-
3639
@${issueAuthor} - Pull requests that modify files in this folder aren't accepted from public contributors.
3740
- closePullRequest
3841

39-
4042
- description: \@mention specific people when a PR is opened in the "ai-foundry/responsible-ai" folder.
4143
if:
4244
- payloadType: Pull_Request

articles/ai-foundry/.openpublishing.redirection.ai-studio.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,11 @@
12031203
"redirect_url": "/azure/ai-foundry/how-to/develop/trace-application#visualize-your-traces",
12041204
"redirect_document_id": false
12051205
},
1206+
{
1207+
"source_path_from_root": "/articles/ai-foundry/agents/index.yml",
1208+
"redirect_url": "/azure/ai-foundry/",
1209+
"redirect_document_id": false
1210+
},
12061211
{
12071212
"source_path_from_root": "/articles/ai-foundry/how-to/online-evaluation.md",
12081213
"redirect_url": "/azure/ai-foundry/how-to/monitor-applications",

articles/ai-foundry/agents/how-to/tools/file-search.md

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-agent-service
88
ms.topic: how-to
9-
ms.date: 12/11/2024
9+
ms.date: 07/17/2025
1010
author: aahill
1111
ms.author: aahi
1212
ms.custom: azure-ai-agents
@@ -26,17 +26,13 @@ File search augments agents with knowledge from outside its model, such as propr
2626

2727
### File sources
2828
- Upload local files
29-
- Azure Blob Storage
30-
31-
### Supported file types
32-
33-
- [Supported file types](#supported-file-types)
29+
- Azure Blob Storage
3430

3531
### Usage support
3632

3733
|Azure AI foundry support | Python SDK | C# SDK | JavaScript SDK | REST API | Basic agent setup | Standard agent setup |
3834
|---------|---------|---------|---------|---------|---------|---------|
39-
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | File upload only | File upload and using BYO blob storage |
35+
| ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | File upload only | File upload and using bring-your-own blob storage |
4036

4137
## Dependency on agent setup
4238

@@ -49,9 +45,8 @@ The file search tool has the same functionality as Azure OpenAI Assistants. Micr
4945
The file search tool uses the Azure AI Search and Azure Blob Storage resources you connected during agent setup.
5046
- Uploaded files get stored in your connected Azure Blob Storage account
5147
- Vector stores get created using your connected Azure AI Search resource
52-
<br> </br>
5348

54-
For both agent setups, Azure OpenAI handles the entire ingestion process, which includes:
49+
For both agent setups, the service handles the entire ingestion process, which includes:
5550
- Automatically parsing and chunking documents
5651
- Generating and storing embeddings
5752
- Utilizing both vector and keyword searches to retrieve relevant content for user queries.
@@ -169,9 +164,9 @@ vector_store = project_client.agents.create_vector_store_and_poll(
169164

170165
Vector stores created using thread helpers (like `tool_resources.file_search.vector_stores` in Threads or `message.attachments` in Messages) have a default expiration policy of seven days after they were last active (defined as the last time the vector store was part of a run).
171166

172-
When a vector store expires, the runs on that thread fail. To fix this issue, you can recreate a new vector_store with the same files and reattach it to the thread.
167+
When a vector store expires, the runs on that thread fail. To fix this issue, you can recreate a new vector_store with the same files and reattach it to the thread.
173168

174-
### Supported file types
169+
## Supported file types
175170

176171
> [!NOTE]
177172
> For text/ MIME types, the encoding must be either utf-8, utf-16, or ASCII.

articles/ai-foundry/agents/how-to/tools/model-context-protocol-samples.md

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: 'MCP tool code samples'
2+
title: Code Samples for the Model Context Protocol Tool (Preview)
33
titleSuffix: Azure AI Foundry
4-
description: Find code samples to connect Foundry Agent service with MCP.
4+
description: Find code samples to connect Azure AI Foundry Agent Service with MCP servers.
55
services: cognitive-services
66
manager: nitinme
77
ms.service: azure-ai-agent-service
@@ -13,13 +13,14 @@ zone_pivot_groups: selection-mcp-code
1313
ms.custom: azure-ai-agents-code
1414
---
1515

16-
# How to use the Model Context Protocol (MCP) tool
16+
# Code samples for the Model Context Protocol tool (preview)
1717

18-
Use this article to find step-by-step instructions and code samples for connecting Foundry Agent service with MCP.
18+
Use this article to find code samples for connecting Azure AI Foundry Agent Service with Model Context Protocol (MCP) servers.
1919

2020
:::zone pivot="python"
2121

22-
## Initialization
22+
## Initialize the client
23+
2324
The code begins by setting up the necessary imports, getting the relevant MCP server configuration, and initializing the AI Project client:
2425

2526
```python
@@ -29,7 +30,7 @@ from azure.ai.projects import AIProjectClient
2930
from azure.identity import DefaultAzureCredential
3031
from azure.ai.agents.models import McpTool, RequiredMcpToolCall, SubmitToolApprovalAction, ToolApproval
3132

32-
# Get MCP server configuration from environment variables
33+
# Get the MCP server configuration from environment variables
3334
mcp_server_url = os.environ.get("MCP_SERVER_URL", "https://gitmcp.io/Azure/azure-rest-api-specs")
3435
mcp_server_label = os.environ.get("MCP_SERVER_LABEL", "github")
3536

@@ -39,8 +40,9 @@ project_client = AIProjectClient(
3940
)
4041
```
4142

42-
## Tool setup
43-
To add the MCP server to the agent, use the following example, which takes the MCP server label and URL from the last step. You can also add or remove allowed tools dynamically through the `allow_tool` parameter.
43+
## Set up the tool
44+
45+
To add the MCP server to the agent, use the following example, which takes the MCP server label and URL from the previous step. You can also add or remove allowed tools dynamically through the `allow_tool` parameter.
4446

4547
```python
4648
mcp_tool = McpTool(
@@ -55,17 +57,18 @@ mcp_tool.allow_tool(search_api_code)
5557
print(f"Allowed tools: {mcp_tool.allowed_tools}")
5658
```
5759

58-
## Agent creation
59-
An agent is created using the `project_client.agents.create_agent` method.
60+
## Create an agent
61+
62+
You create an agent by using the `project_client.agents.create_agent` method:
6063

6164
```python
6265
# Create a new agent.
63-
# NOTE: To reuse existing agent, fetch it with get_agent(agent_id)
66+
# NOTE: To reuse an existing agent, fetch it with get_agent(agent_id)
6467
with project_client:
6568
agents_client = project_client.agents
6669

6770
# Create a new agent.
68-
# NOTE: To reuse existing agent, fetch it with get_agent(agent_id)
71+
# NOTE: To reuse an existing agent, fetch it with get_agent(agent_id)
6972
agent = agents_client.create_agent(
7073
model=os.environ["MODEL_DEPLOYMENT_NAME"],
7174
name="my-mcp-agent",
@@ -74,15 +77,16 @@ with project_client:
7477
)
7578
```
7679

77-
## Thread management
78-
Create the thread and add the initial user message.
80+
## Create a thread
81+
82+
Create the thread and add the initial user message:
7983

8084
```python
81-
# Create thread for communication
85+
# Create a thread for communication
8286
thread = agents_client.threads.create()
8387
print(f"Created thread, ID: {thread.id}")
8488

85-
# Create message to thread
89+
# Create a message for the thread
8690
message = agents_client.messages.create(
8791
thread_id=thread.id,
8892
role="user",
@@ -91,20 +95,20 @@ message = agents_client.messages.create(
9195
print(f"Created message, ID: {message.id}")
9296
```
9397

94-
## Handle tool approvals and create a run
98+
## Handle tool approvals
9599

96-
Set the MCP server update headers and optionally disable tool approval requirements.
100+
Set the MCP server update headers and optionally disable tool approval requirements:
97101

98102
```python
99103
mcp_tool.update_headers("SuperSecret", "123456")
100-
# mcp_tool.set_approval_mode("never") # Uncomment to disable approval requirement
104+
# mcp_tool.set_approval_mode("never") # Uncomment to disable approval requirements
101105
run = agents_client.runs.create(thread_id=thread.id, agent_id=agent.id, tool_resources=mcp_tool.resources)
102106
print(f"Created run, ID: {run.id}")
103107
```
104108

105-
106109
## Create a run and check the output
107-
Create the run, check the output, and examine what tools were called during the run.
110+
111+
Create the run, check the output, and examine what tools were called during the run:
108112

109113
```python
110114
# Create and automatically process the run, handling tool calls internally
@@ -133,9 +137,9 @@ Create the run, check the output, and examine what tools were called during the
133137
print()
134138
```
135139

140+
## Perform cleanup
136141

137-
## Cleanup
138-
After the interaction is complete, the script performs cleanup by deleting the created agent resource using `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread using `agents_client.list_messages()` for review or logging.
142+
After the interaction is complete, the script performs cleanup by deleting the created agent resource via `agents_client.delete_agent()` to avoid leaving unused resources. It also fetches and prints the entire message history from the thread by using `agents_client.list_messages()` for review or logging.
139143

140144
```python
141145
# Delete the agent resource to clean up
@@ -152,24 +156,24 @@ After the interaction is complete, the script performs cleanup by deleting the c
152156

153157
:::zone pivot="rest"
154158

155-
Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api#api-call-information) to set the right values for the environment variables `AGENT_TOKEN`, `AZURE_AI_FOUNDRY_PROJECT_ENDPOINT`, and `API_VERSION`.
159+
Follow the [REST API quickstart](../../quickstart.md?pivots=rest-api#api-call-information) to set the right values for the environment variables `AGENT_TOKEN`, `AZURE_AI_FOUNDRY_PROJECT_ENDPOINT`, and `API_VERSION`.
156160

161+
## Create an agent with the MCP tool enabled
157162

158-
## Create an Agent with the MCP tool enabled
163+
To make the MCP tool available to your agent, initialize a tool with the server endpoint, server label, and more:
159164

160-
To make the MCP tool available to your agent, initialize a tool with the server endpoint, server label and more
161165
```bash
162166
curl --request POST \
163167
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/assistants?api-version=$API_VERSION \
164168
-H "Authorization: Bearer $AGENT_TOKEN" \
165169
-H "Content-Type: application/json" \
166170
-d "{
167-
"instructions": "You are a customer support chatbot. Use the tools provided and your knowledge base to best respond to customer queries.",
168-
"tools": [
171+
"instructions": "You are a customer support chatbot. Use the tools provided and your knowledge base to best respond to customer queries.",
172+
"tools": [
169173
{
170174
"type": "mcp",
171175
"server_label": "<unique name for your MCP server>",
172-
"server_url": "<your MCP server url>",
176+
"server_url": "<your MCP server URL>",
173177
"allowed_tools": ["<tool_name>"], # optional
174178
}
175179
],
@@ -203,26 +207,27 @@ curl --request POST \
203207

204208
## Create a run and check the output
205209

206-
Create a run to pass headers for the tool and observe that the model uses the Grounding with Bing Search tool to provide a response to the user's question.
207-
`require_approval` parameter is optional. If not provided, `always` is the default value, meaning each time developer needs to approve before calling. Supported values:
210+
Create a run to pass headers for the tool. Observe that the model uses the Grounding with Bing Search tool to provide a response to the user's question.
211+
212+
The `require_approval` parameter is optional. Supported values are:
208213

209-
- `always` by default
210-
- `never` meaning no approval is required
211-
- `{"never":[<tool_name_1>, <tool_name_2>]}` you can also provide a list of tools without required approval
212-
- `{"always":[<tool_name_1>, <tool_name_2>]}` you can provide a list of tools with required approval
214+
- `always`: A developer needs to provide approval for every call. If you don't provide a value, this one is the default.
215+
- `never`: No approval is required.
216+
- `{"never":[<tool_name_1>, <tool_name_2>]}`: You provide a list of tools that don't require approval.
217+
- `{"always":[<tool_name_1>, <tool_name_2>]}`: You provide a list of tools that require approval.
213218

214219
```bash
215220
curl --request POST \
216221
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs?api-version=$API_VERSION \
217222
-H "Authorization: Bearer $AGENT_TOKEN" \
218223
-H "Content-Type: application/json" \
219224
-d '{
220-
"assistant_id": "<agent_id>",
221-
"tool_resources": {
225+
"assistant_id": "<agent_id>",
226+
"tool_resources": {
222227
"mcp": [
223228
{
224229
"server_label": "<the same unique name you provided during agent creation>",
225-
"require_approval": "always" #always by default
230+
"require_approval": "always" #always by default
226231
"headers": {
227232
"Authorization": "Bearer <token>",
228233
}
@@ -232,6 +237,7 @@ curl --request POST \
232237
},
233238
}'
234239
```
240+
235241
## Retrieve the status of the run
236242

237243
```bash
@@ -240,7 +246,8 @@ curl --request GET \
240246
-H "Authorization: Bearer $AGENT_TOKEN"
241247
```
242248

243-
If the model is trying to invoke a tool in your MCP server with approval required, you get a run with `require_action` status.
249+
If the model tries to invoke a tool in your MCP server with approval required, you get a run with `requires_action` status:
250+
244251
```bash
245252
{
246253
"id": "run_123",
@@ -274,17 +281,20 @@ If the model is trying to invoke a tool in your MCP server with approval require
274281
...
275282
}
276283
```
277-
Make sure you carefully reviewed the tool and argument(s) to be passed and make an informed decision for approval.
284+
285+
Carefully review the tool and arguments to be passed so that you can make an informed decision for approval.
278286

279287
## Submit your approval
280-
If you decide to approve, you need to set the `approve` parameter to be `true` with the `id` for the preceding tool calls.
288+
289+
If you decide to approve, set the `approve` parameter to `true` with the `id` value for the preceding tool calls:
290+
281291
```bash
282292
curl --request POST \
283293
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs/run_abc123/submit_tool_outputs?api-version=$API_VERSION \
284294
-H "Authorization: Bearer $AGENT_TOKEN" \
285295
-H "Content-Type: application/json" \
286296
-d '{
287-
"tool_approvals": [
297+
"tool_approvals": [
288298
{
289299
"tool_call_id": "call_abc123",
290300
"approve": true,
@@ -295,7 +305,6 @@ curl --request POST \
295305
}
296306
```
297307
298-
299308
## Retrieve the agent response
300309
301310
```bash
@@ -305,4 +314,3 @@ curl --request GET \
305314
```
306315
307316
:::zone-end
308-

0 commit comments

Comments
 (0)