openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.6.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

examples/Responses/Example05_RemoteMcpAsync.cs

36lines · modecode

1using NUnit.Framework;
2using OpenAI.Responses;
3using System;
4using System.Threading.Tasks;
5
6namespace 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
12public partial class ResponseExamples
13{
14 [Test]
15 public async Task Example05_RemoteMcpAsync()
16 {
17 ResponseCreationOptions options = new()
18 {
19 Tools = {
20 new McpTool(serverLabel: "dmcp", serverUri: new Uri("https://dmcp-server.deno.dev/sse"))
21 {
22 ServerDescription = "A Dungeons and Dragons MCP server to assist with dice rolling.",
23 ToolCallApprovalPolicy = new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
24 }
25 }
26 };
27
28 OpenAIResponseClient client = new(model: "gpt-5", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));
29
30 OpenAIResponse response = await client.CreateResponseAsync("Roll 2d4+1", options);
31
32 Console.WriteLine($"[ASSISTANT]: {response.GetOutputText()}");
33 }
34}
35
36#pragma warning restore OPENAI001