openai/openai-dotnet

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/sub-pr-1135

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

27lines · 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(key);
12
13CreateResponseOptions options = new() { Model = "gpt-5.2" };
14options.Tools.Add(
15 ResponseTool.CreateMcpTool(
16 serverLabel: "dmcp",
17 serverUri: new Uri("https://dmcp-server.deno.dev/sse"),
18 toolCallApprovalPolicy: new McpToolCallApprovalPolicy(GlobalMcpToolCallApprovalPolicy.NeverRequireApproval)
19 )
20);
21options.InputItems.Add(
22 ResponseItem.CreateUserMessageItem("Roll 2d4+1")
23);
24
25ResponseResult response = client.CreateResponse(options);
26
27Console.WriteLine(response.GetOutputText());