openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/modify-responsesclient-default-model

Branches

Tags

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

Clone

HTTPS

Download ZIP

docs/quickstart/responses/extend_model_with_tools_remote_mcp.cs

30lines · modecode

1// SAMPLE: Generate response from remote MCP through Responses API
2// PAGE: https://platform.openai.com/docs/quickstart?tool-type=remote-mcp#extend-the-model-with-tools
3// GUIDANCE: Instructions to run this code: https://aka.ms/oai/net/start
4#pragma warning disable OPENAI001
5
6#:package OpenAI@2.*
7
8using OpenAI.Responses;
9
10string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!;
11ResponsesClient client = new(apiKey: key);
12
13CreateResponseOptions options = new()
14{
15 Model = "gpt-5.2"
16};
17options.Tools.Add(
18 ResponseTool.CreateMcpTool(
19 serverLabel: "dmcp",
20 serverUri: new Uri("https://dmcp-server.deno.dev/sse"),
21 toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
22 )
23);
24options.InputItems.Add(
25 ResponseItem.CreateUserMessageItem("Roll 2d4+1")
26);
27
28ResponseResult response = client.CreateResponse(options);
29
30Console.WriteLine(response.GetOutputText());