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