openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
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 | |
| 8 | using OpenAI.Responses; |
| 9 | |
| 10 | string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!; |
| 11 | ResponsesClient client = new(key); |
| 12 | |
| 13 | CreateResponseOptions options = new() { Model = "gpt-5.2" }; |
| 14 | options.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 | ); |
| 21 | options.InputItems.Add( |
| 22 | ResponseItem.CreateUserMessageItem("Roll 2d4+1") |
| 23 | ); |
| 24 | |
| 25 | ResponseResult response = client.CreateResponse(options); |
| 26 | |
| 27 | Console.WriteLine(response.GetOutputText()); |