Skip to content

Commit f0a1154

Browse files
committed
update
1 parent be06f1a commit f0a1154

File tree

1 file changed

+39
-2
lines changed
  • articles/ai-foundry/openai/includes/language-overview

1 file changed

+39
-2
lines changed

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

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,6 @@ BearerTokenPolicy tokenPolicy = new(
170170
new DefaultAzureCredential(),
171171
"https://cognitiveservices.azure.com/.default");
172172

173-
#pragma warning disable OPENAI001
174-
175173
OpenAIResponseClient client = new(
176174
model: "o4-mini",
177175
authenticationPolicy: tokenPolicy,
@@ -244,6 +242,45 @@ await foreach (StreamingResponseUpdate update
244242
}
245243
```
246244

245+
### MCP Server
246+
247+
```csharp
248+
using OpenAI;
249+
using OpenAI.Responses;
250+
using System.ClientModel.Primitives;
251+
using Azure.Identity;
252+
253+
#pragma warning disable OPENAI001 //currently required for token based authentication
254+
255+
BearerTokenPolicy tokenPolicy = new(
256+
new DefaultAzureCredential(),
257+
"https://cognitiveservices.azure.com/.default");
258+
259+
OpenAIResponseClient client = new(
260+
model: "o4-mini",
261+
authenticationPolicy: tokenPolicy,
262+
options: new OpenAIClientOptions()
263+
{
264+
Endpoint = new Uri("https://YOUR-RESOURCE-NAME.openai.azure.com/openai/v1")
265+
}
266+
);
267+
268+
ResponseCreationOptions options = new();
269+
options.Tools.Add(ResponseTool.CreateMcpTool(
270+
serverLabel: "microsoft_learn",
271+
serverUri: new Uri("https://learn.microsoft.com/api/mcp"),
272+
toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
273+
));
274+
275+
OpenAIResponse response = (OpenAIResponse)client.CreateResponse([
276+
ResponseItem.CreateUserMessageItem([
277+
ResponseContentPart.CreateInputTextPart("Search for information about Azure Functions")
278+
])
279+
], options);
280+
281+
Console.WriteLine(response.GetOutputText());
282+
```
283+
247284
## Error handling
248285

249286
### Error codes

0 commit comments

Comments
 (0)