Skip to content

Commit 448a032

Browse files
committed
update
1 parent 8bba676 commit 448a032

File tree

1 file changed

+95
-0
lines changed
  • articles/ai-foundry/openai/includes/language-overview

1 file changed

+95
-0
lines changed

articles/ai-foundry/openai/includes/language-overview/python.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,103 @@ For more examples, see the [Responses API](../../how-to/responses.md) documentat
228228
}
229229
```
230230

231+
### responses.create() with MCP server tool
232+
233+
# [Microsoft Entra ID](#tab/python-entra)
234+
235+
```python
236+
from openai import OpenAI
237+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
238+
239+
token_provider = get_bearer_token_provider(
240+
DefaultAzureCredential(), "https://cognitiveservices.azure.com/.default"
241+
)
242+
243+
client = OpenAI(
244+
base_url = "https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
245+
api_key=token_provider,
246+
)
247+
248+
resp = client.responses.create(
249+
model="gpt-5",
250+
tools=[
251+
{
252+
"type": "mcp",
253+
"server_label": "microsoft_learn",
254+
"server_description": "Microsoft Learn MCP server for searching and fetching Microsoft documentation.",
255+
"server_url": "https://learn.microsoft.com/api/mcp",
256+
"require_approval": "never",
257+
},
258+
],
259+
input="Search for information about Azure Functions",
260+
)
261+
262+
print(resp.output_text)
263+
```
264+
265+
For more examples, see the [Responses API](../../how-to/responses.md) documentation.
266+
267+
# [API Key](#tab/python-key)
268+
269+
```python
270+
import os
271+
from openai import OpenAI
272+
273+
client = OpenAI(
274+
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
275+
base_url="https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1/",
276+
)
277+
278+
resp = client.responses.create(
279+
model="gpt-5",
280+
tools=[
281+
{
282+
"type": "mcp",
283+
"server_label": "microsoft_learn",
284+
"server_description": "Microsoft Learn MCP server for searching and fetching Microsoft documentation.",
285+
"server_url": "https://learn.microsoft.com/api/mcp",
286+
"require_approval": "never",
287+
},
288+
],
289+
input="Search for information about Azure Functions",
290+
)
291+
292+
print(resp.output_text)
293+
```
294+
295+
For more examples, see the [Responses API](../../how-to/responses.md) documentation.
296+
297+
# [Environment Variables](#tab/python-env)
298+
299+
```python
300+
from openai import OpenAI
301+
302+
client = OpenAI()
303+
304+
resp = client.responses.create(
305+
model="gpt-5",
306+
tools=[
307+
{
308+
"type": "mcp",
309+
"server_label": "microsoft_learn",
310+
"server_description": "Microsoft Learn MCP server for searching and fetching Microsoft documentation.",
311+
"server_url": "https://learn.microsoft.com/api/mcp",
312+
"require_approval": "never",
313+
},
314+
],
315+
input="Search for information about Azure Functions",
316+
)
317+
318+
print(resp.output_text)
319+
```
320+
321+
For more examples, see the [Responses API](../../how-to/responses.md) documentation.
322+
323+
# [Response](#tab/python-output)
324+
231325
---
232326

327+
233328
## Chat
234329

235330
### chat.completions.create()

0 commit comments

Comments
 (0)