@@ -170,8 +170,6 @@ BearerTokenPolicy tokenPolicy = new(
170
170
new DefaultAzureCredential (),
171
171
" https://cognitiveservices.azure.com/.default" );
172
172
173
- #pragma warning disable OPENAI001
174
-
175
173
OpenAIResponseClient client = new (
176
174
model : " o4-mini" ,
177
175
authenticationPolicy : tokenPolicy ,
@@ -244,6 +242,45 @@ await foreach (StreamingResponseUpdate update
244
242
}
245
243
```
246
244
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
+
247
284
## Error handling
248
285
249
286
### Error codes
0 commit comments