openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
examples/Responses/Example05_RemoteMcpAsync.cs
42lines · modecode
| 1 | using NUnit.Framework; |
| 2 | using OpenAI.Responses; |
| 3 | using System; |
| 4 | using System.Collections.Generic; |
| 5 | using System.Threading.Tasks; |
| 6 | |
| 7 | namespace OpenAI.Examples; |
| 8 | |
| 9 | // This example uses experimental APIs which are subject to change. To use experimental APIs, |
| 10 | // please acknowledge their experimental status by suppressing the corresponding warning. |
| 11 | #pragma warning disable OPENAI001 |
| 12 | |
| 13 | public partial class ResponseExamples |
| 14 | { |
| 15 | [Test] |
| 16 | public async Task Example05_RemoteMcpAsync() |
| 17 | { |
| 18 | List<ResponseItem> inputItems = |
| 19 | [ |
| 20 | ResponseItem.CreateUserMessageItem("Roll 2d4+1"), |
| 21 | ]; |
| 22 | |
| 23 | CreateResponseOptions options = new("gpt-5", inputItems) |
| 24 | { |
| 25 | Tools = { |
| 26 | new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse")) |
| 27 | { |
| 28 | ServerDescription = "A Dungeons and Dragons MCP server to assist with dice rolling.", |
| 29 | ToolCallApprovalPolicy = GlobalMcpToolCallApprovalPolicy.NeverRequireApproval // An implicit conversion is used here for convenience. |
| 30 | } |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | ResponsesClient client = new(apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")); |
| 35 | |
| 36 | ResponseResult response = await client.CreateResponseAsync(options); |
| 37 | |
| 38 | Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}"); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | #pragma warning restore OPENAI001 |