Skip to content

Commit 5440bdc

Browse files
authored
Merge pull request #5858 from lindazqli/patch-9
Update model-context-protocol-samples.md
2 parents d64e9e8 + 0db86a5 commit 5440bdc

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

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

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ ms.custom: azure-ai-agents-code
1717

1818
Use this article to find step-by-step instructions and code samples for connecting Foundry Agent service with MCP.
1919

20-
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`.
20+
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`.
2121

2222

2323
## Create an Agent with the MCP tool enabled
@@ -35,7 +35,7 @@ curl --request POST \
3535
"type": "mcp",
3636
"server_label": "<unique name for your MCP server>",
3737
"server_url": "<your MCP server url>",
38-
"require_approval": "never",
38+
"allowed_tools": ["<tool_name>"], # optional
3939
}
4040
],
4141
"name": "my-assistant",
@@ -68,7 +68,13 @@ curl --request POST \
6868

6969
## Create a run and check the output
7070

71-
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.
71+
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.
72+
`require_approval` parameter is optional. If not provided, `always` is the default value, meaning each time developer needs to approve before calling. Supported values:
73+
74+
- `always` by default
75+
- `never` meaning no approval is required
76+
- `{"never":[<tool_name_1>, <tool_name_2>]}` you can also provide a list of tools without required approval
77+
- `{"always":[<tool_name_1>, <tool_name_2>]}` you can provide a list of tools with required approval
7278

7379
```bash
7480
curl --request POST \
@@ -81,9 +87,11 @@ curl --request POST \
8187
"mcp": [
8288
{
8389
"server_label": "<the same unique name you provided during agent creation>",
90+
"require_approval": "always" #always by default
8491
"headers": {
8592
"Authorization": "Bearer <token>",
8693
}
94+
8795
}
8896
]
8997
},
@@ -97,6 +105,62 @@ curl --request GET \
97105
-H "Authorization: Bearer $AGENT_TOKEN"
98106
```
99107

108+
If the model is trying to invoke a tool in your MCP server with approval required, you get a run with `require_action` status.
109+
```bash
110+
{
111+
"id": "run_123",
112+
"object": "thread.run",
113+
...
114+
"status": "requires_action",
115+
...
116+
"required_action": {
117+
"type": "submit_tool_approval",
118+
"submit_tool_approval": {
119+
"tool_calls": [
120+
{
121+
"id": "call_123",
122+
"type": "mcp",
123+
"arguments": "{...}",
124+
"name": "<tool_name>",
125+
"server_label": "<server_label_you_provided>"
126+
}
127+
]
128+
}
129+
},
130+
...
131+
"tools": [
132+
{
133+
"type": "mcp",
134+
"server_label": "<server_label_you_provided>",
135+
"server_url": "<server_url_you_provided>",
136+
"allowed_tools": null
137+
}
138+
],
139+
...
140+
}
141+
```
142+
Make sure you carefully reviewed the tool and argument(s) to be passed and make an informed decision for approval.
143+
144+
## Submit your approval
145+
If you decide to approve, you need to set the `approve` parameter to be `true` with the `id` for the preceding tool calls.
146+
```bash
147+
curl --request POST \
148+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs/run_abc123/submit_tool_outputs?api-version=$API_VERSION \
149+
-H "Authorization: Bearer $AGENT_TOKEN" \
150+
-H "Content-Type: application/json" \
151+
-d '{
152+
"tool_approvals": [
153+
{
154+
"tool_call_id": "call_abc123",
155+
"approve": true,
156+
"headers": {
157+
}
158+
}
159+
]
160+
}
161+
```
162+
163+
100164
## Retrieve the agent response
101165
102166
```bash

0 commit comments

Comments
 (0)