openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
docs/guides/tools-connectors-mcp/responses/authentication.cs
28lines · modecode
| 1 | // SAMPLE: Generate response from remote MCP through Responses API |
| 2 | // PAGE: https://platform.openai.com/docs/guides/tools-connectors-mcp#authentication |
| 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 authToken = Environment.GetEnvironmentVariable("STRIPE_OAUTH_ACCESS_TOKEN")!; |
| 11 | string key = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!; |
| 12 | ResponsesClient client = new(key); |
| 13 | |
| 14 | CreateResponseOptions options = new() { Model = "gpt-5.2" }; |
| 15 | options.Tools.Add( |
| 16 | ResponseTool.CreateMcpTool( |
| 17 | serverLabel: "stripe", |
| 18 | serverUri: new Uri("https://mcp.stripe.com"), |
| 19 | authorizationToken: authToken |
| 20 | ) |
| 21 | ); |
| 22 | options.InputItems.Add( |
| 23 | ResponseItem.CreateUserMessageItem("Create a payment link for $20") |
| 24 | ); |
| 25 | |
| 26 | ResponseResult response = client.CreateResponse(options); |
| 27 | |
| 28 | Console.WriteLine(response.GetOutputText()); |