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