openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
OpenAI_2.10.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

examples/Responses/Example05_RemoteMcpAsync.cs

42lines · modecode

1using NUnit.Framework;
2using OpenAI.Responses;
3using System;
4using System.Collections.Generic;
5using System.Threading.Tasks;
6
7namespace 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
13public 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